Add External Dependencies to Python Scripts with uv
Ever wanted to share a Python script that uses external packages without making the recipient set up a virtual environment? With uv, you can embed dependencies directly in the script. The Command uv add --script example.py 'requests<3' 'rich' This adds inline metadata to your script: # /// script # 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]) Running It Anyone with uv installed can now run the script directly: ...