python dependencies in-script with uv


This Share Python scripts like a pro article shows a way to use uv to store dependency information within a script (those single-file custom-purpose ones that are so common) and leverage uv’s speed and caching to provision dependencies at runtime.

In short, uv add --script your-script.py the-dependency. These get added as a comment in the script and then uv run your-script.py will ensure dependencies are installed and available.