Juha-Matti Santala
Community Builder. Dreamer. Adventurer.

U is for uv - Python A to Z

Code in this blog post was written with versions: Python: 3.14, uv: 0.12.5

Python A-Z is a blog series about Python. Each day, I share insights, ideas and examples for different parts of Python development that match with the letter of the day. Blaugust is an annual blogging festival in August where the goal is to write a blog post every day of the month.

uv is a Python package and project manager but in my day-to-day use it’s more of a script and improved REPL runner. In Tame your pesky little scripts, I wrote about my methods for dealing with different scripts I run from a command line and for the ones I write in Python, I use uv to make them easy to run with dependencies.

For example, the following script saved as soup

#!/usr/bin/env -S uv run --quiet --script

# /// script
# requires-python = ">=3.10"
# dependencies = [
#    "bs4",
# ]
# ///

from bs4 import BeautifulSoup

soup = BeautifulSoup('<ul><li>First</li><li>Second</li></ul>')

can be ran with ./soup and uv will take care of installing BeautifulSoup into a virtual environment that it will run this script in and I can import it into a script. I really like that.

I can also include external dependencies to my REPL sessions with

uv run --with bs4 python
>>> from bs4 import BeautifulSoup
>>> soup = BeautifulSoup('<ul><li>First</li><li>Second</li></ul>')

or I can run a script with a specific Python version with

uv run --python 3.12 script.py

This can be handy if you need to run with a specific version that you don’t default to. Sometimes I run stuff with older versions for example to make sure they work with a specific version or I run stuff with a newer version to test what’s coming in the future.

I’m not particularly excited about the future of uv now that OpenAI acquired it. But for now, it still seems to be a useful tool.


If something above resonated with you, let's start a discussion about it! Email me at juhis@hamatti.org and share your thoughts. This year, I want to have more deeper discussions with people from around the world and I'd love if you'd be part of that.