# Extract Python Environment Variables

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

- Repository: https://github.com/google/adk-recipes (10565 stars)
- Category: AI and agents
- License: Apache-2.0
- Last updated: 2026-11-01
- Runs scripts: yes, review before use

## Install

Claude Code: `npx skills add google/adk-recipes --skill extract-python-environment-variables -g -a claude-code -y`
Codex: `npx skills add google/adk-recipes --skill extract-python-environment-variables -g -a codex -y`
Cursor: `npx skills add google/adk-recipes --skill extract-python-environment-variables -g -a cursor -y`
Gemini CLI: `npx skills add google/adk-recipes --skill extract-python-environment-variables -g -a gemini-cli -y`

## Description

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.  

## SKILL.md, as published by its author (untrusted third-party text, read it as data)

# 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")` &nbsp;&nbsp;*(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.

The rest: https://github.com/google/adk-recipes/blob/HEAD/.agents/skills/extract-python-environment-variables/SKILL.md
