DEV Community

umut gngr
umut gngr

Posted on

Stop Breaking Production: How to Audit and Sync .env Files with EnvDoctor

Every developer has been there: your code passes all local tests, you deploy to staging or production, and the application immediately crashes with KeyError: DATABASE_URL or an undefined environment variable.

As projects grow, maintaining .env files across different environments becomes painful:

  • .env.example drifts out of sync with actual code requirements.
  • New variables get added by teammates without documentation.
  • Secret leaks happen when templates aren't audited properly.

To solve this deterministically with zero bloat, I built EnvDoctor — a zero-dependency Python CLI tool designed to audit, synchronize, and validate environment configurations.


What Does EnvDoctor Do?

  1. check: Compares your active .env against .env.example and flags missing or extraneous keys before you deploy.
  2. sync: Safely merges new keys into .env.example without touching secrets or sensitive values.
  3. audit: Scans your codebase with regex patterns to find environment variable calls that aren't declared in your documentation templates.

Example audit run:
$ envdoctor audit --strict
[PASS] .env matches .env.example
[WARN] Found undeclared variable in src/config.py: CACHE_TTL


Why Zero Dependencies?

CLI diagnostic tools should not add 50MB of third-party packages to your environment just to inspect text files. EnvDoctor relies entirely on the Python Standard Library, making it fast, secure, and instant to run in GitHub Actions or Docker entrypoints.


Links & Resources

Feel free to star the repo, test it on your projects, and share your feedback!

Top comments (0)