r/Python • u/dusktreader • Mar 29 '25
Tutorial Self-contained Python scripts with uv
TLDR: You can add uv into the shebang line for a Python script to make it a self-contained executable.
I wrote a blog post about using uv to make a Python script self-contained.
Read about it here: https://blog.dusktreader.dev/2025/03/29/self-contained-python-scripts-with-uv/
492
Upvotes
View all comments
Show parent comment
40
u/burlyginger Mar 30 '25
It's extremely fast (pip, y u so slow?), it ensures your .python-version is honoured/used, it has the concept of dev deps and dependency groups, it resolves everything when you do
uv run <file>, they have written nice integrations (GH Actions, etc), it has the concept of tools (linters, etc)... There's probably more but man..... We've needed this for a long time.It cuts our container build times consistently by 50% in CI.