| name | uv-python |
| description | Standardize Python development using UV - a fast, unified package and project manager. Use when creating Python projects, managing dependencies, setting up virtual environments, installing Python versions, or optimizing Python workflows. Replaces pip, virtualenv, pyenv, poetry, and pipx with a single 10-100x faster tool. |
uv-python-manager
UV is the modern standard for Python package and project management in 2025, delivering 10-100x speed improvements while unifying pip, virtualenv, pyenv, poetry, and pipx into a single Rust-based tool.
When to Use This Skill
Use this skill when:
- Creating new Python projects
- Managing dependencies and lockfiles
- Setting up virtual environments
- Installing or switching Python versions
- Building or publishing packages
- Optimizing CI/CD pipelines
- Migrating from pip, poetry, or other tools
- Creating portable Python scripts
- Working with Docker containers
Core Principles
- Project-first workflow: Use
uv init and uv add instead of manual configuration
- Lock file discipline: Always commit
uv.lock for reproducibility
- Universal execution: Use
uv run instead of manual environment activation
- Version pinning: Use
.python-version for team consistency
- Fast by default: Leverage caching and parallel operations (8-100x faster than pip)
Quick Start
Installing UV
curl -LsSf https://astral.sh/uv/install.sh | sh
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"
uv self update
Creating a New Project
uv init my-project
cd my-project
uv add requests fastapi pandas
uv add --dev pytest ruff mypy
uv add --group docs sphinx
uv add --group test pytest-cov
uv run python main.py
uv run pytest
Essential Commands Reference
Project Lifecycle
uv init [name]
uv add <package>
uv add --dev <package>
uv add --group <name> <pkg>
uv remove <package>
uv sync
uv sync --frozen
uv sync --no-dev
uv run <command>
uv build
uv publish
Python Version Management
uv python install 3.12
uv python install 3.11 3.12
uv python list
uv python pin 3.12
uv python find
Virtual Environments
uv venv
uv venv --python 3.12
uv venv my-env
Lock File Management
uv lock
uv lock --upgrade
uv lock --upgrade-package <pkg>
uv lock --check
uv export --format requirements-txt > requirements.txt
Tool Management (replaces pipx)
uvx <tool>
uvx ruff check .
uv tool install <tool>
uv tool list
uv tool uninstall <tool>
Maintenance
uv cache clean
uv cache dir
uv self update
Project Structure Best Practices
Standard Layout
project/
├── .git/
├── .gitignore # Auto-generated by uv init
├── .python-version # Python version pin (COMMIT THIS)
├── README.md # Setup instructions
├── pyproject.toml # Project configuration (COMMIT THIS)
├── uv.lock # Universal lockfile (COMMIT THIS)
├── .venv/ # Virtual environment (DO NOT COMMIT)
├── src/
│ └── package/
│ ├── __init__.py
│ └── main.py
└── tests/
└── test_main.py
pyproject.toml Structure
[project]
name = "my-app"
version = "0.1.0"
description = "Application description"
readme = "README.md"
requires-python = ">=3.11"
dependencies = [
"requests>=2.31.0,<3.0.0",
"pandas>=2.0.0",
"fastapi[standard]>=0.115.0",
]
[project.optional-dependencies]
plotting = ["matplotlib>=3.7.0", "seaborn>=0.12.0"]
database = ["sqlalchemy>=2.0.0", "psycopg2-binary>=2.9.0"]
[dependency-groups]
dev = ["pytest>=8.0.0", "ruff>=0.3.0", "mypy>=1.8.0"]
test = ["pytest-cov>=4.1.0", "pytest-asyncio>=0.23.0"]
docs = ["sphinx>=7.0.0", "sphinx-rtd-theme>=2.0.0"]
Key Workflows
Dependency Management
Adding dependencies:
uv add requests
uv add requests pandas numpy
uv add "fastapi>=0.115.0,<1.0.0"
uv add "fastapi[standard]"
uv add --dev pytest ruff mypy
uv add --optional plotting matplotlib seaborn
Managing versions:
uv lock --upgrade
uv lock --upgrade-package requests
uv add requests --upgrade
Running Code
Always use uv run instead of activating environments:
uv run python script.py
uv run python -m mymodule
uv run pytest
uv run ruff check .
uv run mypy src/
uv run --python 3.12 python script.py
uv run pytest tests/ -v --cov
Why uv run is better:
- Auto-syncs environment before running
- Works cross-platform without activation scripts
- Ensures reproducibility
- Handles environment discovery automatically
Inline Script Dependencies (PEP 723)
Create portable single-file scripts:
import requests
from rich import print
response = requests.get("https://api.github.com")
print(response.json())
Run with: uv run script.py (automatically installs dependencies)
Python Version Management
Project-level pinning:
uv python pin 3.12
uv run python --version
Installing Python versions:
uv python install 3.12
uv python install 3.11 3.12 3.13
uv python list --all-versions
uv python list
CI/CD Integration
GitHub Actions example:
name: CI
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up UV
uses: astral-sh/setup-uv@v6
with:
version: "0.9.5"
enable-cache: true
- name: Set up Python
run: uv python install
- name: Install dependencies
run: uv sync --frozen
- name: Check lock file is current
run: uv lock --check
- name: Run tests
run: uv run pytest
- name: Run linting
run: uv run ruff check .
Docker optimization:
FROM python:3.12-slim
# Install UV
COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
# Set working directory
WORKDIR /app
# Copy dependency files
COPY pyproject.toml uv.lock ./
# Install dependencies with caching
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --frozen --no-dev
# Copy application code
COPY . .
# Compile bytecode for faster startup
ENV UV_COMPILE_BYTECODE=1
# Run application
CMD ["uv", "run", "python", "-m", "myapp"]
Multi-stage Docker build:
# Stage 1: Build
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 --mount=type=cache,target=/root/.cache/uv \
uv sync --frozen --no-dev --no-editable
# Stage 2: Runtime
FROM python:3.12-slim
WORKDIR /app
COPY --from=builder /app/.venv /app/.venv
COPY . .
ENV PATH="/app/.venv/bin:$PATH"
ENV UV_COMPILE_BYTECODE=1
CMD ["python", "-m", "myapp"]
Migration from Existing Tools
From pip/pip-tools
uvx migrate-to-uv
uv init
uv add -r requirements.txt
uv add --dev -r requirements-dev.txt
git add pyproject.toml uv.lock .python-version
git rm requirements.txt requirements-dev.txt
From Poetry
uvx migrate-to-uv
uv sync
uv add pkg
uv run cmd
From virtualenv/venv
uv init
uv add -r requirements.txt
uv run python script.py
Troubleshooting
Common Issues
Lock file out of sync:
uv lock
Python version not found:
uv python install 3.12
Dependency conflicts:
uv lock --verbose
uv lock --upgrade
uv lock --upgrade-package problematic-package
Cache issues:
uv cache clean
uv cache dir
Import resolution issues:
uv sync
uv sync --reinstall
Best Practices Checklist
- ✅ Always commit
uv.lock and .python-version to version control
- ✅ Use
uv sync --frozen in CI/CD pipelines
- ✅ Add
.venv/ to .gitignore and .dockerignore
- ✅ Pin UV version in CI for consistency
- ✅ Use
uv run instead of manual environment activation
- ✅ Specify
requires-python range in pyproject.toml
- ✅ Use dependency groups for dev tools, not optional-dependencies
- ✅ Test with
--resolution lowest for libraries
- ✅ Enable bytecode compilation in Docker:
UV_COMPILE_BYTECODE=1
- ✅ Use cache mounts in Docker for faster builds
- ✅ Run
uv lock --check in CI to catch outdated lockfiles
- ✅ Leverage inline script dependencies (PEP 723) for portable tools
- ✅ Document UV setup in README for team onboarding
Performance Impact
UV achieves dramatic speed improvements:
- 8-10x faster than pip without caching
- 80-115x faster with warm cache
- Virtual environment creation: 100ms vs 8 seconds (python -m venv)
- Complex dependency resolution: seconds vs minutes
- CI/CD impact: 30-65% faster builds
This speed enables new workflows like re-syncing environments on every command invocation without performance penalties.
Advanced Topics
For more specialized use cases, see:
Key Differences from Other Tools
vs pip
- Speed: 8-100x faster
- Lock files: Built-in universal lockfiles
- Python management: Can install Python versions
- Unified: Replaces pip + pip-tools + virtualenv
vs Poetry
- Speed: Significantly faster resolution and installation
- Lock files: Universal (cross-platform in one file)
- Simpler: Less configuration required
- Compatible: Reads Poetry's pyproject.toml
vs Conda
- Scope: Python-only (doesn't handle system dependencies)
- Speed: Much faster for Python packages
- Compatibility: Standard PyPI ecosystem
- Not a replacement: Use Conda when you need non-Python dependencies
Support and Resources
Summary
UV standardizes Python development by unifying package management, environment management, Python version management, and script execution into a single fast tool. The key workflow is:
uv init to create projects
uv add to manage dependencies
uv run to execute code
uv sync --frozen in CI/CD
- Commit
uv.lock and .python-version
This provides consistent, fast, reproducible Python workflows across all platforms.