Unified Python packaging with uv
Episode #476,
published Wed, Sep 4, 2024, recorded Tue, Sep 3, 2024
A couple of weeks ago, Charlie Marsh and the folks at Astral made another big splash with a major release of uv called "uv: Unified Python packaging" which has many far reaching features. We had to have Charlie on the show to give us the inside look into this development. Let's get to it.
Episode Deep Dive
1. Origins and Context
- Charlie Marsh’s background: Creator of the incredibly fast Python linter/formatter Ruff, which is written in Rust.
- Transition to uv: After the success of Ruff, Charlie and team at Astral embarked on building a high-performance Python packaging tool called uv.
2. uv as a Pip Alternative
- Initial Release Goal
- The first release of uv (in February 2024) aimed to behave similarly to pip (
uv pip install
,uv pip uninstall
, etc.) so developers could adopt it with minimal friction. - This was intentionally close to pip’s CLI to make it straightforward for those already using pip-based workflows.
- The first release of uv (in February 2024) aimed to behave similarly to pip (
- Performance and Simplicity
- Like Ruff, uv is written in Rust, making it very fast compared to typical Python-based installers.
- Emphasis on caching and optimization so repeated operations (e.g., re-installing or updating) are extremely quick.
3. Major New Features (August 2024 Release)
The new release, dubbed “uv: Unified Python Packaging,” packs in significant enhancements:
- Project Management Workflow
uv init
: Creates a new Python project with sensible defaults, generating apyproject.toml
.uv add
/uv remove
: Easily add or remove dependencies, updating the project’spyproject.toml
and lock file in one step.uv lock
/uv sync
: Generates and enforces a lock file for reproducible installs.uv run
: Automatically resolves dependencies (via the lock file), creates or updates the virtual environment, then runs the specified command in that environment.
- Tool Installation (Global CLI Tools)
uv tool install <pkg>
(aliased asuv install
in some docs) anduv tool run <pkg>
(aliased asuvx
) allow you to install global CLI tools.- Example:
uv tool install ruff
places Ruff on your PATH for repeated use. uvx ruff
can also install or update Ruff on-demand to the latest version before running it.uv tool upgrade --all
can mass-upgrade globally installed tools.
- Python Installation & Management
uv python install 3.12
: Installs Python itself if it’s not present—using Python Build Standalone, which ships prebuilt, optimized binaries for many OS/architecture combos.- Very fast installation—just download and unzip; no local compilation required.
uv venv --python 3.11
automatically downloads and creates a virtual environment with Python 3.11 if it’s missing.
- Script Execution with PEP 723-like Syntax
- Single-file scripts can declare dependencies at the top in a special syntax.
uv run <script.py>
: uv sees the script’s declared requirements, resolves them, and runs it in an ephemeral virtual environment.uv add --script <script.py> <dependencies>
can automatically insert or update those dependency lines in the script.
4. Emphasis on Virtual Environments
- uv takes a “virtual environment first” approach:
- By default, it requires a virtual environment to avoid issues with system Python.
- This ensures isolation and reproducibility, yet you can override if you truly want to install in the system environment.
5. Addressing Different Use Cases
- Global Tools: Replaces things like pipx for globally installed CLI apps (e.g., Ruff, Black, etc.).
- Local Projects: Similar to poetry or PDM, with
pyproject.toml
plus lock files. - One-off Scripts: Just run a script with ephemeral or embedded dependencies. No need for manual environment creation.
6. Key Tools, Projects, and Links
- Ruff (the Rust-based Python linter): https://github.com/astral-sh/ruff
- uv (the packaging tool itself): https://github.com/astral-sh/uv
- Python Build Standalone (used for pre-built Python installs): https://github.com/indygreg/python-build-standalone
Overall Takeaway
This episode underscored uv’s ambition to streamline Python development from every angle: installing Python itself, locking and syncing dependencies, running single-file scripts, and installing CLI tools globally. By combining Rust’s speed, thoughtful design of workflows, and alignment with Python standards like pyproject.toml
and PEP 723-style metadata, uv promises a unified, faster, and more integrated experience across a wide range of Python packaging scenarios.
Links from the show
Charlie Marsh on Twitter: @charliermarsh
Charlie Marsh on Mastodon: @charliermarsh
Episode follow up: Wrote up how we use uv at Talk Python: mkennedy.codes
uv: Unified Python packaging: astral.sh
Python executable management: astral.sh
Projects: astral.sh
Tools: astral.sh
Scripts: astral.sh
Rye and uv: August is Harvest Season for Python Packaging: lucumr.pocoo.org
Python Build Standalone releases: github.com
Rules: astral.sh
Watch this episode on YouTube: youtube.com
Episode transcripts: talkpython.fm
--- Stay in touch with us ---
Subscribe to Talk Python on YouTube: youtube.com
Talk Python on Bluesky: @talkpython.fm at bsky.app
Talk Python on Mastodon: talkpython
Michael on Bluesky: @mkennedy.codes at bsky.app
Michael on Mastodon: mkennedy
Charlie Marsh on Mastodon: @charliermarsh
Episode follow up: Wrote up how we use uv at Talk Python: mkennedy.codes
uv: Unified Python packaging: astral.sh
Python executable management: astral.sh
Projects: astral.sh
Tools: astral.sh
Scripts: astral.sh
Rye and uv: August is Harvest Season for Python Packaging: lucumr.pocoo.org
Python Build Standalone releases: github.com
Rules: astral.sh
Watch this episode on YouTube: youtube.com
Episode transcripts: talkpython.fm
--- Stay in touch with us ---
Subscribe to Talk Python on YouTube: youtube.com
Talk Python on Bluesky: @talkpython.fm at bsky.app
Talk Python on Mastodon: talkpython
Michael on Bluesky: @mkennedy.codes at bsky.app
Michael on Mastodon: mkennedy