GeistHaus
log in · sign up

Lazy self-installing Python scripts with uv

treyhunner.com

I frequently find myself writing my own short command-line scripts in Python that help me with day-to-day tasks. It’s so easy to throw together …

3 pages link to this URL
Using uv as shebang line and adding requirements

Using uv as your shebang line – Rob Allen (HN comments) and more detailed article on this: Lazy self-installing Python scripts with uv But especially Defining Python dependencies at the top of the file – Rob Allen and the PEP 723 – Inline script metadata | peps.python.org You can add uv to the shebang line as #!/usr/bin/env -S uv run --script And you can set requirements by adding this under the shebang line: # /// script # requires-python = ">=3.11" # dependencies = [ # "flickrapi", # ] # /// Then you can uv run sync-flickr-dates.py Full package: #!/usr/bin/env -S uv run --script # /// script # requires-python = ">=3.11" # dependencies = [ # "flickrapi", # ] # /// import flickrapi print("\nI am running") ❯ chmod +x test.py ❯ ./test.py Installed 11 packages in 134ms I am running! Neat!

0 inbound links article en dtb ZcZc/ItLinuxUvCli
Using uv as shebang line and adding requirements

Using uv as your shebang line – Rob Allen (HN comments) and more detailed article on this: Lazy self-installing Python scripts with uv But especially Defining Python dependencies at the top of the file – Rob Allen and the PEP 723 – Inline script metadata | peps.python.org You can add uv to the shebang line as #!/usr/bin/env -S uv run --script And you can set requirements by adding this under the shebang line: # /// script # requires-python = ">=3.11" # dependencies = [ # "flickrapi", # ] # /// Then you can uv run sync-flickr-dates.py Full package: #!/usr/bin/env -S uv run --script # /// script # requires-python = ">=3.11" # dependencies = [ # "flickrapi", # ] # /// import flickrapi print("\nI am running") ❯ chmod +x test.py ❯ ./test.py Installed 11 packages in 134ms I am running! Neat!

1 inbound link article en dtb ZcZc/ItLinuxUvCli