In your script example.py, you would specify your dependencies in a special comment like this:
# Requirements:
# requests
import requests
...
Then you could run the script like this: pipx run file:example.py
This would install the dependencies in a temporary virtual environment, and run the script in that virtual environment. # /// pyproject
# [run]
# requires-python = ">=3.11"
# dependencies = [
# "requests<3",
# "rich",
# ]
# ///
import requests
from rich.pretty import pprint
resp = requests.get("https://peps.python.org/api/peps.json")
data = resp.json()
pprint([(k, v["title"]) for k, v in data.items()][:10])Now someone upload it to pypi for even more hilarity.