Config · Python · MIT

EnvDoctor — Diagnose Environment-Variable Drift

A local-first Python CLI (with a modern dark-themed GUI) that compares .env files with variables referenced by your code — catching missing, duplicated, undocumented, unused, placeholder and secret values before they break production.

View on GitHub Download ZIP

Overview

EnvDoctor is a local-first Python CLI — with an optional PyQt6 desktop GUI — that compares environment files with the variables your source code actually references. It detects missing, duplicated, undocumented, unused, placeholder and potentially sensitive values, applying strict syntax checks (ENV001–ENV011), typed schema validation (ENV501–ENV503) and multi-environment profile comparison.

It exists because environment configuration drifts silently: a key gets renamed in code but not in .env.example, a placeholder like changeme ships to production, or a real credential lands in a committed file. EnvDoctor catches these at commit time and in CI, and — critically — never prints secret contents. All values are redacted from console output and generated reports.

It is built for developers and teams who run more than one environment (development, staging, production): full-stack and backend engineers, platform teams maintaining shared .env.example contracts, and anyone who wants a CI gate that fails on configuration drift before a deploy does.

Use cases

  • Pre-deploy drift check — run envdoctor check . in CI to fail the pipeline when code references a variable that is missing from the env file.
  • Onboard new developers — envdoctor generate --env .env.example -o settings.py emits a starter pydantic-settings model from the example contract.
  • Multi-environment parity — compare .env.development, .env.staging and .env.production with profile validation (ENV503).
  • Secret hygiene — ENV401 flags likely secrets by key name, value length and entropy so you can investigate before they leak.
  • Schema enforcement — declare PORT as port, NODE_ENV as an enum, DATABASE_URL as a required url in envdoctor.toml.
  • Safe auto-fix — envdoctor fix .env --dry-run previews formatting repairs (trailing whitespace, delimiter style, missing newline) before applying them.
  • Watch mode during refactoring — envdoctor watch . --interval 2 re-scans automatically as you rename keys.
  • Code scanning integration — export SARIF 2.1.0 and upload to GitHub code scanning.

How to work with it

A typical day: you pull a branch, run envdoctor check . and see ENV101 — a key referenced in code is missing from .env. You add it, re-run, and get a clean report. Before pushing, envdoctor diff .env .env.example shows the drift between your local file and the shared contract. In CI, fail_on = "warning" in envdoctor.toml turns any warning into a build failure. When a teammate asks "what env vars does this service need?", the answer is the example file and envdoctor validate --env .env --example .env.example.

envdoctor check .
envdoctor diff .env .env.example
envdoctor fix .env --dry-run

Features

  • Strict dotenv syntax checks — ENV001–ENV011 cover invalid syntax, duplicate keys, keys without values, spaces around =, lowercase keys, trailing whitespace, missing newline, colon delimiters, trailing comments in values, mismatched quotes and extra blank lines.
  • Cross-language reference scanning — finds env-var references across Python, JavaScript, TypeScript, shell, YAML, JSON, Go, Rust, Java, Ruby and PHP.
  • Drift detection — reports missing variables (ENV101), example-contract gaps (ENV102), unused keys (ENV201) and example keys absent locally (ENV202).
  • Placeholder and secret detection — ENV301 flags empty or placeholder-like values; ENV401 conservatively flags likely secrets.
  • Typed schema validation — ENV501–ENV503: int, port, bool, url, enum, required, ranges and allowed choices, with dev_default and required_in_prod support.
  • Multi-environment profiles — one profiles = ["development", "staging", "production"] line validates base and profile files together.
  • Auto-fix with dry-run — fix repairs formatting issues safely; --dry-run previews changes first.
  • Watch mode — watch re-scans on file changes with a configurable interval.
  • Redaction by default — values never appear in findings, console output or exported reports.
  • Multiple formats — text, JSON, HTML and SARIF 2.1.0 output; CI-friendly exit codes.
  • Starter settings model — generate emits a pydantic-settings class from your example file.
  • Modern GUI — dark-themed desktop app (envdoctor-gui) with scan, diff, fix, export and watch.

Installation

Requires Python. From a virtual environment (recommended):

python -m venv .venv
# Windows: .venv\Scripts\python -m pip install -e .
# macOS/Linux:
.venv/bin/python -m pip install -e .

Or with plain pip:

python -m pip install -e .

For the GUI, also install PyQt6:

pip install PyQt6

Windows and Linux/macOS users can also double-click start.bat / run ./start.sh — both scripts install dependencies and launch the GUI. Test against the included intentionally unhealthy example:

envdoctor check examples --env .env --example .env.example --fail-on never

For development: python -m pip install -e ".[dev]", then ruff check . and pytest -q.

Quickstart (30 seconds)

$ envdoctor check .
ENV101  ERROR    referenced key DATABASE_URL missing from .env
ENV301  WARNING  placeholder-like value for REDIS_URL
ENV401  ERROR    potential secret value for AWS_SECRET_ACCESS_KEY (value redacted)
$ envdoctor fix .env --dry-run
would remove trailing whitespace on line 12
would add missing trailing newline
$ envdoctor check . --format sarif -o envdoctor.sarif

Three commands: see the drift, preview the repairs, export a redacted SARIF report for code scanning.

Workflow & architecture

EnvDoctor runs a four-stage pipeline: parse the env and example files with strict syntax checks → scan source trees with per-language reference patterns → cross-check references against definitions and schema rules → redact values and emit reports. Behavior is configured in envdoctor.toml: per-key rule overrides, ignored paths and keys, fail_on thresholds for CI, typed [[schema]] entries and environment profiles. Exit codes are CI-friendly and reports never contain secret contents.

parse env files → scan source references → match & validate → redact & report

Troubleshooting

  • ENV201 flags a variable I know is used — static pattern matching can't see every framework-specific mechanism; add the key to [ignore] keys or set ENV201 = "ignore" in envdoctor.toml.
  • Cloud/Docker/manifest variables show as unused — expected; variables consumed only by external systems have no in-repo reference. Ignore those keys explicitly.
  • ENV401 false positive — secret detection is a prompt to investigate, not proof a credential is valid; allowlist the key or lower the severity for that finding.
  • Multiline values mis-parsed — multiline dotenv values and shell interpolation are parsed conservatively; restructure or quote the value.
  • GUI fails to launch — install PyQt6 (pip install PyQt6) or use the CLI; on headless Linux use envdoctor check . instead of envdoctor-gui.
  • CI fails on a warning — check [ci] fail_on in envdoctor.toml; set it to "error" or "never" if warnings should not block the build.

Release & license

Current release line is v0.2 (typed schema validation, multi-environment profiles, auto-fix, watch mode, GUI, SARIF export). Roadmap includes framework adapters (Django, FastAPI, Next.js, Vite, Docker Compose, Kubernetes), interactive repair, monorepo workspaces and pre-commit hook integration. Licensed under MIT. Full details live in USER_GUIDE.md, CHANGELOG.md and RELEASE_LOG.md in the repository.

Need help? Visit the PeaBox Lab help page or the project:

← Back to RepositoriesMore Help →