PEP-723 is great!

PEP 723 standardises new inline metadata
for scripts. It’s most useful when writing stand-alone scripts as the
dependencies can be managed within the script itself without having to setup a
complete project and create pyproject.toml
file.
Example
Here’s a quick example:
|
|
As you might have noticed, I’m using uv
as part of shebang so, it’s possible
to just run the script on its own and it will magically take care of its own
dependencies (which basically means that uv
will take care of creating a
dedicated virtual environment in which it will install all required
dependencies prior to running the script):
In this example, I’m using --no-cache
in the shebang but, most likely,
you’ll want to drop that.
Syntax
The format is as follows:
|
|
At the moment, there’s only
script
1 type defined with two
fields: requires-python
and dependencies
.
PEP-723 aware tool is needed as well. I’m using uv
which introduced support
in version 0.2.0 (April 2024).