Post

TIL you can put uv in your shebang line of a python script, and, along with listing dependencies in a `# /// script` comment block, make your python script superpowered. I wrote a script to upsert test data to an API with httpx. Now I can run it with just `./upsert.py` right from the command line!

My script goes like this: ``` #!/usr/bin/env -S uv run --script # /// script # dependencies = ["httpx", "ipython"] # /// import httpx import IPython # make a few http requests to the API IPython.embed() ```

Now, I just run it, it jams a bunch of test data into the api I'm testing, and drops me into a REPL where I can make additional queries.

0 reposts1 like

Even better, I can run this script on any system that has uv installed. I don't need to worry about python versions, globally installed dependencies, or anything like that!

At first I was very skeptical about the `# /// script` syntax, but after trying this out, I'm on-board. This is so convenient! #python #uv