Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I love this, the biggest problem I have right now with python scripts is distributing my single file utility scripts (random ops scripts).

I wish there was a way to either shebang something like this or build a wheel that has the full venv inside.



There’s a shebang now. as of PEP 722 you can declare dependencies in a comment at the top of a single file script that a package manager can choose to read and resolve.

uv has support for it: https://docs.astral.sh/uv/guides/scripts/#running-a-script-w... (which only helps if your team is all in on uv, but maybe they are)


PEP 722 was rejected. You are thinking of PEP 723, which was very similar to 722 in goals.

https://discuss.python.org/t/pep-722-723-decision/36763 contains the reasoning for accepting 723 and rejecting 722.


How does that work with the shebang?



  #!uv run
  # /// script
  # requires-python = ">=3.10"
  # dependencies = [
  #     "click>8",
  #     "rich",
  # ]
  # ///
and that's it


Cool. I wasn't sure it would skip the first comment line.


Do other package managers support this yet?


Pipx isn't in any meaningful sense a package manager (although it can manage environments to a limited extent), but the `pipx run` command supports this PEP as of version 1.4.2.


https://peps.python.org/pep-0723/ is at the very least related. It's a way of specifying the metadata in the script, allowing other tools to do the right thing. One of the use cases is:

> A user facing CLI that is capable of executing scripts. If we take Hatch as an example, the interface would be simply hatch run /path/to/script.py [args] and Hatch will manage the environment for that script. Such tools could be used as shebang lines on non-Windows systems e.g. #!/usr/bin/env hatch run

https://micro.webology.dev/2024/08/21/uv-updates-and.html shows an example with uv:

> With this new feature, I can now instruct users to run uv run main.py without explaining what a venv or virtualenv is, plus a long list of requirements that need to be passed to pip install.

That ends:

> PEP 723 also opens the door to turning a one-file Python script into a runnable Docker image that doesn’t even need Python on the machine or opens the door for Beeware and Briefcase to build standalone apps.



You mean like pyinstaller https://pyinstaller.org that takes your python and makes a standalone, self extracting or onedir archive to convert you ops script plus dependencies into something you can just distribute like a binary?


This makes sense when you need to provision Python itself to the end user, not just third-party libraries.




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: