| name | uv-workflow |
| description | Master uv package manager for Python: project setup, dependency management, virtual environments,
lockfiles, CI/CD integration, Docker builds, and migration from pip/poetry.
MUST BE USED when user mentions: "uv", "uv add", "uv run", "uv sync", "uv init", "uv lock",
"uv venv", "uv pip", "pyproject.toml", "python project setup", "python dependencies",
"virtual environment", "venv", "pip install", "poetry to uv", "migrate from pip",
"lockfile python", "requirements.txt", "setup.py", "pip freeze", "uv tool",
"install package", "add dependency", "python environment", "new python project",
"package manager python", "create project", "uv export", "uv cache", "uv python".
10-100x faster than pip. Covers init, add, sync, lock, run, Docker, CI/CD.
NOT for npm/pnpm/yarn (JS toolchain), Rust cargo, or deployment (use deployment-assistant). |
| allowed-tools | ["Bash","Read","Write","Edit","Grep","Glob","mcp__context7__resolve-library-id","mcp__context7__get-library-docs"] |
UV Package Manager
Ultra-fast Python package installer and resolver written in Rust. 10-100x faster than pip.
Quick Reference
uv init my-project
uv add requests pandas
uv add --dev pytest ruff
uv remove package
uv sync
uv lock
uv run pytest
uv venv
uv venv --python 3.12
uv python install 3.12
uv python pin 3.12
uv pip install -r requirements.txt
uv pip freeze > requirements.txt
Project Setup Pattern
uv init my-project && cd my-project
uv python pin 3.12
uv add fastapi uvicorn pydantic
uv add --dev pytest ruff mypy black
mkdir -p src/my_project tests
uv run pytest
Creates: pyproject.toml, .python-version, uv.lock, .venv/
pyproject.toml Standard
[project]
name = "my-project"
version = "0.1.0"
requires-python = ">=3.10"
dependencies = [
"requests>=2.31.0",
"pydantic>=2.0.0",
]
[project.optional-dependencies]
dev = [
"pytest>=7.4.0",
"ruff>=0.1.0",
"mypy>=1.5.0",
]
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
[tool.uv]
dev-dependencies = []
[tool.uv.workspace]
members = ["packages/*"]
Lockfile Workflow
uv lock
uv sync --frozen
uv lock --upgrade
uv lock --upgrade-package requests
uv lock --check
uv export --format requirements-txt > requirements.txt
Rule: Always commit uv.lock to version control.
Docker Integration
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
FROM python:3.12-slim
WORKDIR /app
COPY --from=builder /app/.venv .venv
COPY . .
ENV PATH="/app/.venv/bin:$PATH"
CMD ["python", "app.py"]
CI/CD (GitHub Actions)
name: Tests
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: astral-sh/setup-uv@v2
with:
enable-cache: true
- run: uv python install 3.12
- run: uv sync --all-extras --dev
- run: uv run pytest
- run: uv run ruff check .
Migration Guides
From pip
uv init
uv add -r requirements.txt
From poetry
uv sync
From pip-tools
uv lock && uv sync --frozen
Key Commands
| Command | Purpose |
|---|
uv init | Initialize project |
uv add PKG | Add dependency |
uv add --dev PKG | Add dev dependency |
uv remove PKG | Remove dependency |
uv sync | Install all deps |
uv sync --frozen | Install exact (CI) |
uv lock | Create/update lockfile |
uv run CMD | Run in venv |
uv venv | Create venv |
uv python install | Install Python |
uv python pin | Pin Python version |
uv cache clean | Clear cache |
Best Practices
- Always use
uv run instead of activating venv
- Commit
uv.lock to git
- Use
--frozen in CI for reproducible builds
- Pin Python version with
.python-version
- Separate dev deps from production deps
- Use workspaces for monorepos
- Export
requirements.txt for compatibility when needed