| name | uv-package-manager |
| version | 1.1.1 |
| description | Speeds Python packaging with Astral uv: uv init, venvs, lockfiles, interpreter install, pip-compat, workspace monorepos, and Docker/CI installs. Use when setting up Python projects, migrating from pip/poetry/pip-tools, or fixing resolver conflicts. Not for conda channels, non-Python packages, or Python 2.7; never assume uv runs where Rust binaries cannot execute. |
| risk | safe |
| source | openrouter-deepsearch |
| date_added | 2026-06-14T00:00:00.000Z |
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. uv is 10–100x faster than pip, acts as a drop-in pip replacement, manages virtual environments, installs Python interpreters, and produces lockfiles for reproducible builds.
When to Use
- Setting up new Python projects quickly
- Managing Python dependencies faster than pip
- Creating and managing virtual environments
- Installing and pinning Python interpreters
- Resolving dependency conflicts efficiently
- Migrating from pip / pip-tools / poetry
- Speeding up CI/CD pipelines
- Managing monorepo Python projects with workspaces
- Working with lockfiles for reproducible builds
- Optimizing Docker builds with Python dependencies
Do NOT use uv when:
- You require conda-specific packages or environments (use conda/mamba instead)
- You need non-Python language package management
- You need advanced conda features (channels, complex binary dependencies)
- The target environment cannot execute Rust binaries
- Legacy Python 2.7 projects (uv requires Python 3.8+)
- Deprecation warning: Avoid using
uv with Python < 3.8 — no longer supported.
- Security warning: Be cautious when using
uv with untrusted packages.
Prerequisites
- A supported OS: Linux, macOS, or Windows (Windows PowerShell is the primary host for this skill)
- Python 3.8+ available or installable (uv can bootstrap Python itself)
- Network access for initial install and package downloads (offline mode available after cache populated)
- For Windows PowerShell: execution policy must allow script activation (
.venv\Scripts\Activate.ps1)
Install uv
# Windows (PowerShell) — primary host
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"
curl -LsSf https://astral.sh/uv/install.sh | sh
pip install uv
brew install uv
cargo install --git https://github.com/astral-sh/uv uv
Verify Installation
uv --version
Procedure
1. Create a New Project
uv init my-project
cd my-project
uv init .
2. Install Dependencies
uv add requests pandas
uv add --dev pytest black ruff
uv pip install -r requirements.txt
uv sync
3. Virtual Environment Management
uv venv
uv venv --python 3.12
uv venv my-env
uv venv --system-site-packages
uv venv /path/to/venv
Activate the venv:
source .venv/bin/activate
.venv\Scripts\activate.bat
.venv\Scripts\Activate.ps1
Prefer uv run (no activation needed):
uv run python script.py
uv run pytest
uv run --python 3.11 python script.py
uv run python script.py --arg value
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
5. Removing Dependencies
uv remove requests
uv remove --dev pytest
uv remove numpy pandas matplotlib
6. Upgrading Dependencies
uv add --upgrade requests
uv sync --upgrade
uv tree --outdated
7. Locking Dependencies
uv lock
uv lock --upgrade
uv lock --no-install
uv lock --upgrade-package requests
8. Python Version Management
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
uv python pin 3.12
uv --python 3.11 run python script.py
uv venv --python 3.12
9. pyproject.toml Configuration
[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" }
10. Migrating from Other Tools
uv add -r requirements.txt
uv sync
uv pip freeze > requirements.txt
uv pip freeze --require-hashes > requirements.txt
11. Monorepo / Workspace Support
[tool.uv.workspace]
members = ["packages/*"]
uv sync
uv add --path ./packages/package-a
12. CI/CD Integration (GitHub Actions)
name: Tests
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v2
with:
enable-cache: true
- name: Set up Python
run: uv python install 3.12
- name: Install dependencies
run: uv sync --all-extras --dev
- name: Run tests
run: uv run pytest
- name: Run linting
run: |
uv run ruff check .
uv run black --check .
13. Docker Integration
Single-stage:
FROM python:3.12-slim
# Install uv from official image
COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
WORKDIR /app
# Copy dependency files first for cache efficiency
COPY pyproject.toml uv.lock ./
RUN uv sync --frozen --no-dev
COPY . .
CMD ["uv", "run", "python", "app.py"]
Multi-stage (optimized):
FROM python:3.12-slim AS builder
COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
WORKDIR /app
COPY pyproject.toml uv.lock ./
RUN uv sync --frozen --no-dev --no-editable
# Runtime stage
FROM python:3.12-slim
WORKDIR /app
COPY --from=builder /app/.venv .venv
COPY . .
ENV PATH="/app/.venv/bin:$PATH"
CMD ["python", "app.py"]
14. Lockfile Workflows
uv lock
uv sync --frozen
uv lock --no-install
uv lock --upgrade-package requests
uv lock --check
uv export --format requirements-txt > requirements.txt
uv export --format requirements-txt --hash > requirements.txt
15. Performance Optimization
uv cache clean
uv cache dir
uv pip install --jobs 4 package1 package2
uv pip install --jobs 1 package
uv pip install --offline package
uv sync --frozen --offline
16. Pre-commit Hooks
repos:
- repo: local
hooks:
- id: uv-lock
name: uv lock
entry: uv lock
language: system
pass_filenames: false
- id: ruff
name: ruff
entry: uv run ruff check --fix
language: system
types: [python]
- id: black
name: black
entry: uv run black
language: system
types: [python]
17. VS Code Integration
{
"python.defaultInterpreterPath": "${workspaceFolder}/.venv/bin/python",
"python.terminal.activateEnvironment": true,
"python.testing.pytestEnabled": true,
"python.testing.pytestArgs": ["-v"],
"python.linting.enabled": true,
"python.formatting.provider": "black",
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.formatOnSave": true
}
}
Windows note: On Windows the interpreter path is ${workspaceFolder}/.venv/Scripts/python.exe.
Examples
Complete New Project Workflow
uv init my-project
cd my-project
uv python pin 3.12
uv add fastapi uvicorn pydantic
uv add --dev pytest black ruff mypy
mkdir -p src/my_project tests
uv run pytest
uv run black .
uv run ruff check .
Maintaining an Existing Project
git clone https://github.com/user/project.git
cd project
uv sync
uv sync --all-extras
uv lock --upgrade
uv run python app.py
uv run pytest
uv add new-package
git add pyproject.toml uv.lock
git commit -m "Add new-package dependency"
Migration Cheatsheet
| From | Before | After |
|---|
| pip + requirements.txt | python -m venv .venv && pip install -r requirements.txt | uv venv && uv pip install -r requirements.txt (or uv init && uv add -r requirements.txt) |
| poetry | poetry install && poetry add requests | uv sync && uv add requests |
| pip-tools | pip-compile requirements.in && pip-sync requirements.txt | uv lock && uv sync --frozen |
Pitfalls
- uv not found after install: Ensure uv binary is on PATH. On Windows, the installer updates PATH for new shells; restart your terminal. On Linux/macOS add
export PATH="$HOME/.cargo/bin:$PATH" to your shell rc.
- Wrong Python version selected: Always pin explicitly with
uv python pin 3.12 and create venv with uv venv --python 3.12.
- Dependency conflict unresolved: Run
uv lock --verbose to inspect resolution steps.
- Cache corruption or stale cache: Run
uv cache clean then re-sync.
- Lockfile out of sync with pyproject.toml: Regenerate with
uv lock --upgrade; never manually edit uv.lock.
- Windows PowerShell activation blocked: If
Activate.ps1 fails, set execution policy for the current user: Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser. Alternatively, use uv run to avoid activation entirely.
- Docker image bloat: Use multi-stage builds and
--no-dev --no-editable --frozen to keep runtime image small.
- CI flakiness from floating versions: Always commit
uv.lock and use uv sync --frozen in CI.
- Untrusted packages: Be cautious installing untrusted packages; they may pose security risks.
- Python < 3.8 unsupported: uv requires Python 3.8+; do not attempt to use with Python 2.7.
Verification
uv --version
uv venv
uv pip list
uv lock --check
cat .python-version
uv cache dir
uv run python -c "import requests; print(requests.__version__)"
Related Skills
- python-project-setup — scaffolding Python project structure
- ruff-linter — fast Python linting with ruff
- black-formatter — Python code formatting
- pytest-testing — Python test workflows
- docker-python — containerizing Python applications