The UV package manager is a modern, high-performance tool designed to streamline and accelerate Python package and environment management. Developed by the creators of the Ruff linter, UV is positioned as a revolutionary alternative to traditional tools like pip
, pip-tools
, poetry
, and conda
. It aims to unify the functionality of multiple tools into a single, efficient package manager, offering significant speed improvements and a more streamlined developer experience.
The primary goal of UV is to address the limitations of traditional Python package managers, particularly concerning speed, efficiency, and ease of use. As Python projects grow in size and complexity, managing dependencies, environments, and project configurations can become cumbersome. UV seeks to:
pip
, with benchmarks showing speed improvements ranging from 10x to 100x for certain operations. This is achieved through its implementation in Rust and efficient caching mechanisms.pip
(for installing packages), pip-tools
(for dependency resolution), poetry
(for project management), virtualenv
(for environment management), pyenv
(for Python version management), and twine
(for publishing packages), into a single interface.Blazing-Fast Performance:
UV is significantly faster than traditional tools like pip
and pip-tools
. Benchmarks indicate it can be 8 to 10 times faster without caching, and up to 80 to 115 times faster with a warm cache. This speed is attributed to its implementation in Rust, which allows for parallel package downloads and installations, and efficient caching mechanisms.
Unified Tooling:
UV combines the functionality of multiple tools, including:
pip
(for installing packages)pip-tools
(for dependency resolution)poetry
(for project management)virtualenv
(for environment management)pyenv
(for Python version management)twine
(for publishing packages)Drop-in Replacement:
UV provides a familiar interface for users of pip
, making it easy to adopt. For example, instead of running:
pip install django
You can run:
uv pip install django
Dependency Management:
UV supports managing dependencies via pyproject.toml
and uv.lock
files, ensuring reproducible builds and compatibility across environments. It also supports alternate resolution strategies, such as resolving against the lowest-compatible version of dependencies (--resolution=lowest
), and allows resolutions against arbitrary target Python versions.
Environment Management:
UV simplifies the creation and management of isolated Python environments. Virtual environments created by UV are standards-compliant and work interchangeably with other tools.
Cross-Platform Support:
UV works seamlessly across Windows, macOS, and Linux.
Advanced Features:
Support for disposable environments, dependency groups (e.g., dev vs. production), and Docker integration. It also supports editable installs, Git dependencies, URL dependencies, local dependencies, constraint files, source distributions, and custom indexes.
Strictness and Spec Enforcement:
UV is stricter than pip
and rejects packages with invalid version specifiers in their metadata. It also implements lenient behavior for popular packages with known spec compliance issues.
UV can be installed using several methods:
Standalone Installer:
macOS and Linux:
curl -LsSf https://astral.sh/uv/install.sh | sh
Alternatively, use wget
:
wget -qO- https://astral.sh/uv/install.sh | sh
To request a specific version:
curl -LsSf https://astral.sh/uv/0.5.8/install.sh | sh
Windows:
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
Using Package Managers:
pipx
or other package managers:
pipx install uv
pip
:
pip install uv
For detailed installation instructions, refer to the official installation guide.
Installing Packages:
UV can be used as a faster alternative to pip
for installing packages:
uv pip install flask
Managing Dependencies:
UV supports dependency resolution and lockfile generation:
uv lock
This generates a uv.lock
file, which ensures consistent dependencies across environments.
Creating Virtual Environments:
UV simplifies environment creation:
uv venv
To activate the virtual environment:
.\.venv\Scripts\activate
source .venv/bin/activate
Switching Python Versions:
UV can manage Python installations and versions:
uv python install 3.11
uv python use 3.11
Publishing Packages:
UV can replace twine
for publishing Python packages:
uv publish
Syncing Your Environment:
To keep your virtual environment aligned with your project's dependency requirements:
uv sync
This command installs missing dependencies, upgrades or downgrades existing packages to match the specified versions, and removes unnecessary packages.
Resolving Dependencies:
To lock your dependencies, use:
uv pip compile
This command generates a lock file that can be used to ensure consistent dependency versions across different environments.
Here are some examples of how to use UV effectively in a Python project:
Initialize a New Project:
uv init
This creates a pyproject.toml
file for your project.
Add Dependencies:
uv add django requests
This installs django
and requests
and updates the pyproject.toml
file.
Generate a Lockfile:
uv lock
This resolves dependencies and creates a uv.lock
file.
Create a Virtual Environment:
uv env create
Run Your Project:
uv run python manage.py runserver
Publish Your Package:
uv publish
Setting Up a New Project:
uv init my_project
cd my_project
uv add flask
This initializes a new project, installs Flask, and sets up a virtual environment.
Installing Development Dependencies:
uv add --group dev pytest black
This adds pytest
and black
as development dependencies.
Locking and Syncing Dependencies:
uv lock
uv sync
This locks the dependencies in uv.lock
and ensures the environment matches the lock file.
Running Python Scripts:
uv run python app.py
This runs the app.py
script within the project's environment.
Building and Publishing a Package:
uv build
uv publish
This builds the project into a distributable package and publishes it to PyPI.
Speed:
UV is significantly faster than pip
, conda
, and poetry
, making it ideal for large projects with many dependencies. It achieves this through its Rust implementation and efficient caching mechanisms.
Unified Tooling:
UV replaces multiple tools, reducing the need to switch between different utilities. It combines the functionalities of pip
, pip-tools
, and virtualenv
into a single tool, simplifying the workflow and reducing the complexity of managing multiple tools.
Reproducibility:
UV lockfiles ensure consistent dependency resolution across environments.
Ease of Use:
UV provides a simple and intuitive interface, making it accessible to both beginners and experienced developers.
Cross-Platform Support:
Unlike conda
, which is more focused on scientific computing, UV is a general-purpose tool that works across all platforms.
Strict Dependency Management:
UV is stricter about package metadata and version specifiers, which can help in maintaining a more reliable and consistent dependency environment.
Cross-Version Compatibility:
UV can manage dependencies across different Python versions without the need to manage separate pip
installations for each version.
Efficiency:
UV offers better disk space management and dependency resolution.
Modern Features:
UV supports advanced features like inline dependency metadata for scripts, workspace support, and more.
Official Documentation:
In-Depth Guides:
Blog Posts:
UV vs. PIP: Revolutionizing Python Package Management
UV: An In-Depth Guide to Python's Fast and Ambitious New Package Manager
GitHub Repository:
UV is a significant advancement in Python package and project management. Its speed, unified tooling, and modern features make it a compelling choice for developers looking to streamline their workflows. By adopting UV, you can replace multiple tools with a single, efficient solution, making your Python development experience faster and more enjoyable. While it is a relatively new tool, its development by the team behind Ruff suggests a strong foundation and continued improvement in the future. Its integration with Rust for performance, along with support for modern Python development practices, makes it an attractive alternative or complement to existing tools like pip or conda. However, its adoption might depend on community acceptance and the evolution of its ecosystem support.