Yeah, but you need `uv`. If we are reaching out for tools that might not be around, then you can also depend on nix-shell,
#! /usr/bin/env nix-shell
#! nix-shell -i python3 --packages python3The issue I have with `nix-shell` is that the evaluation time is long, so if you need to run the script repeatedly it may take a long time. `nix shell` at least fix this issue by caching evaluations, but I think uv is still faster.
As shared in a sibling comment, you can get away with just curl+shell: https://paulw.tokyo/standalone-python-script-with-uv/
This comes with the added benefit that your environment is reverted as soon as you exit the Nix shell.
Yeah, but you need Nix. If we are reaching out for tools that might not be around, then you can also depend on `curl | sudo bash` to install Nix when not present.
(this is a joke btw)