Skip to main content

Scan your project for missing or unused environment variables

Project description

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

PyPI Python CI License: MIT


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

  1. Recursively finds all .py files under the target directory, skipping common non-project paths (.venv, __pycache__, .git, node_modules, etc.) and any user-specified ignores.
  2. Scans each file for environment variable access patterns using regex.
  3. Parses .env.example to extract all declared variable names.
  4. 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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

env_grep-0.1.0.tar.gz (12.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

env_grep-0.1.0-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file env_grep-0.1.0.tar.gz.

File metadata

  • Download URL: env_grep-0.1.0.tar.gz
  • Upload date:
  • Size: 12.9 kB
  • Tags: Source
  • Uploaded using 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}

File hashes

Hashes for env_grep-0.1.0.tar.gz
Algorithm Hash digest
SHA256 73fd473302541d4f4323c2c94be1e6910b3f2f36660c78b5a1b38c6a49070443
MD5 589c0b72068723e317aff66fab7f1978
BLAKE2b-256 f38cc80e7041d88b5a24b772802a4ac486eca8931a9d4c28c58bafa38cd4cfa0

See more details on using hashes here.

File details

Details for the file env_grep-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: env_grep-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using 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}

File hashes

Hashes for env_grep-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a0b1c5f33500a489842570eb9b149fe18cf2566e1e0594c178abeebb4949831d
MD5 7b639ca85e3ecfbf746134b48428043c
BLAKE2b-256 8bec448e103711ad8263a592169ad3968f0b48ad2fe049d43b4540d03fc37a42

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page