Taking a minor detour from our Design Patterns series for the weekend.
I’m a sucker for “a better mousetrap”, as they say on Shark Tank when it comes to anything related to packaging on Python. So when I came across this latest nifty library that promised to make pip package installation much faster than pip, I immediately decided to try it out.
And post a few experiments, both naive and as required for my daily driver environments, it turns out uv
is actually really fast!
For example, here’s the set of steps I did to try this out.
Installed Anaconda on Windows
Created a new conda environment called py312 with python=3.12. If I were using WSL, I would have used the deadsnakes PPA provided by Anthony Sottile and followed the steps in one of the many, many blogs. But I’m using Windows for these experiments and therefore downloaded and installed the Python3.12 binary.
Activated the environment - `
conda activate py312
`Installed the flask package using pip and timed how long it took to install. On WSL, I would have used
time
. On CMD though, I used my own variation of Ubuntu’stime
post execution ofpip install flask
and the installation took ~4 seconds.Next I uninstalled the package and then attempted to reinstall it using uv.
The way to use “uv” is to first install it in an activated conda/virtualenv environment -
pip install uv
Next using "uv”, repeat the installation step -
As seen in the screenshot above, there seems to be huge reduction in time from 4 seconds to 1 second.
This is pretty fast.
Now what if we have to install a bunch of requirements from a file in an environment?
We’d normally do “pip install -r requirements.txt
” from within the environment.
We can do the same using uv since it is a drop-in replacement.
Considering a requirements.txt file with the following entries -
flask==2.2.2
pydantic==1.9.1
requests==2.28.1
sqlalchemy==1.4.36
pytest==7.1.2
Using pip to install them -
…
Using uv pip
to install them -
Time taken by pip = 171 seconds
Time taken by uv pip = 79 seconds.
A net 2.1x improvement! This shows how much faster uv pip can be .
Now obviously it might suffer the disadvantages of being new and not completely at par with the more mature pip. But those limitations will have to wait for a later edition.
Benchmarks - https://github.com/astral-sh/uv/blob/main/BENCHMARKS.md