Compare configuration files across environments
pip install philiprehberger-config-diffCompare configuration files across environments.
pip install philiprehberger-config-diff
from philiprehberger_config_diff import diff_files, diff_dicts
# Compare files (JSON, TOML, INI, .env)
report = diff_files("config.dev.json", "config.prod.json")
for change in report.changes:
print(change) # "+ db.name = 'proddb'" / "~ port: 3000 -> 8080"
print(report.summary())
# "Added: 3, Removed: 1, Modified: 5"
# Filter by key patterns
report = diff_files("dev.env", "prod.env", include=["DB_*"])
# Compare dicts directly
report = diff_dicts(dev_config, prod_config)
from philiprehberger_config_diff import unified_diff
dev = {"db": {"host": "localhost", "port": 5432}}
prod = {"db": {"host": "prod-server", "port": 5432}}
print(unified_diff(dev, prod, left_label="dev", right_label="prod"))
# --- dev
# +++ prod
# @@ -1,2 +1,2 @@
# -db.host = 'localhost'
# +db.host = 'prod-server'
# db.port = 5432
| Function / Class | Description |
|---|---|
diff_files(left, right, include=None, exclude=None) | Compare config files |
diff_dicts(left, right, include=None, exclude=None) | Compare dicts |
unified_diff(left, right, *, context=3, left_label, right_label) | Render diff -u style output |
report.changes | List of Change objects |
report.added / report.removed / report.modified | Filtered changes |
report.summary() | Change count summary |
pip install -e .
python -m pytest tests/ -v
If you find this project useful: