Python

Forget `pip install`, Use This Instead

Install Python packages up to 100x ⚡ faster than before.

Benedict Neo
bitgrit Data Science Publication
4 min readMar 27, 2024

--

Photo by NASA on Unsplash

While scrolling X (give me a follow!), I came across this tweet.

Who is this?

Charlie Marsh is the man behind Astral, a company that is:

about page #1

They’re building tools that enable developers to ship great software, faster

about page #2

Ruff

They first released Ruff, a 10–100x speed boost from existing linters like Flake8 and formatters like Black.

I’ve switched to Ruff for all my Python projects, it’s a must-have tool.

Read my article on Ruff here 👇

Now back to uv.

What is uv?

uv is a turbo-fast Python package installer and resolver, written in Rust as a high-speed drop-in substitute for pip, pip-tools, and virtualenv.

It’s 10–100x faster than pip and pip-tools: with a warm cache, uv installs are near-instant.

A few more highlights

  • Save Disk Space: uses a global cache to prevent duplicated dependencies
  • Works Everywhere: supports macOS, Linux, and Windows.
  • Easy to Install: You don’t need Python or Rust installed. You can use using curl, pip, or brew.
  • Advanced Features: supports dependency version overrides and alternative resolution strategies.
  • Better Error messages: Best-in-class error messages with a conflict-tracking resolver
  • Advanced pip: editable installs, git dependicies, local dependencies, source distributions

Why it’s Fast:

  • Rust: Rust is is known for its speed and safety
  • “resolver”: a smart way to figure out which versions of packages can work together.
  • global module cache: it remembers files it has already seen, so it doesn’t redownload or rebuild dependencies
  • Copy-on-Write and hardlinks: this helps minimize disk space usage.

The bigger vision of uv is to transform Python package management with its speed and reliability.

The next Poetry?

If you’ve been in the Python ecosystem long enough, you know how painful it is to setup a Python environment or to create a package.

Python Environment by xkcd

uv has plans to establish a “Cargo for Python,” a unified Python package and project manager that is extremely fast, reliable, and easy to use.

Think: a single binary that bootstraps your Python installation and gives you everything you need to be productive with Python, bundling not only pip, pip-tools, and virtualenv, but also pipx, tox, poetry, pyenv, ruff, and more.

Python tooling can be a low-confidence experience: it’s a significant amount of work to stand up a new or existing project, and commands fail in confusing ways. In contrast, when working in the Rust ecosystem, you trust the tools to succeed. The Astral toolchain is about bringing Python from a low-confidence to a high-confidence experience.

I’m excited to watch uv significantly improve the Python development experience!

Benchmarks

Let’s look at some numbers from their benchmarks

cold installation (8–10x faster)

This is equivalent to running uv pip sync on a new machine

uv is 8–10x faster than pip and pip-tools without caching.

source

warm installation (80–115x faster)

It is 80–115x faster when running with a warm cache (e.g., recreating a virtual environment or updating a dependency)

source

creating a venv

It’s about 80x faster than python -m venv and 7x faster than virtualenv

source

More in this benchmarks

installing transformers

I tested out uv on the transformers package by hugging face.

The speed difference is crystal clear.

pip (left), uv (right)

How to use?

Below are a couple commands you should keep in handy to start using uv.

From installation to syncing dependencies.

Find the code on Deepnote.

Installation

Create venv

Activate venv

Install packages

Here’s what it looks like installing torch.

Generate locked dependencies

Sync dependencies

That’s all for this article!

More on UV

If you want more information about uv, check out these links:

Check out this recent article on Summarizing emails with GPT4

Thanks for reading

Be sure to follow the bitgrit Data Science Publication to keep updated!

Want to discuss the latest developments in Data Science and AI with other data scientists? Join our discord server!

Follow Bitgrit below to stay updated on workshops and upcoming competitions!

Discord | Website | Twitter | LinkedIn | Instagram | Facebook | YouTube

--

--