Skills

Extract Python Environment Variables

Scans a Python recipe to find every place an environment variable is accessed, ...

Install

npx skills add google/adk-recipes --skill extract-python-environment-variables -g -a claude-code -y
Repository
google/adk-recipes10.6k
Category
AI and agents
Updated
4d ago
License
Apache-2.0
Context cost
Mediumabout 3,000 tokens
Runs scripts
Yes, review before use

What it does

Scans a Python recipe to find every place an environment variable is accessed, including `os.environ.setdefault("V", "d")`, whose "d" would otherwise be a hidden default a user editing .env.example has no way to discover, then ensures all variables are declared in `.env.example`, that `load_dotenv()` is bootstrapped in the package `__init__.py`, and that `python-dotenv>=1.0.0` is listed in `pyproject.toml`. When a new entry is added to `.env.example`, the extracted default from source is written as the value (with a `# extracted-by:extract-env-vars` marker and provenance comment); values that look like stubs (`"my-project-id"`, `"changeme"`, `"<...>"`) are downgraded to the TODO placeholder but the source string is preserved in the marker comment. Also detects hardcoded model-name string literals (e.g. `"gemini-3.5-flash"` in `agent.py`) and rewrites them to an `os.getenv(...)` call. The variable name is derived from the assignment target when it names a model (`DEFAULT_EMBEDDING_MODEL` → `EMBEDDING_MODEL`), else `MODEL_NAME` (single model) or `MODEL_NAME_GENERATED_1` / `MODEL_NAME_GENERATED_2`, … (multiple models). Normally no fallback default is written into the Python source; the one exception is when no `load_dotenv()` bootstrap could be installed (no package `__init__.py`), where the original literal is kept as the fallback so the lookup cannot evaluate to `None` at runtime. The model string is written as the value in `.env.example` with a comment prompting a rename.

Extract Python Environment Variables

Use this skill to ensure a Python recipe properly declares and loads all environment variables it uses.


What This Skill Does

Runs scripts/extract_env_vars.py against a recipe directory. The script:

  1. Scans all .py files (excluding tests/ and common cache/venv directories) for environment variable accesses:

    • os.environ["VAR"]
    • os.environ.get("VAR") / os.environ.get("VAR", "default")
    • os.getenv("VAR") / os.getenv("VAR", "default")
    • os.environ.setdefault("VAR", "default")   (v2)

    Only names matching ^[A-Z_][A-Z0-9_]*$ (UPPER_SNAKE_CASE) are captured; a lowercase name like os.getenv("my_api_key") is skipped and a [WARN] line lists any that were dropped. Rename such vars to uppercase in source, or add them to .env.example by hand.

Read the whole SKILL.md on GitHub

More in AI and agents