Conference Presentation, Keynote
Charlie Marsh: uv: An Extremely Fast Python Package Manager
- Charlie Marsh, founder of Astral, introduces UV, a high-performance, all-in-one Python package manager written in Rust.
- Astral's primary tools include Ruff (a linter, formatter, and code transformer) and UV, both achieving tens of millions of monthly downloads and rapid enterprise adoption.
- UV functions as a unified drop-in replacement for pip, pipx, pyenv, virtualenv, and Poetry, aiming to replicate the streamlined, high-confidence experience of Rust's Cargo.
- Since its mid-February release, UV has reached 16 million downloads per month and now accounts for over 10% of all requests to PyPI.
- Unlike previous attempts, UV was built from scratch without inheriting dependencies or baggage from existing tools like pip, establishing a fully unified stack.
- The tool is designed to change user workflows by treating virtual environments as ephemeral, allowing destruction and recreation at negligible cost due to extreme speed.
- UV offers two interfaces: a pip-compatible interface (
uv pip install) for legacy workflow compatibility, and higher-level commands likeuv syncanduv lockfor declarative dependency management. - The core installation lifecycle involves finding the Python interpreter, discovering user requirements, resolving dependencies, and generating a lock file containing package metadata, SHA hashes, and source URLs.
- Python's lack of multiversion support forces the resolver to solve a Boolean Satisfiability (SAT) problem (NP-hard), as conflicting dependencies cannot be resolved by installing multiple package versions simultaneously.
- To address Python's marker syntax (platform/version-specific constraints), UV employs a "fork and merge" strategy, solving platform-specific graphs independently before merging them into a universal lock file.
- The marker resolution process utilizes Algebraic Decision Diagrams (ADTs) to normalize complex boolean expressions and efficiently test for disjointness, avoiding exponential complexity in graph traversal.
- UV handles packages with non-static metadata (requiring execution of
setup.py) by implementing heuristics to minimize the need to build source distributions solely to retrieve dependency lists. - Performance optimization strategies include Rust for low-level memory control, zero-copy serialization via the
zstdorarchivelibrary for deserialization, and range requests to fetch ZIP central directories without downloading entire wheels. - A custom version parsing algorithm represents over 90% of Python package versions as a single
u64integer, enabling direct integer comparison instead of complex vector operations. - UV's cache design stores unzipped archives directly, utilizing reflinking and hard linking to install packages into environments instantly without redundant file duplication.
- Zero-copy techniques are applied to metadata storage, where data is read from disk in its in-memory struct representation, ensuring deserialization time does not scale with data size.
- The tool avoids a second resolution phase at install time; instead, it performs a direct graph traversal on the pre-computed universal lock file to determine relevant packages for specific platforms.
- Future capabilities rely on cache efficiency for "warm" operations, where the majority of installs are satisfied by linking existing files rather than re-downloading or recompiling.