env-grep
A command-line tool for Python projects that scans source files for environment variable usage and cross-references them against .env.example to surface missing or undocumented variables before they cause issues in production.
pip install env-grep
Overview
Environment variable mismatches are a common source of production failures — a variable used in code but missing from the documented .env.example, or a stale entry in .env.example that no longer maps to anything in the codebase.
env-grep catches both classes of problem locally, before deployment, by statically scanning your Python source files and cross-referencing the results against your .env.example.
Installation
pip install env-grep
Or with uv:
uv add env-grep
Usage
Run from the root of your Python project:
env-grep scan
# or using the short alias
evg scan
Options
env-grep 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 exclude from scanning (repeatable)
--no-table Output plain text instead of a formatted table
--help Show this message and exit.
Example Output
env-grep scanning: .
Ignoring: tests
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.
What Gets Detected
env-grep scans for the following patterns across all .py files in your project:
Standard os module usage
os.getenv("DATABASE_URL")
os.environ["DATABASE_URL"]
os.environ.get("DATABASE_URL")
python-dotenv usage via dotenv_values()
config = dotenv_values(".env")
config["DATABASE_URL"]
config.get("DATABASE_URL")
Ignoring Files and Directories
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.
# Ignore a directory
env-grep scan --ignore tests
# Ignore a specific file
env-grep scan --ignore legacy.py
# Ignore multiple paths
env-grep scan -i tests -i scripts -i migrations
CI Integration
env-grep exits with code 1 if any variables are missing from .env.example, making it suitable for use in CI pipelines.
- name: Check environment variables
run: env-grep scan --no-table
Use --no-table for plain-text output that is easier to read in CI logs.
How It Works
- Recursively finds all
.pyfiles under the target directory, skipping common non-project paths (.venv,__pycache__,.git,node_modules, etc.) and any user-specified ignores. - Scans each file for environment variable access patterns using regex.
- Parses
.env.exampleto extract all declared variable names. - Computes the difference between variables used in code and variables declared in
.env.example, reporting both missing and unused entries.
Project Structure
env-grep/
├── src/
│ └── env_grep/
│ ├── __init__.py
│ ├── main.py # CLI entrypoint (Typer)
│ ├── scanner.py # Source file scanner
│ └── checker.py # .env.example cross-reference logic
├── tests/
│ ├── test_scanner.py
│ ├── test_checker.py
│ └── test_main.py
├── .github/
│ └── workflows/
│ └── tests.yml
├── pyproject.toml
└── README.md
Contributing
Issues and pull requests are welcome. If you encounter a pattern that env-grep fails to detect, opening an issue with a minimal example is the most helpful way to report it.
License
MIT © ratherpixelate
Metadata
Release files for env-grep 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| env_grep-0.1.0.tar.gz | 12.9 kB | Without provenance | Details for env_grep-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| env_grep-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for env_grep-0.1.0-py3-none-any.whl |
Total release size: 20.1 kB
Release files / env_grep-0.1.0.tar.gz
| Download URL | env_grep-0.1.0.tar.gz |
|---|---|
| Size | 12.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
73fd473302541d4f4323c2c94be1e6910b3f2f36660c78b5a1b38c6a49070443
|
|
BLAKE2b-256 checksum How to use checksums |
f38cc80e7041d88b5a24b772802a4ac486eca8931a9d4c28c58bafa38cd4cfa0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.17 {"installer":{"name":"uv","version":"0.11.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / env_grep-0.1.0-py3-none-any.whl
| Download URL | env_grep-0.1.0-py3-none-any.whl |
|---|---|
| Size | 7.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a0b1c5f33500a489842570eb9b149fe18cf2566e1e0594c178abeebb4949831d
|
|
BLAKE2b-256 checksum How to use checksums |
8bec448e103711ad8263a592169ad3968f0b48ad2fe049d43b4540d03fc37a42
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.17 {"installer":{"name":"uv","version":"0.11.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for env-grep 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.