Django
,Python
,UV
🤠 UV Roundup: Five good articles and a pre-commit tip
I have written quite a bit about UV on my micro blog, and I am happy to see more and more people adopt it. I have stumbled on so many good articles recently that I wanted to share them because every article points out something new or different about why UV works well for them.
If you are new to UV, it’s a new tool written by Astral, the creators of Ruff.
I like UV because it replaces, combines, or complements a bunch of Python tools into one tool and user developer experience without forcing a UV way of doing it. UV effectively solves the question, “Why do I need another Python tool?” to do everyday Python tasks.
Some reason I like UV after using it for months:
- It’s a faster pip and is really, really fast
- It can install and manage Python versions
- It can run and install Python scripts
- It can run single-file Python scripts along with their dependencies
- It can handle project lock files
While some people don’t care about UV being fast, it’s shaved minutes off my CI builds and container rebuilds, which means it has also saved me money and energy resources.
Overall thoughts on UV
Oliver Andrich’s UV — I am (somewhat) sold takes the approach of only using UV to set up a new Python environment. Oliver uses UV to install Python, aliases to call Python, and UV tool install to set up a few global utilities.
Using UV with Django
Anže Pečar’s UV with Django shows how to use UV to set up a new project with Django.
Switching from pyenv to UV
Will Guaraldi Kahn-Greene’s Switching from pyenv to uv was relatable for me because I also use pyenv, but I plan to slowly migrate to using only UV. I’m already halfway there, but I will have pyenv for my legacy projects for years because many aren’t worth porting yet.
Using UV and managing with Ansible
Adam Johnson’s Python: my new uv setup for development taught me to use uv cache prune
to clean up unused cache entries and shows how he manages his UV setup using Ansible.
Some notes on UV
Simon Willison’s Notes on UV is an excellent summary of Oliver’s notes.
A parting UV tip
If you are a pre-commit fan hoping for a version that supports UV, the pre-commit-uv
project does just that. I started updating my justfile recipes to bake just lint
to the following uv run
command, which speeds up running and installing pre-commit significantly.
$ uv run --with pre-commit-uv pre-commit run --all-files
pre-commit-uv
If you are attending DjangoCon US…
If you are attending DjangoCon US and want to talk UV, Django, Django News, Django Packages, hit me up while you are there.
I’ll be attending, volunteering, organizing, sponsoring, and sprinting around the venue in Durham, NC, for the next week starting this Friday.
We still have online and in-person tickets, but not much longer!
Thursday September 19, 2024