<< All versions
Skill v0.1.0
currentAutomated scan100/100xlx777/ccg-scholar/uv-package-manager
──Details
PublishedOctober 31, 2026 at 06:54 AM
Content Hashsha256:05eed3f130b0738c...
Git SHA660096fde1e1
──Files
Files (1 file, 15.7 KB)
SKILL.md15.7 KBactive
SKILL.md · 833 lines · 15.7 KB
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. version: 0.1.0
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
bash
# macOS/Linuxcurl -LsSf https://astral.sh/uv/install.sh | sh# Windows (PowerShell)powershell -c "irm https://astral.sh/uv/install.ps1 | iex"# Using pip (if you already have Python)pip install uv# Using Homebrew (macOS)brew install uv# Using cargo (if you have Rust)cargo install --git https://github.com/astral-sh/uv uv
Verify Installation
bash
uv --version# uv 0.x.x
Quick Start
Create a New Project
bash
# Create new project with virtual environmentuv init my-projectcd my-project# Or create in current directoryuv init .# Initialize creates:# - .python-version (Python version)# - pyproject.toml (project config)# - README.md# - .gitignore
Install Dependencies
bash
# Install packages (creates venv if needed)uv add requests pandas# Install dev dependenciesuv add --dev pytest black ruff# Install from requirements.txtuv pip install -r requirements.txt# Install from pyproject.tomluv sync
Virtual Environment Management
Pattern 1: Creating Virtual Environments
bash
# Create virtual environment with uvuv venv# Create with specific Python versionuv venv --python 3.12# Create with custom nameuv venv my-env# Create with system site packagesuv venv --system-site-packages# Specify locationuv venv /path/to/venv
Pattern 2: Activating Virtual Environments
bash
# Linux/macOSsource .venv/bin/activate# Windows (Command Prompt).venv\Scripts\activate.bat# Windows (PowerShell).venv\Scripts\Activate.ps1# Or use uv run (no activation needed)uv run python script.pyuv run pytest
Pattern 3: Using uv run
bash
# Run Python script (auto-activates venv)uv run python app.py# Run installed CLI tooluv run black .uv run pytest# Run with specific Python versionuv run --python 3.11 python script.py# Pass argumentsuv run python script.py --arg value
Package Management
Pattern 4: Adding Dependencies
bash
# Add package (adds to pyproject.toml)uv add requests# Add with version constraintuv add "django>=4.0,<5.0"# Add multiple packagesuv add numpy pandas matplotlib# Add dev dependencyuv add --dev pytest pytest-cov# Add optional dependency groupuv add --optional docs sphinx# Add from gituv add git+https://github.com/user/repo.git# Add from git with specific refuv add git+https://github.com/user/repo.git@v1.0.0# Add from local pathuv add ./local-package# Add editable local packageuv add -e ./local-package
Pattern 5: Removing Dependencies
bash
# Remove packageuv remove requests# Remove dev dependencyuv remove --dev pytest# Remove multiple packagesuv remove numpy pandas matplotlib
Pattern 6: Upgrading Dependencies
bash
# Upgrade specific packageuv add --upgrade requests# Upgrade all packagesuv sync --upgrade# Upgrade package to latestuv add --upgrade requests# Show what would be upgradeduv tree --outdated
Pattern 7: Locking Dependencies
bash
# Generate uv.lock fileuv lock# Update lock fileuv lock --upgrade# Lock without installinguv lock --no-install# Lock specific packageuv lock --upgrade-package requests
Python Version Management
Pattern 8: Installing Python Versions
bash
# Install Python versionuv python install 3.12# Install multiple versionsuv python install 3.11 3.12 3.13# Install latest versionuv python install# List installed versionsuv python list# Find available versionsuv python list --all-versions
Pattern 9: Setting Python Version
bash
# Set Python version for projectuv python pin 3.12# This creates/updates .python-version file# Use specific Python version for commanduv --python 3.11 run python script.py# Create venv with specific versionuv venv --python 3.12
Project Configuration
Pattern 10: pyproject.toml with uv
toml
[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 = [# Additional dev dependencies managed by uv][tool.uv.sources]# Custom package sourcesmy-package = { git = "https://github.com/user/repo.git" }
Pattern 11: Using uv with Existing Projects
bash
# Migrate from requirements.txtuv add -r requirements.txt# Migrate from poetry# Already have pyproject.toml, just use:uv sync# Export to requirements.txtuv pip freeze > requirements.txt# Export with hashesuv pip freeze --require-hashes > requirements.txt
Advanced Workflows
Pattern 12: Monorepo Support
bash
# Project structure# monorepo/# packages/# package-a/# pyproject.toml# package-b/# pyproject.toml# pyproject.toml (root)# Root pyproject.toml[tool.uv.workspace]members = ["packages/*"]# Install all workspace packagesuv sync# Add workspace dependencyuv add --path ./packages/package-a
Pattern 13: CI/CD Integration
yaml
# .github/workflows/test.ymlname: Testson: [push, pull_request]jobs:test:runs-on: ubuntu-lateststeps:- uses: actions/checkout@v4- name: Install uvuses: astral-sh/setup-uv@v2with:enable-cache: true- name: Set up Pythonrun: uv python install 3.12- name: Install dependenciesrun: uv sync --all-extras --dev- name: Run testsrun: uv run pytest- name: Run lintingrun: |uv run ruff check .uv run black --check .
Pattern 14: Docker Integration
dockerfile
# DockerfileFROM python:3.12-slim# Install uvCOPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv# Set working directoryWORKDIR /app# Copy dependency filesCOPY pyproject.toml uv.lock ./# Install dependenciesRUN uv sync --frozen --no-dev# Copy application codeCOPY . .# Run applicationCMD ["uv", "run", "python", "app.py"]
Optimized multi-stage build:
dockerfile
# Multi-stage DockerfileFROM python:3.12-slim AS builder# Install uvCOPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uvWORKDIR /app# Install dependencies to venvCOPY pyproject.toml uv.lock ./RUN uv sync --frozen --no-dev --no-editable# Runtime stageFROM python:3.12-slimWORKDIR /app# Copy venv from builderCOPY --from=builder /app/.venv .venvCOPY . .# Use venvENV PATH="/app/.venv/bin:$PATH"CMD ["python", "app.py"]
Pattern 15: Lockfile Workflows
bash
# Create lockfile (uv.lock)uv lock# Install from lockfile (exact versions)uv sync --frozen# Update lockfile without installinguv lock --no-install# Upgrade specific package in lockuv lock --upgrade-package requests# Check if lockfile is up to dateuv lock --check# Export lockfile to requirements.txtuv export --format requirements-txt > requirements.txt# Export with hashes for securityuv export --format requirements-txt --hash > requirements.txt
Performance Optimization
Pattern 16: Using Global Cache
bash
# UV automatically uses global cache at:# Linux: ~/.cache/uv# macOS: ~/Library/Caches/uv# Windows: %LOCALAPPDATA%\uv\cache# Clear cacheuv cache clean# Check cache sizeuv cache dir
Pattern 17: Parallel Installation
bash
# UV installs packages in parallel by default# Control parallelismuv pip install --jobs 4 package1 package2# No parallel (sequential)uv pip install --jobs 1 package
Pattern 18: Offline Mode
bash
# Install from cache only (no network)uv pip install --offline package# Sync from lockfile offlineuv sync --frozen --offline
Comparison with Other Tools
uv vs pip
bash
# pippython -m venv .venvsource .venv/bin/activatepip install requests pandas numpy# ~30 seconds# uvuv venvuv add requests pandas numpy# ~2 seconds (10-15x faster)
uv vs poetry
bash
# poetrypoetry initpoetry add requests pandaspoetry install# ~20 seconds# uvuv inituv add requests pandasuv sync# ~3 seconds (6-7x faster)
uv vs pip-tools
bash
# pip-toolspip-compile requirements.inpip-sync requirements.txt# ~15 seconds# uvuv lockuv sync --frozen# ~2 seconds (7-8x faster)
Common Workflows
Pattern 19: Starting a New Project
bash
# Complete workflowuv init my-projectcd my-project# Set Python versionuv python pin 3.12# Add dependenciesuv add fastapi uvicorn pydantic# Add dev dependenciesuv add --dev pytest black ruff mypy# Create structuremkdir -p src/my_project tests# Run testsuv run pytest# Format codeuv run black .uv run ruff check .
Pattern 20: Maintaining Existing Project
bash
# Clone repositorygit clone https://github.com/user/project.gitcd project# Install dependencies (creates venv automatically)uv sync# Install with dev dependenciesuv sync --all-extras# Update dependenciesuv lock --upgrade# Run applicationuv run python app.py# Run testsuv run pytest# Add new dependencyuv add new-package# Commit updated filesgit add pyproject.toml uv.lockgit commit -m "Add new-package dependency"
Tool Integration
Pattern 21: Pre-commit Hooks
yaml
# .pre-commit-config.yamlrepos:- repo: localhooks:- id: uv-lockname: uv lockentry: uv locklanguage: systempass_filenames: false- id: ruffname: ruffentry: uv run ruff check --fixlanguage: systemtypes: [python]- id: blackname: blackentry: uv run blacklanguage: systemtypes: [python]
Pattern 22: VS Code Integration
json
// .vscode/settings.json{"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}}
Troubleshooting
Common Issues
bash
# Issue: uv not found# Solution: Add to PATH or reinstallecho 'export PATH="$HOME/.cargo/bin:$PATH"' >> ~/.bashrc# Issue: Wrong Python version# Solution: Pin version explicitlyuv python pin 3.12uv venv --python 3.12# Issue: Dependency conflict# Solution: Check resolutionuv lock --verbose# Issue: Cache issues# Solution: Clear cacheuv cache clean# Issue: Lockfile out of sync# Solution: Regenerateuv lock --upgrade
Best Practices
Project Setup
- Always use lockfiles for reproducibility
- Pin Python version with .python-version
- Separate dev dependencies from production
- Use uv run instead of activating venv
- Commit uv.lock to version control
- Use --frozen in CI for consistent builds
- Leverage global cache for speed
- Use workspace for monorepos
- Export requirements.txt for compatibility
- Keep uv updated for latest features
Performance Tips
bash
# Use frozen installs in CIuv sync --frozen# Use offline mode when possibleuv sync --offline# Parallel operations (automatic)# uv does this by default# Reuse cache across environments# uv shares cache globally# Use lockfiles to skip resolutionuv sync --frozen # skips resolution
Migration Guide
From pip + requirements.txt
bash
# Beforepython -m venv .venvsource .venv/bin/activatepip install -r requirements.txt# Afteruv venvuv pip install -r requirements.txt# Or better:uv inituv add -r requirements.txt
From Poetry
bash
# Beforepoetry installpoetry add requests# Afteruv syncuv add requests# Keep existing pyproject.toml# uv reads [project] and [tool.poetry] sections
From pip-tools
bash
# Beforepip-compile requirements.inpip-sync requirements.txt# Afteruv lockuv sync --frozen
Command Reference
Essential Commands
bash
# Project managementuv init [PATH] # Initialize projectuv add PACKAGE # Add dependencyuv remove PACKAGE # Remove dependencyuv sync # Install dependenciesuv lock # Create/update lockfile# Virtual environmentsuv venv [PATH] # Create venvuv run COMMAND # Run in venv# Python managementuv python install VERSION # Install Pythonuv python list # List installed Pythonsuv python pin VERSION # Pin Python version# Package installation (pip-compatible)uv pip install PACKAGE # Install packageuv pip uninstall PACKAGE # Uninstall packageuv pip freeze # List installeduv pip list # List packages# Utilityuv cache clean # Clear cacheuv cache dir # Show cache locationuv --version # Show version
Resources
- Official documentation: https://docs.astral.sh/uv/
- GitHub repository: https://github.com/astral-sh/uv
- Astral blog: https://astral.sh/blog
- Migration guides: https://docs.astral.sh/uv/guides/
- Comparison with other tools: https://docs.astral.sh/uv/pip/compatibility/
Best Practices Summary
- Use uv for all new projects - Start with
uv init - Commit lockfiles - Ensure reproducible builds
- Pin Python versions - Use .python-version
- Use uv run - Avoid manual venv activation
- Leverage caching - Let uv manage global cache
- Use --frozen in CI - Exact reproduction
- Keep uv updated - Fast-moving project
- Use workspaces - For monorepo projects
- Export for compatibility - Generate requirements.txt when needed
- Read the docs - uv is feature-rich and evolving