I have recently learned about inline script dependencies in uv.
The documentation speaks for itself, but I wanted to show a little bit more to highlight how useful this can be.
I like toml as a configuration language, but I had a problem (before 3.11
but pretend they didn’t add a TOML module to the standard library) where I had little scripts that I wanted to read TOML config files, I didn’t want to pollute my global python installation with packages, but having to create and use a virtual environment for something so trivial was annoying.
uv
to the rescue!
#!/usr/bin/env -S uv run --script
# /// script
# requires-python = ">=3.10"
# dependencies = [
# "toml",
# ]
# ///
import toml
= toml.load("config.toml")
config print(config)
Clever use the of the shebang line combined with an inline metadata block defining a dependency on the toml
package means the convenience of a script without any of the downsides (aside from maybe storage space).