๐งฉ What is UV? Link to heading
uv is a modern tool created by Astral (the creators of ruff ๐ฆ) designed to be the only manager you need in the Python ecosystem. Written in Rust, it is 10x to 100x faster than traditional tools.
โก Why is it so fast? Link to heading
- Global Cache: It doesn’t redownload what you already have.
- Hardlinks: It uses physical links to avoid duplicating files on your disk.
- Parallel Resolution: Resolves dependencies massively and efficiently.
โ๏ธ Installation Link to heading
# macOS & Linux
curl -LsSf https://astral.sh/uv/install.sh | sh
# Windows
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
๐ 1. Python Version Management Link to heading
Forget about pyenv or fighting with your system’s Python versions. uv downloads and manages Python versions for you.
# Install a specific version
uv python install 3.12
# List installed and available versions
uv python list
# Use a specific version for a project
uv venv --python 3.11
๐ฆ 2. Modern Project Workflow Link to heading
The recommended mode is to use uv as a project manager (similar to cargo or npm).
# Initialize a project
uv init my-project
cd my-project
# Add dependencies (updates pyproject.toml and uv.lock)
uv add fastapi uvicorn
# Sync the environment (installs everything missing)
uv sync
# View the dependency tree
uv tree
๐ ๏ธ 3. Tool Management (Pipx killer) Link to heading
You can install and run CLI tools in isolation without cluttering your global environment.
# Run a tool without installing it (on-the-fly)
uvx ruff check .
# Install a tool globally
uv tool install yt-dlp
uv tool install black
# List installed tools
uv tool list
๐งช 4. Migration and Compatibility Link to heading
If you are coming from a requirements.txt based workflow:
# Install from an existing file
uv pip install -r requirements.txt
# Export your project to requirements.txt (with hashes)
uv export --format requirements-txt > requirements.txt
๐งน 5. Useful Maintenance Commands Link to heading
| Action | Command |
|---|---|
| Update UV | uv self update |
| Clean Cache | uv cache clean |
| Generate Lockfile | uv lock |
| Run Script | uv run myscript.py |
| List packages | uv pip list |
๐ Conclusion Link to heading
uv is not just an incremental improvement; it’s a paradigm shift. It centralizes the management of versions, environments, and tools into a single fast and modern interface. If you’re not using it yet, today is the best day to migrate.