🚀 What is UV?
UV is an extremely fast Python package installer and resolver, written in Rust. It's designed to be a drop-in replacement for pip and pip-tools, with speeds 10-100x faster than traditional tools.
pip
~45s
poetry
~30s
uv
~1.5s
Getting Started with UV
1
Install UV
curl -LsSf https://astral.sh/uv/install.sh | sh
Install UV using the official installer script
2
Create Project
uv init my-project
Initialize a new Python project with pyproject.toml
3
Add Dependencies
uv add requests pandas
Add packages to your project dependencies
4
Create Virtual Environment
uv venv
Create an isolated Python environment
5
Install Dependencies
uv sync
Install all project dependencies from lock file
6
Run Commands
uv run python main.py
Execute Python scripts in the project environment
Essential UV Commands
uv init <project-name>
Create new project with pyproject.toml
uv init --lib
Initialize as a library project
uv init --app
Initialize as an application project
uv sync
Install dependencies from lock file
uv lock
Update the dependency lock file
uv add requests
Add package to dependencies
uv add --dev pytest
Add development dependency
uv add "django>=4.0"
Add with version constraint
uv add --optional typing numpy
Add to optional dependency group
uv remove requests
Remove package from dependencies
uv venv
Create virtual environment
uv venv --python 3.11
Create with specific Python version
uv python list
List available Python versions
uv python install 3.12
Install Python version
source .venv/bin/activate
Activate virtual environment
uv run python script.py
Run Python script in project environment
uv run --with requests python -c "import requests"
Run with additional dependencies
uv run pytest
Run tests using project dependencies
uv run --python 3.11 script.py
Run with specific Python version
uv pip install requests
Install package (pip compatibility)
uv pip install -r requirements.txt
Install from requirements file
uv pip freeze
List installed packages
uv pip uninstall requests
Uninstall package
uv pip compile requirements.in
Generate pinned requirements.txt
uv tree
Show dependency tree
uv show numpy
Show package information
uv cache clean
Clear package cache
uv version
Show UV version
uv self update
Update UV to latest version
📊 UV vs Traditional Tools
pip + venv
python -m venv .venv
pip install -r requirements.txt
pip freeze > requirements.txt
Poetry
poetry init
poetry add requests
poetry install
UV
uv init
uv add requests
uv sync
Pipenv
pipenv install
pipenv install requests
pipenv shell
📄 Sample pyproject.toml
[project]
name = "my-awesome-app"
version = "0.1.0"
description = "A sample Python project"
authors = [
{name = "Your Name", email = "you@example.com"}
]
requires-python = ">=3.8"
dependencies = [
"requests>=2.28.0",
"pandas>=1.5.0",
]
[project.optional-dependencies]
dev = [
"pytest>=7.0",
"black>=22.0",
"ruff>=0.1.0",
]
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"