DEV Community

Alex Spinov
Alex Spinov

Posted on

uv Has a Free API — The Python Package Manager That's 100x Faster Than pip

TL;DR

uv by Astral (makers of Ruff) is a Python package manager written in Rust that replaces pip, pip-tools, pipx, poetry, pyenv, and virtualenv. It's 10-100x faster and works as a drop-in replacement.

What Is uv?

uv is the all-in-one Python toolchain:

  • 100x faster than pip — Rust-powered resolution and installation
  • Replaces everything — pip, pip-tools, poetry, pyenv, virtualenv, pipx
  • Python version management — install and manage Python versions
  • Lockfile — reproducible installs with uv.lock
  • Scripts — run single-file Python scripts with dependencies
  • Free — MIT/Apache 2.0

Quick Start

# Install uv
curl -LsSf https://astral.sh/uv/install.sh | sh

# Create a new project
uv init my-project
cd my-project

# Add dependencies
uv add fastapi uvicorn sqlalchemy

# Run your app
uv run python main.py

# Or run directly
uv run fastapi dev
Enter fullscreen mode Exit fullscreen mode

Replace pip

# Instead of: pip install requests
uv pip install requests

# Instead of: pip install -r requirements.txt
uv pip install -r requirements.txt

# Instead of: pip freeze > requirements.txt
uv pip freeze > requirements.txt

# 10-100x faster, same interface!
Enter fullscreen mode Exit fullscreen mode

Python Version Management (Replace pyenv)

# Install Python versions
uv python install 3.12
uv python install 3.11 3.10

# List installed versions
uv python list

# Pin version for project
uv python pin 3.12

# Use specific version
uv run --python 3.11 python script.py
Enter fullscreen mode Exit fullscreen mode

Project Management (Replace Poetry)

# Initialize with pyproject.toml
uv init my-api

# Add dependencies
uv add fastapi
uv add sqlalchemy>=2.0
uv add --dev pytest ruff mypy

# Remove dependencies
uv remove sqlalchemy

# Sync environment from lockfile
uv sync

# Update all dependencies
uv lock --upgrade
Enter fullscreen mode Exit fullscreen mode

Inline Script Dependencies

# /// script
# dependencies = [
#   "requests>=2.31",
#   "rich>=13.0",
# ]
# ///

import requests
from rich import print

response = requests.get("https://api.github.com/repos/astral-sh/uv")
data = response.json()
print(f"uv has {data['stargazers_count']} stars!")
Enter fullscreen mode Exit fullscreen mode
# Run it — uv auto-installs dependencies!
uv run script.py
Enter fullscreen mode Exit fullscreen mode

Replace pipx (Install CLI Tools)

# Instead of: pipx install ruff
uv tool install ruff

# Run without installing
uv tool run black --check .
uvx black --check .  # shorthand

# Run specific version
uvx ruff@0.8.0 check .
Enter fullscreen mode Exit fullscreen mode

Speed Comparison

Operation uv pip poetry
Install Django 0.5s 15s 25s
Resolve 500 deps 2s 45s 120s
Create virtualenv 0.01s 2s 3s
Cold install (no cache) 3s 30s 60s

pyproject.toml

[project]
name = "my-api"
version = "0.1.0"
requires-python = ">=3.11"
dependencies = [
    "fastapi>=0.115",
    "uvicorn>=0.32",
    "sqlalchemy>=2.0",
]

[tool.uv]
dev-dependencies = [
    "pytest>=8.0",
    "ruff>=0.8",
    "mypy>=1.13",
]
Enter fullscreen mode Exit fullscreen mode

Resources


Managing Python scraping projects? My Apify tools provide production web scrapers — manage them with uv for lightning-fast dependency management. Questions? Email spinov001@gmail.com

Top comments (0)