Appearance
uv Scripts Guide
All ADW scripts run via uv run. This guide explains how uv manages dependencies for the ADW system and how to use it for your own scripts.
Why uv
uv automatically manages virtual environments. Instead of:
bash
python -m venv venv
source venv/bin/activate
pip install requests rich
python my_script.pyYou write:
bash
uv run my_script.pyOr with inline dependencies declared in the script itself.
Running ADW Scripts
bash
# All ADW scripts use uv run
uv run adws/adw_plan_build.py 42
uv run adws/adw_sdlc.py 42 --skip-e2e
uv run adws/adw_triggers/trigger_cron.pyuv reads the pyproject.toml in the adws/ directory for dependencies.
Inline Script Dependencies (PEP 723)
For standalone scripts outside the adws/ project, declare dependencies inline:
python
# /// script
# requires-python = ">=3.12"
# dependencies = [
# "requests<3",
# "rich",
# ]
# ///
import requests
from rich.pretty import pprint
resp = requests.get("https://api.example.com/data")
pprint(resp.json())Run it:
bash
uv run my_script.pyuv creates an isolated environment with exactly those dependencies, runs the script, and cleans up. No venv, no pip, no activation.
Adding Dependencies to an Existing Script
bash
# uv add --script automatically updates the inline metadata
uv add --script my_script.py 'httpx' 'pydantic>=2'Specifying Python Version
python
# /// script
# requires-python = ">=3.12"
# dependencies = []
# ///uv will download the required Python version if it's not installed.
Running with a Specific Python Version
bash
uv run --python 3.11 my_script.py
uv run --python 3.12 my_script.pyRunning with Extra Dependencies (Without Modifying Script)
bash
uv run --with rich my_script.py
uv run --with 'rich>12,<13' --with requests my_script.pyLocking Dependencies
For reproducible script execution:
bash
uv lock --script my_script.py
# Creates my_script.py.lock
# Subsequent runs use the locked versions
uv run my_script.pyUsing in Projects (pyproject.toml)
The ADW system uses adws/pyproject.toml to declare dependencies:
toml
[project]
name = "adws"
requires-python = ">=3.12"
dependencies = [
"anthropic",
"PyGithub",
"gitpython",
"pydantic",
"python-dotenv",
]Run any script in the project context:
bash
cd adws
uv run adw_plan_build.py 42 # uv installs from pyproject.toml automaticallySkip project installation for scripts that don't need it:
bash
uv run --no-project standalone_script.pyShebang for Executable Scripts
python
#!/usr/bin/env -S uv run --script
# /// script
# requires-python = ">=3.12"
# dependencies = ["httpx"]
# ///
import httpx
print(httpx.get("https://example.com").status_code)bash
chmod +x my_script.py
./my_script.py # No "uv run" neededCommon Patterns in ADW Scripts
ADW scripts use uv run with:
--no-projectwhen running utility scripts outside the adws/ directory- Inline metadata for one-off research or setup scripts
- The
adws/pyproject.toml for all pipeline scripts
To run a quick research script alongside your ADW project:
python
# /// script
# requires-python = ">=3.11"
# dependencies = ["anthropic", "python-dotenv"]
# ///
import os
from dotenv import load_dotenv
from anthropic import Anthropic
load_dotenv()
client = Anthropic()
message = client.messages.create(
model="claude-3-5-sonnet-20241022",
max_tokens=1024,
messages=[{"role": "user", "content": "Summarize the key ADW concepts"}]
)
print(message.content[0].text)bash
uv run my_research.py