Skip to main content

Compare configuration files across environments

Project description

philiprehberger-config-diff

Tests PyPI version Last updated

philiprehberger-config-diff

Compare configuration files across environments.

Installation

pip install philiprehberger-config-diff

Usage

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)

Regex filter patterns

include and exclude accept compiled re.Pattern objects alongside glob strings, which is handy for redacting secret keys by suffix or prefix.

import re
from philiprehberger_config_diff import diff_dicts

report = diff_dicts(
    dev_config,
    prod_config,
    exclude=[re.compile(r".*_token$"), re.compile(r"^secret\.")],
)

Unified diff output

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

API

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

Development

pip install -e .
python -m pytest tests/ -v

Support

If you find this project useful:

Star the repo

🐛 Report issues

💡 Suggest features

❤️ Sponsor development

🌐 All Open Source Projects

💻 GitHub Profile

🔗 LinkedIn Profile

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

philiprehberger_config_diff-0.3.0.tar.gz (178.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

philiprehberger_config_diff-0.3.0-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file philiprehberger_config_diff-0.3.0.tar.gz.

File metadata

File hashes

Hashes for philiprehberger_config_diff-0.3.0.tar.gz
Algorithm Hash digest
SHA256 a0a22fda882dfefcbbd84d699eac1591a08f7edc21dc640677a46bc459cb4746
MD5 bf8024c3a6924cdc45903c6e615e4ac3
BLAKE2b-256 da78bc396fcf0f22f866669697185c40b7e22a3896b0989611ab1acd68dc78e7

See more details on using hashes here.

File details

Details for the file philiprehberger_config_diff-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for philiprehberger_config_diff-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0581e3d31fbae8937e991bcea9c5de231f6d3a353a0e3635510f0c2ff6bac770
MD5 7d11d1d140723fe7383a986f8954b3fb
BLAKE2b-256 47c05c716177e8904c9448ff6eccb4fa060df6922ce6e9c0ff2418aa0ffda9f2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page