A command-line tool for Python projects that detects missing or undocumented environment variables by statically scanning source files and cross-referencing them against a .env.example.
Environment variable mismatches are a common source of production failures. env-guard addresses this by scanning your codebase for every os.getenv, os.environ.get, and os.environ[] call, then comparing the results against your .env.example to surface any discrepancies before deployment.
- Static scanning of
.pyfiles for environment variable usage - Cross-reference against
.env.exampleto detect missing and unused variables - Rich, color-coded terminal output with an optional plain-text mode for CI
--ignoreflag to exclude specific files or directories from scanning- Exits with code
1on any issues, making it suitable for use in CI pipelines
This package is not yet published to PyPI. Install from source:
git clone https://github.com/ratherpixelate/env-guard.git
cd env-guard
uv syncRun from the root of your Python project:
env-guard scanenv-guard scan [OPTIONS] [PATH]
Arguments:
PATH Directory to scan [default: .]
Options:
-e, --env-file TEXT Path to .env.example [default: .env.example]
-i, --ignore TEXT Name to ignore during scanning (repeatable)
--no-table Output plain text instead of a formatted table
--help Show this message and exit.
env-guard scanning: .
Ignoring: tests, scripts
Detected Environment Variables
┏━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┳━━━━━━┓
┃ File ┃ Variable ┃ Line ┃
┡━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━╇━━━━━━┩
│ app/db.py │ DATABASE_URL │ 12 │
│ app/payments.py │ STRIPE_KEY │ 8 │
└────────────────────┴───────────────┴──────┘
Missing from .env.example:
✗ STRIPE_KEY
No unused variables.
Scan complete — 1 missing, 0 unused.
Use --ignore or -i to exclude paths from scanning. The value is matched against each segment of every file path, so it applies at any depth.
env-guard scan --ignore tests --ignore migrations
env-guard scan -i tests -i scripts/seed.py- name: Check environment variables
run: env-guard scan --no-tableThe process exits with code 1 if any variables are missing from .env.example, which will fail the workflow step.
env-guard/
├── src/
│ └── env_guard/
│ ├── __init__.py
│ ├── main.py # CLI entrypoint (Typer)
│ ├── scanner.py # Regex-based source file scanner
│ └── checker.py # .env.example cross-reference logic
├── tests/
├── pyproject.toml
└── README.md
- Static scanning for
os.getenvandos.environusages - Cross-reference against
.env.example - Rich table output with
--no-tableflag - CI-friendly exit codes
-
--ignoreflag for excluding files and directories -
python-dotenvload_dotenv()support - pytest test suite
- PyPI release
- GitHub Actions CI
MIT © ratherpixelate