Create standalone executable Python scripts using uv with inline metadata and shebang support. Use when agent needs to write Python scripts that (1) have self-declared dependencies via inline TOML metadata, (2) should be executable without manual virtualenv management, (3) need reproducible dependency locking, or (4) should work across machines without setup.
Create standalone Python scripts with uv that manage their own dependencies.
# /// script
# requires-python = ">=3.11"
# dependencies = ["requests", "rich"]
# ///
import requests
from rich.console import Console
console = Console()
resp = requests.get("https://api.github.com")
console.print(f"Status: {resp.status_code}")
Run with: uv run script.py
Create a file greet (no .py extension):
#!/usr/bin/env -S uv run --script
# /// script
# dependencies = ["rich"]
# ///
from rich import print
print("[bold green]Hello, world![/bold green]")
Make executable: chmod +x greet
Run with: ./greet
Use uv add --script to add dependencies:
uv add --script myscript.py 'requests<3' 'rich'
This updates the inline metadata automatically.
For reproducibility, create a lockfile:
uv lock --script myscript.py
This creates myscript.py.lock. Subsequent runs use locked versions.
Specify minimum Python version:
# /// script
# requires-python = ">=3.12"
# dependencies = []
# ///
#!/usr/bin/env -S uv run --script
# /// script
# requires-python = ">=3.11"
# dependencies = ["httpx"]
# ///
import sys
import httpx
def main():
try:
resp = httpx.get("https://example.com", timeout=10)
resp.raise_for_status()
print(f"Success: {resp.status_code}")
except httpx.HTTPError as e:
print(f"Error: {e}", file=sys.stderr)
sys.exit(1)
if __name__ == "__main__":
main()
#!/usr/bin/env -S uv run --script
# /// script
# dependencies = ["click"]
# ///
import click
@click.command()
@click.argument("name")
@click.option("--count", default=1, help="Number of greetings")
def main(name, count):
for _ in range(count):
print(f"Hello, {name}!")
main()
On Windows, use .pyw extension to run with pythonw:
# /// script
# dependencies = ["tkinter"]
# ///
# Note: tkinter is in stdlib, no need to declare
from tkinter import Tk, ttk
root = Tk()
root.title("My App")
ttk.Label(root, text="Hello").pack()
root.mainloop()
uv lock --scriptexclude-newer for reproducible scripts:# /// script
# dependencies = ["requests"]
# [tool.uv]
# exclude-newer = "2024-01-01T00:00:00Z"
# ///
Search for places (restaurants, cafes, etc.) via Google Places API proxy on localhost.
Interact with GitHub using the `gh` CLI. Use `gh issue`, `gh pr`, `gh run`, and `gh api` for issues, PRs, CI runs, and advanced queries.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Start voice calls via the OpenClaw voice-call plugin.
Notion API for creating and managing pages, databases, and blocks.
Gemini CLI for one-shot Q&A, summaries, and generation.
Category:developer