UV - Fast Python Package Manager
Install UV
# On macOS and Linux
curl -LsSf https://astral.sh/uv/install.sh | sh
# On Windows
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
# Using pip
pip install uv
# Using pipx
pipx install uv
Project Management
# Initialize a new project
uv init example
cd example
# Add dependencies
uv add ruff
uv add requests pandas
# Create/update lockfile
uv lock
# Sync dependencies from lockfile
uv sync
Tool Management
# Run tool in ephemeral environment
uvx pycowsay 'hello world!'
# Install tool permanently
uv tool install ruff
# Run installed tool
ruff --version
Script Management
# Add dependencies to a script
uv add --script example.py requests
# Run script in isolated environment
uv run example.py
Python Version Management
# Install Python versions
uv python install 3.10 3.11 3.12
# Create venv with specific Python version
uv venv --python 3.12.0
# Pin Python version for project
uv python pin 3.11
Pip Interface Commands
# Compile requirements
uv pip compile requirements.in --output-file requirements.txt
# Create virtual environment
uv venv
# Install from requirements
uv pip sync requirements.txt
Command | Description |
---|---|
uv init <name> | Initialize new project |
uv add <package> | Add dependency to project |
uv lock | Generate lockfile |
uv sync | Install from lockfile |
uv run <script> | Run Python script |
uv venv | Create virtual environment |
uvx <tool> | Run tool in ephemeral env |
UV is an extremely fast Python package and project manager written in Rust. It aims to replace multiple tools like pip, pip-tools, pipx, poetry, pyenv, and virtualenv with a single unified solution. The tool offers 10-100x faster performance compared to pip and includes features like universal lockfiles, workspace support, and global dependency deduplication.
Enjoy Reading This Article?
Here are some more articles you might like to read next: