I heard about uv
and Astral last year and as I previously mentioned in this blog post, I did (and still have) have some concerns about them.
By the way, inspired by some work a colleague of mine is doing, I wanted to give it a chance and I checked if I could start using it without disrupting my pyenv
workflow.
Note: Even if you don’t want to migrate away from your favourite Python environment and virtualenv manager, there are a few ways to use it to speed up your existing configuration, so stay with me.
What is uv?
uv
is a package manager for Python which is written in Rust, it’s extremely fast and it’s becoming the favourite package manager across the Python community. As usual, please refer to the official website for more details: https://docs.astral.sh/uv/
Installing uv
It seems obvious but before proceeding with this tutorial, you need to install uv
. There are a few different ways described in the official documentation, but if you are using MacOS and also use brew
, you can install it with:
|
|
Using uv pip
uv
reimplements pip
so instead of doing pip install -r requirements.txt
you can do uv pip install requirements.txt
(or similar), and believe me: It’s faster!
This is a pip
command I used to upgrade the dependencies in the virtual environment of one of the work projects (I only renamed the project name)
|
|
The speed is impressive! I almost thought the command had failed because it finished so quickly. You can find more details in the docs: https://docs.astral.sh/uv/pip/packages/
Using nox[uv]
For the same project, we use nox
as a wrapper to run tests and it takes care of creating specific virtual environments. By default it uses virtualenv
but there is a simple trick to make it use uv
.
First you need to install nox[uv]
|
|
Then you just need to set this environment variable:
|
|
That’s it! I can’t provide the full output of our test suite, but I timed (time nox -s test ...
) the execution and by using uv
as backend, our virtual environment is created 13 seconds faster!
Conclusion
I used “part 1” as suffix for this blog post, because I’m sure these experiments will continue in the next days, by using more of the available uv
tools. Once I’ve learned more, I will share my experience again.