| name | uv-package-manager |
| description | Master the uv package manager for fast Python dependency management, virtual environments, and modern Python project workflows. Use when setting up Python projects, managing dependencies, or optimizing Python development workflows with uv. |
UV Package Manager
Comprehensive guide to using uv, an extremely fast Python package installer and resolver written in Rust, for modern Python project management and dependency workflows.
When to Use This Skill
- Setting up new Python projects quickly
- Managing Python dependencies faster than pip
- Creating and managing virtual environments
- Installing Python interpreters
- Resolving dependency conflicts efficiently
- Migrating from pip/pip-tools/poetry
- Speeding up CI/CD pipelines
- Managing monorepo Python projects
- Working with lockfiles for reproducible builds
- Optimizing Docker builds with Python dependencies
Core Concepts
1. What is uv?
- Ultra-fast package installer: 10-100x faster than pip
- Written in Rust: Leverages Rust's performance
- Drop-in pip replacement: Compatible with pip workflows
- Virtual environment manager: Create and manage venvs
- Python installer: Download and manage Python versions
- Resolver: Advanced dependency resolution
- Lockfile support: Reproducible installations
2. Key Features
- Blazing fast installation speeds
- Disk space efficient with global cache
- Compatible with pip, pip-tools, poetry
- Comprehensive dependency resolution
- Cross-platform support (Linux, macOS, Windows)
- No Python required for installation
- Built-in virtual environment support
3. UV vs Traditional Tools
- vs pip: 10-100x faster, better resolver
- vs pip-tools: Faster, simpler, better UX
- vs poetry: Faster, less opinionated, lighter
- vs conda: Faster, Python-focused
Installation
Quick Install
curl -LsSf https://astral.sh/uv/install.sh | sh
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"
pip install uv
brew install uv
cargo install --git https://github.com/astral-sh/uv uv
Verify Installation
uv --version
Quick Start
Create a New Project
uv init my-project
cd my-project
uv init .
Install Dependencies
uv add requests pandas
uv add --dev pytest black ruff
uv pip install -r requirements.txt
uv sync
Virtual Environment Management
Pattern 1: Creating Virtual Environments
uv venv
uv venv --python 3.12
uv venv my-env
uv venv --system-site-packages
uv venv /path/to/venv
Pattern 2: Activating Virtual Environments
source .venv/bin/activate
.venv\Scripts\activate.bat
.venv\Scripts\Activate.ps1
uv run python script.py
uv run pytest
Pattern 3: Using uv run
uv run python app.py
uv run black .
uv run pytest
uv run --python 3.11 python script.py
uv run python script.py --arg value
Package Management
Pattern 4: Adding Dependencies
uv add requests
uv add "django>=4.0,<5.0"
uv add numpy pandas matplotlib
uv add --dev pytest pytest-cov
uv add --optional docs sphinx
uv add git+https://github.com/user/repo.git
uv add git+https://github.com/user/repo.git@v1.0.0
uv add ./local-package
uv add -e ./local-package
Pattern 5: Removing Dependencies
uv remove requests
uv remove --dev pytest
uv remove numpy pandas matplotlib
Pattern 6: Upgrading Dependencies
uv add --upgrade requests
uv sync --upgrade
uv add --upgrade requests
uv tree --outdated
Pattern 7: Locking Dependencies
uv lock
uv lock --upgrade
uv lock --no-install
uv lock --upgrade-package requests
Python Version Management
Pattern 8: Installing Python Versions
uv python install 3.12
uv python install 3.11 3.12 3.13
uv python install
uv python list
uv python list --all-versions
Pattern 9: Setting Python Version
uv python pin 3.12
uv --python 3.11 run python script.py
uv venv --python 3.12
Project Configuration
Pattern 10: pyproject.toml with uv
[project]
name = "my-project"
version = "0.1.0"
description = "My awesome project"
readme = "README.md"
requires-python = ">=3.8"
dependencies = [
"requests>=2.31.0",
"pydantic>=2.0.0",
"click>=8.1.0",
]
[project.optional-dependencies]
dev = [
"pytest>=7.4.0",
"pytest-cov>=4.1.0",
"black>=23.0.0",
"ruff>=0.1.0",
"mypy>=1.5.0",
]
docs = [
"sphinx>=7.0.0",
"sphinx-rtd-theme>=1.3.0",
]
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
[tool.uv]
dev-dependencies = [
]
[tool.uv.sources]
my-package = { git = "https://github.com/user/repo.git" }
Pattern 11: Using uv with Existing Projects
uv add -r requirements.txt
uv sync
uv pip freeze > requirements.txt
uv pip freeze --require-hashes > requirements.txt
For advanced workflows including Docker integration, lockfile management, performance optimization, tool comparison, common workflows, tool integration, troubleshooting, best practices, migration guides, and command reference, see references/advanced-patterns.md