Compare two .env files and report drift — keys missing on either side and
values that have changed. Pure-Python, zero dependencies, ships with both a
library API and a small CLI.
python -m pip install -e .Or, from a checkout:
pip install -e .envdiff .env.example .envExit codes:
0— no drift1— drift detected2— input error (missing file or parse error)
Pass --no-color to disable ANSI colors in piped output.
from envdiff import diff_envs, format_diff, parse_env_file
left = parse_env_file(".env.example")
right = parse_env_file(".env")
diff = diff_envs(left, right)
if not diff.is_empty:
print(format_diff(diff, color=True))Parse a .env document. Supports comments (#), inline comments,
double-quoted values with \n, \t, \r, \\, \" escapes, single-quoted
literal values, the export prefix, and a UTF-8 BOM. Later definitions of a
key override earlier ones. Raises EnvParseError on malformed lines or invalid
keys, and TypeError on non-string input.
Read a file from disk and parse it. Raises FileNotFoundError if the path
does not exist.
Return an EnvDiff describing the keys missing on either side, the keys whose
values have changed, and the keys that match.
Frozen dataclass with missing_in_right, missing_in_left, changed,
unchanged fields and an is_empty property.
Render a diff as a human-readable, optionally ANSI-colored string.
envdiff intentionally does not perform shell-style variable interpolation
(${OTHER}), does not write or sync files, and does not modify your
environment. It is a read-only drift reporter.
pip install pytest pytest-cov
PYTHONPATH=src pytest --cov=envdiffMIT — see LICENSE.