Python Development · 3 November 2026 · 14 min read
UV: The Modern Python Package Manager – Complete Beginner's Guide
Learn how to use uv, the fast Python package and project manager. Explore installation, project initialization, virtual environments, dependency management, pip alternatives, Python version management, and essential uv commands.
- Python
- uv
- Package Management
- Python Development
- pip
- Virtual Environments
- Developer Tools

UV: The Modern Python Package Manager – Complete Beginner's Guide
If you have worked with Python, you are probably familiar with tools like pip, venv, and requirements.txt.
Whenever you start a new Python project, the usual workflow involves creating a virtual environment, activating it, installing dependencies, and managing package versions.
For a small project, this is straightforward. But as your projects grow, managing dependencies, Python versions, and environments across different machines can become increasingly complicated.
This is where uv comes in.
uv is a modern Python package and project manager developed by Astral, the team behind Ruff. It is designed to make Python development faster and simplify several tasks that traditionally require separate tools.
Instead of managing multiple tools independently, uv provides a unified workflow for:
- Installing Python versions.
- Creating Python projects.
- Managing dependencies.
- Creating virtual environments.
- Running Python applications.
- Managing lockfiles.
- Installing and executing CLI tools.
If you already know pip and venv, learning uv is relatively easy.
In this guide, we'll understand what uv is, why developers use it, how to initialize a Python project, and how to manage dependencies and virtual environments using practical terminal commands.
1. What is uv?
uv is an extremely fast Python package and project manager written in Rust.
It is designed to provide a unified alternative to several tools in the Python ecosystem.
Traditionally, you might use:
| Tool | Purpose |
|---|---|
| pip | Install Python packages |
| venv | Create virtual environments |
| pip-tools | Manage dependency versions |
| pipx | Install Python CLI tools |
| pyenv | Manage Python versions |
| Poetry | Manage Python projects and dependencies |
uv brings many of these capabilities together through a single command-line interface.
For example, instead of using:
python -m venv .venv
# Activate environment
source .venv/bin/activate
# Install dependencies
pip install requests fastapi
# Generate requirements
pip freeze > requirements.txtYou can use uv:
uv init my-project
cd my-project
uv add requests fastapi
uv run python main.pyuv manages the project environment, dependency resolution, and lockfile for you.
What makes uv different?
Some of its major characteristics include:
- Written in Rust for performance.
- Global caching to avoid unnecessary downloads and repeated work.
- Automatic virtual environment management for projects.
- Dependency resolution and lockfile generation.
- Python version installation and management.
- Support for existing Python packages and PyPI.
- Cross-platform support for Windows, macOS, and Linux.
Astral reports that uv can be 10–100x faster than pip in certain benchmarks. Actual performance depends on the project, network, cache state, and installation workflow.
Official documentation: https://docs.astral.sh/uv/
2. Installing uv
Before using uv, you need to install its command-line interface.
One useful feature is that you don't need to install Rust or an existing Python interpreter just to use uv's standalone installer.
Windows installation
Open PowerShell:
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"Alternatively, you can install it through WinGet:
winget install --id=astral-sh.uv -eLinux and macOS installation
Open your terminal:
curl -LsSf https://astral.sh/uv/install.sh | shInstall using pip
If you already have Python and pip:
pip install uvYou can also use pipx:
pipx install uvVerify installation
After installation, open a new terminal and execute:
uv --versionTo get help:
uv --helpYou should now be able to use uv from your terminal.
Update uv
If you installed uv using its standalone installer:
uv self updateThis updates uv to the latest available release.
3. Initializing a Python Project Using uv
One of the most useful features of uv is project initialization.
Traditionally, you would manually create a directory, initialize a virtual environment, create a Python file, and manage your dependencies.
With uv, you can get started with a single command.
Step 1: Create a project
Run:
uv init my-projectThis creates a new Python project named my-project.
Navigate into it:
cd my-projectStep 2: Understand the generated structure
A typical application project looks like this:
my-project/
│
├── .git/
├── .gitignore
├── .python-version
├── pyproject.toml
├── README.md
└── main.pyThe important files are:
1. pyproject.toml
This is the main configuration file for your Python project.
It stores project metadata, Python version requirements, dependencies, and other configuration.
2. .python-version
Specifies the Python version that uv should use for the project.
3. main.py
The entry point of the application.
4. .gitignore
Contains files and directories that should not be committed to Git, including virtual environments.
Step 3: Run your application
You can execute your Python application using:
uv run main.pyuv automatically checks the project environment and installs the required dependencies when needed.
Initializing different project types
uv also supports different project structures.
Create an application project:
uv init --app my-appAn application project is intended for building and running applications.
Create a library project:
uv init --lib my-libraryA library project is useful when you want to create reusable Python code.
Create a packaged application:
uv init --package my-packageA packaged project uses a package-oriented source layout and can define executable entry points.
Initialize the current directory:
uv initThis initializes the current directory instead of creating a new one.
These options are useful because the structure of a reusable Python library is different from that of a simple application.
4. Understanding pyproject.toml
The pyproject.toml file is one of the most important parts of a uv-managed project.
It defines the project's metadata and dependencies.
For example:
[project]
name = "my-project"
version = "0.1.0"
description = "My Python application"
readme = "README.md"
requires-python = ">=3.12"
dependencies = []Let's understand some of these fields.
| Field | Purpose |
|---|---|
| name | Project name |
| version | Project version |
| description | Project description |
| readme | README file |
| requires-python | Supported Python versions |
| dependencies | Project dependencies |
When you install a package using uv add, uv automatically updates the dependency list.
For example:
uv add requestsYour configuration will now contain something similar to:
[project]
name = "my-project"
version = "0.1.0"
requires-python = ">=3.12"
dependencies = [
"requests>=2.32.0"
]The exact version constraint will depend on the version resolved during installation.
You don't need to manually edit the dependency list every time you install a package.
5. Managing Python Versions Using uv
Another useful feature is Python version management.
Traditionally, developers use tools like pyenv to install and switch between multiple Python versions.
uv provides built-in commands for this.
View available Python versions
uv python listThis displays Python versions available for installation and those already installed.
Install Python
For example, install Python 3.12:
uv python install 3.12You can also install another version:
uv python install 3.13Check installed Python versions
uv python list --only-installedUse a specific Python version
When creating a new project:
uv init my-project --python 3.12For an existing project:
uv python pin 3.12This creates or updates the .python-version file.
Example:
3.12uv will use this version when managing the project's environment.
Why is this useful?
Imagine you have three projects:
project-a -> Python 3.10
project-b -> Python 3.12
project-c -> Python 3.13Instead of manually switching your system Python installation, uv can manage the required versions for each project.
This is particularly useful when working with older machine learning libraries, APIs, and applications that have different Python version requirements.
6. Managing Dependencies Using uv
This is probably the most important section if you're coming from pip.
uv provides two main approaches to package management:
- Project-based dependency management using
uv add,uv remove, anduv sync. - pip-compatible package management using
uv pip.
Understanding the difference will help you choose the correct commands.
6.1 Install a package using uv add
Suppose you want to install FastAPI.
With pip:
pip install fastapiWith uv:
uv add fastapiThis command does more than simply install the package.
It also:
- Adds FastAPI to
pyproject.toml. - Updates
uv.lock. - Synchronizes the project environment.
6.2 Install multiple packages
You can install multiple packages in one command:
uv add fastapi uvicorn sqlalchemyFor a typical FastAPI project, you might use:
uv add fastapi uvicorn pydantic6.3 Install development dependencies
Some packages are needed only during development.
For example, you might need:
- pytest for testing.
- Ruff for linting and formatting.
- mypy for static type checking.
Install them using:
uv add --dev pytest ruff mypyThis adds them to the development dependency group instead of the main application dependencies.
6.4 Install a specific package version
You can specify a version constraint:
uv add "requests==2.32.0"Install a compatible version range:
uv add "fastapi>=0.100,<1.0"This is useful when your project depends on a particular version of a library.
6.5 Remove a package
With pip:
pip uninstall requestsWith uv:
uv remove requestsThis removes the dependency from your project configuration and updates the lockfile and environment.
6.6 Update dependencies
Update the project's lockfile:
uv lock --upgradeUpgrade a specific dependency:
uv lock --upgrade-package requestsSynchronize the environment:
uv sync6.7 View installed dependencies
List the project's dependency tree:
uv treeThis helps you understand which packages are installed and which dependencies they require.
Package management command comparison
| pip | uv |
|---|---|
pip install requests |
uv add requests |
pip uninstall requests |
uv remove requests |
pip install pytest (dev) |
uv add --dev pytest |
pip install -r requirements.txt |
uv add -r requirements.txt |
pip freeze |
uv pip freeze |
pip list |
uv pip list |
pip show requests |
uv pip show requests |
pip check |
uv pip check |
pip install --upgrade requests |
uv lock --upgrade-package requests |
pip install -e . |
uv sync (for a managed project) |
Important: uv add is intended for project dependency management. uv pip install is the closer replacement for traditional pip commands that install directly into an environment. They are related but not interchangeable in every workflow.
7. Understanding Virtual Environments in uv
In traditional Python development, you normally create a virtual environment manually.
For example:
python -m venv .venvThen activate it.
Windows:
.venv\Scripts\activateLinux and macOS:
source .venv/bin/activateAfter activation, you install packages using pip.
With uv, project environments are managed automatically.
Create a virtual environment
If you're working with a uv project, commands such as uv sync create the .venv directory automatically when needed.
You can also create one manually:
uv venvTo create an environment using a specific Python version:
uv venv --python 3.12Activate the environment manually
Windows PowerShell:
.venv\Scripts\activateLinux and macOS:
source .venv/bin/activateDeactivate
deactivateDo you need to activate the environment every time?
Not necessarily.
One of the biggest conveniences of uv is that you can run commands directly through uv run.
For example:
uv run python main.pyOr:
uv run pytestuv ensures that commands run in the project's managed environment.
This means you don't have to manually activate your virtual environment for every development session.
8. Running Python Applications Using uv
The uv run command is one of the commands you'll use most frequently.
It executes Python scripts and other commands inside the project's environment.
Run a Python file
uv run main.pyRun a Python module
uv run python -m http.server 8000Run tests
uv run pytestRun a FastAPI application
First, install the dependencies:
uv add fastapi uvicornCreate main.py:
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
def home():
return {"message": "Hello from uv!"}Start the application:
uv run uvicorn main:app --reloadYour API will be available at:
http://127.0.0.1:8000API documentation:
http://127.0.0.1:8000/docsNotice that you didn't need to activate the virtual environment manually.
9. Understanding uv.lock
Just like npm has package-lock.json, uv maintains a lockfile called:
uv.lockThis file records the exact resolved dependency versions for your project.
For example, your pyproject.toml might specify:
dependencies = [
"fastapi>=0.100",
"requests>=2.30"
]These are version constraints, not exact versions.
The uv.lock file records the exact versions selected during dependency resolution.
Why is uv.lock important?
Imagine you're working on a project with another developer.
You both have the same pyproject.toml, but new versions of dependencies may become available over time.
Without a lockfile, different installations might resolve different versions.
With uv.lock, both developers can reproduce the same resolved dependency set.
Generate or update the lockfile
uv lockInstall dependencies from the lockfile
uv syncInstall without changing the lockfile
uv sync --lockedThis checks that the lockfile matches the project configuration.
For CI/CD environments, this is particularly useful.
Important: Commit uv.lock to Git for application projects. Do not manually edit it.
10. Using uv Without Initializing a Project
You don't always need to create a complete project to use uv.
For smaller scripts, uv provides convenient standalone workflows.
Run a Python script
uv run script.pyExecute a script with a dependency
Suppose you have a script that requires requests.
You can execute it without adding requests to a permanent project:
uv run --with requests script.pyuv creates or uses an appropriate temporary environment for the command.
Add dependencies directly to a script
uv also supports inline dependency metadata.
For example:
uv init --script example.pyThen add a dependency:
uv add --script example.py requestsThe script can declare its dependencies in its metadata.
This is useful for standalone automation scripts, small utilities, and experiments.
11. Running Python Tools Using uvx
Another useful command is uvx.
It allows you to execute Python CLI tools without permanently installing them into your project.
For example, suppose you want to use Ruff.
With pip, you might install it:
pip install ruffWith uvx:
uvx ruff check .uvx runs the tool in an isolated environment.
Other examples
Run Black:
uvx black .Run HTTPie:
uvx httpie --helpRun a specific tool version:
uvx ruff@0.11.0 check .If you frequently use a particular tool, you can install it permanently:
uv tool install ruffList installed tools:
uv tool listRemove a tool:
uv tool uninstall ruffThis is especially useful for developer utilities that you want available across multiple Python projects.
12. Useful uv Commands Cheat Sheet
Here is a collection of commands worth bookmarking.
Project initialization
uv init my-project
uv init --app my-app
uv init --lib my-library
uv init --package my-package
uv initPython version management
uv python list
uv python install 3.12
uv python pin 3.12
uv python find
uv python uninstall 3.12Package management
uv add requests
uv add fastapi uvicorn
uv add --dev pytest ruff
uv remove requests
uv lock
uv lock --upgrade
uv sync
uv treeVirtual environments
uv venv
uv venv --python 3.12Running applications
uv run main.py
uv run python -m http.server
uv run pytest
uv run uvicorn main:app --reloadStandalone tools
uvx ruff check .
uvx black .
uv tool install ruff
uv tool list
uv tool uninstall ruffpip-compatible commands
uv pip install requests
uv pip uninstall requests
uv pip list
uv pip freeze
uv pip show requests
uv pip checkMaintenance
uv --version
uv --help
uv self update
uv cache dir
uv cache clean
uv cache prune13. Migrating an Existing Python Project to uv
You don't need to start a new project to use uv.
Suppose you already have a Python application with this structure:
my-project/
│
├── main.py
├── requirements.txt
└── README.mdYou can migrate it to uv without rewriting your application.
Step 1: Initialize uv
Navigate to your existing project:
cd my-projectInitialize it:
uv init --bareThis creates the basic project configuration without generating a new application entry point or source layout.
Step 2: Import dependencies
If you already have a requirements.txt file:
uv add -r requirements.txtuv imports the dependencies into your project configuration and resolves them.
Step 3: Synchronize the environment
uv syncThis creates the .venv environment and installs the required packages.
Step 4: Run your application
uv run main.pyStep 5: Update Git
Your project should now contain:
my-project/
│
├── .venv/
├── .python-version
├── main.py
├── pyproject.toml
├── uv.lock
└── README.mdMake sure .venv is included in .gitignore.
You can now manage the project using uv instead of manually maintaining requirements and virtual environment commands.
14. Why Should You Use uv Instead of pip?
Now that we've covered the commands, let's understand the practical advantages of using uv.
1. Faster dependency installation
uv uses optimized dependency resolution, parallel operations, and caching.
This can significantly reduce installation time, particularly for projects with many dependencies.
2. One tool for multiple tasks
Instead of switching between pip, venv, pip-tools, pipx, and Python version managers, uv provides a unified CLI.
3. Automatic virtual environment management
You don't need to manually create and activate environments for every project.
Commands such as uv run and uv sync handle the project environment.
4. Reproducible dependencies
The uv.lock file records exact resolved versions.
This makes it easier to maintain consistent development and production environments.
5. Python version management
You can install and pin multiple Python versions without manually changing your system installation.
6. Global caching
uv uses a global cache to reuse downloaded and built packages.
This can reduce repeated downloads and save disk space.
7. Easy migration
If you already have a Python project using requirements.txt, you can migrate gradually without rewriting your application.
15. Final Thoughts
Python development often involves managing more than just application code.
You need to manage Python versions, dependencies, virtual environments, and package compatibility.
Tools like pip and venv have been essential to the Python ecosystem, but uv brings many of these workflows together in a single, modern interface.
If you're starting a new Python project, I'd recommend trying this workflow:
# Create a project
uv init my-project
# Navigate into it
cd my-project
# Install dependencies
uv add fastapi uvicorn
# Add development dependencies
uv add --dev pytest ruff
# Run your application
uv run main.py
# Run tests
uv run pytest
# Synchronize dependencies
uv syncThat's enough to get a basic Python project running without manually managing pip installations and virtual environment activation.
You don't need to learn every uv command immediately. Start with uv init, uv add, uv remove, uv run, and uv sync.
Once you're comfortable with these, explore Python version management, standalone tools, workspaces, and advanced dependency management.
The biggest advantage of uv is simple: less time managing your Python environment and more time building your application.
Official Documentation and Resources
- uv Official Documentation
- Installation Guide
- Getting Started
- Project Management
- Managing Dependencies
- Python Version Management
- Virtual Environments
- CLI Reference
Examples and command references are based on Astral's official uv documentation.
Aditya Manoj Shinde
Author
I'm Aditya, a developer passionate about AI, Machine Learning, and software development. I love exploring new technologies, building projects, and sharing what I learn along the way.