| name | uv-expert |
| description | Expert guidance for uv Python package and project manager. Use when working with uv, Python dependency management, project setup, virtual environments, or when users mention uv commands, pip alternatives, or fast Python package management. |
UV Expert
Expert guidance for uv, the extremely fast Python package and project manager written in Rust. UV provides a unified interface for Python dependency management, project creation, virtual environments, and more.
Additional Resources
For detailed API documentation and configuration options, see the UV Source Documentation which includes:
For performance benchmarks and technical details, refer to BENCHMARKS.md in the source code.
For troubleshooting common issues, see the Troubleshooting Guide.
The complete source code and implementation details are available at source/uv/.
Instructions
Core UV Concepts
UV is a comprehensive Python tool that replaces:
pip (package installation)
pip-tools (dependency resolution)
pipx (tool installation)
poetry (project management)
pyenv (Python version management)
virtualenv (virtual environments)
twine (package publishing)
Installation
Recommended installation methods:
curl -LsSf https://astral.sh/uv/install.sh | sh
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
pip install uv
pipx install uv
Project Management
Initialize new projects:
uv init my-project
cd my-project
uv init my-project --python 3.11
uv init
Dependency management:
uv add requests pandas
uv add --dev pytest black
uv add "requests>=2.28.0"
uv remove requests
uv lock --upgrade
Project execution:
uv run python main.py
uv run pytest
uv run black .
uv run script.py
Virtual Environments
Environment management:
uv venv
uv venv --python 3.11
source .venv/bin/activate
.venv\Scripts\activate
uv pip install requests
uv python script.py
Package Installation
** pip-compatible interface:**
uv pip install requests pandas
uv pip install -r requirements.txt
uv pip install -c constraints.txt
uv pip install -e .
uv pip uninstall requests
Python Version Management
Python version management:
uv python list
uv python install 3.11
uv python pin 3.11
uv run --python 3.11 script.py
Tool Management
Install and manage tools:
uv tool install ruff
uv tool install pytest
uv run ruff check .
uv run pytest
uv tool list
uv tool uninstall ruff
Scripts Support
Run scripts with inline dependencies:
import requests
import typer
def main():
response = requests.get("https://api.github.com")
print(f"Status: {response.status_code}")
if __name__ == "__main__":
typer.run(main)
uv run script.py
Advanced Features
Workspaces:
[tool.uv.workspace]
members = ["packages/*"]
uv add requests --workspace
uv sync --workspace
Caching:
uv cache clean
uv cache info
uv sync --cache-dir ~/.cache/uv
Configuration:
uv config set global.cache-dir ~/.cache/uv
uv config show
[global]
cache-dir = "~/.cache/uv"
index-url = "https://pypi.org/simple"
Common Workflows
1. Set up new project:
uv init my-project
cd my-project
uv add requests pytest --dev
uv run pytest
2. Work on existing project:
git clone <repo>
cd <repo>
uv sync
uv run python main.py
3. Migrate from pip:
uv pip install package
uv add package
uv lock
4. CI/CD integration:
uv sync
uv run pytest
uv build
Performance Benefits
UV is 10-100x faster than pip:
- Parallel downloads and installations
- Efficient caching
- Rust-based performance
- Global dependency deduplication
Use UV when you need:
- Faster dependency resolution
- Unified Python toolchain
- Modern Python project management
- Better caching and performance
- Cross-platform consistency
Migration Guides
From pip:
- Replace
pip install with uv add (for projects) or uv pip install (standalone)
- Replace
pip freeze with uv pip freeze or use uv.lock
- Replace
venv with uv venv
From poetry:
pyproject.toml format is compatible
- Replace
poetry add with uv add
- Replace
poetry install with uv sync
- Replace
poetry run with uv run
From conda:
- Use UV for Python packages, conda for system packages
- Migrate environment.yml to pyproject.toml
- Use
uv venv instead of conda environments
Best Practices
1. Project Structure:
my-project/
├── pyproject.toml
├── uv.lock
├── src/
└── tests/
2. Dependency Management:
- Use
uv add for project dependencies
- Use
uv add --dev for development dependencies
- Keep
uv.lock in version control
- Use
uv sync to reproduce environments
3. Virtual Environments:
- Always use virtual environments
- Use
uv run instead of manual activation
- Delete
.venv when switching Python versions
4. Performance:
- Let UV manage the cache automatically
- Use workspaces for multi-package projects
- Enable parallel operations where possible
Troubleshooting
Common issues:
- Cache corruption: Run
uv cache clean
- Python version conflicts: Use
uv python pin
- Network issues: Check
uv config get index-url
- Permission errors: Use user installations or virtual environments
Debug mode:
uv --verbose sync
uv add package --verbose
Integration Examples
With Docker:
FROM python:3.11-slim
COPY uv.lock pyproject.toml ./
RUN pip install uv && uv sync
COPY . .
CMD ["uv", "run", "python", "main.py"]
With GitHub Actions:
- name: Install uv
uses: astral-sh/setup-uv@v1
- name: Install dependencies
run: uv sync
- name: Run tests
run: uv run pytest
Resources