Skip to content
purkat0301-sysPublic

About

Keep .env, .env.example and your code in sync: missing, empty and undocumented env vars, safe sync, init, lint and export.

Topics

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

"Works on my machine" because someone forgot to add a variable to .env.example? This is for you. envdrift keeps your .env files, your .env.example and the variables your code actually reads in sync.

envdrift

Catch missing, empty and undocumented environment variables before they reach production.

CI License: MIT Python 3.10+ Dependencies: 0

envdrift comparing .env, .env.example and source code

Real output of envdrift --code src inside examples/app.


Why

.env.example is the contract between your code and everyone who runs it. It drifts all the time:

  • a teammate adds REDIS_URL to the code but not to the example, and the next deploy crashes
  • your local .env still has STRIPE_SECRET_KEY=<your-key>
  • old keys pile up in .env long after the code stopped reading them

A plain linter checks syntax. envdrift checks the three-way contract: example file, real env files, and source code.

Features

  • 🔍 Check one or many env files against .env.example: MISSING, EMPTY (blank or <placeholder>), EXTRA
  • 🧠 Code scan: finds env vars read in Python, JavaScript/TypeScript (incl. import.meta.env), Go, Ruby, Rust, PHP, Java and Deno, and reports UNDOCUMENTED and UNUSED keys
  • 🩹 Sync: appends missing keys to .env with the example's default; never edits or deletes your lines (--dry-run to preview)
  • 🏗️ Init: turns a real .env into a .env.example, blanking secrets but keeping safe defaults like DEBUG=true or PORT=8080
  • 🧹 Lint: duplicate keys, invalid names, spaces around =, unquoted spaces, unclosed quotes, trailing whitespace; reads stdin with -
  • 🔧 Lint --fix: rewrites spacing, quoting and trailing whitespace in place; removes duplicate keys only after you pick which copy stays (--dedupe first|last or a prompt); --dry-run to preview
  • 🪝 pre-commit hooks: envdrift-lint and envdrift-lint-fix
  • 📦 Export to JSON, shell export, Docker --env-file, or $GITHUB_ENV (multi-line safe)
  • 🙈 Ignore lists with globs (--ignore 'AWS_*' or a .envdriftignore file)
  • 🔒 Values are never printed by check; 🪶 zero dependencies; --json and exit codes for CI

Quick start

pip install git+https://github.com/purkat0301-sys/envdrift
envdrift --code src        # compare .env, .env.example and the code in src/
envdrift sync              # add whatever .env is missing

How it works

flowchart LR
    X[.env.example] --> C{compare}
    E[.env / .env.production ...] --> C
    S[source code] --> K[scan for os.getenv,<br/>process.env, ENV ...] --> C
    C --> M[MISSING / EMPTY / EXTRA]
    C --> U[UNDOCUMENTED / UNUSED]
    M & U --> R[report + exit code]
Loading
Command What it does
envdrift / envdrift check Compare env files (and optionally code) with the example. Exit 1 on missing, empty or undocumented keys; --strict also fails on extras
envdrift scan [dir] List every env var the code reads, with file and line
envdrift sync Append missing keys to .env
envdrift init [.env] Print a safe .env.example built from a real .env
envdrift lint [files or -] Syntax and style problems
envdrift lint --fix [files] Fix formatting in place (--dry-run to preview, --dedupe first|last for duplicates)
envdrift export [file] --format json|shell|docker|github Convert an env file

Use it with pre-commit

- repo: https://github.com/purkat0301-sys/envdrift
  rev: <commit SHA or release tag>
  hooks:
    - id: envdrift-lint-fix

envdrift-lint only reports; envdrift-lint-fix fixes formatting and fails the commit so you can review the change. Both skip .env.example.

Use it in CI

- run: pip install git+https://github.com/purkat0301-sys/envdrift
- run: envdrift --env .env.ci --code src

Compared with dotenv-linter

Inspired by dotenv-linter/dotenv-linter (MIT, Rust), a fast and mature .env linter, and by requests in its issue tracker: --stdin (#803), filtering comparisons (#541), filling missing keys (#728), an export command (#715) and .envignore (#773). The code here is written from scratch.

envdrift dotenv-linter
Syntax / style lint ✅ basic set ✅ larger set, very fast
Auto-fix lint problems ✅ formatting only; duplicates need a choice ✅
Compare env files ✅ against an example ✅
Scan source code for undocumented vars ✅ 9 languages ❌
Fill missing keys from the example ✅ sync requested in #728
Read from stdin ✅ lint - requested in #803
Export to JSON / shell / Docker / GitHub ✅ requested in #715
Ignore file with globs ✅ .envdriftignore requested in #773
Install pip (Python) binary, brew, cargo, Docker

Status of the dotenv-linter feature requests is as of 2026-11-29. If you need the fastest pure linter, use dotenv-linter; envdrift focuses on drift between files and code.

FAQ

Will it leak my secrets in CI logs? check, lint, scan and sync print key names only. export prints values by design.

My code reads variables dynamically (os.environ[name]). Only string literals are detected. Put such keys in .envdriftignore or document them.

Does sync overwrite anything? No. It only appends missing keys under a comment.

What does lint --fix change? Spaces around =, trailing whitespace, and unquoted values with spaces (they get double quotes). It never renames keys, never touches multi-line values, and never prints values. A duplicate key stays until you choose which copy to keep.

Limitations

  • Code scanning is regex based: it finds literal names, not computed ones.
  • The parser follows common dotenv rules; exotic variable expansion (${A:-b}) is read as plain text.
  • Not on PyPI yet; install from GitHub.

Roadmap

See ROADMAP.md: type hints in .env.example (# type: url), monorepo mode, variable expansion.

Related tools

By the same author: mcp-preflight (check MCP configs) · agent-skill-lint (lint Agent Skills)

Contributing

Issues and pull requests are welcome. pip install -e '.[dev]' && pytest. New languages for the code scan go in CODE_PATTERNS with a test.

License

MIT

About

Keep .env, .env.example and your code in sync: missing, empty and undocumented env vars, safe sync, init, lint and export.

Topics

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages