Skip to main content

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\.")],
)

Serializing diffs

DiffReport.to_dict() returns a JSON-serializable representation, and DiffReport.is_empty() is a quick check for "no changes" in scripts or CI gates.

import json
from philiprehberger_config_diff import diff_dicts

report = diff_dicts({"a": 1}, {"a": 2, "b": 3})

if report.is_empty():
    print("No drift detected")
else:
    print(json.dumps(report.to_dict(), indent=2))
    # {
    #   "changes": [
    #     {"path": "a", "type": "modified", "old": 1, "new": 2},
    #     {"path": "b", "type": "added", "old": null, "new": 3}
    #   ]
    # }

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
report.is_empty() True when the report contains no changes
report.to_dict() JSON-serializable {"changes": [...]} representation

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

Metadata

Release files for philiprehberger-config-diff 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for philiprehberger-config-diff 0.4.0
File Size Uploaded Provenance Actions
philiprehberger_config_diff-0.4.0.tar.gz 179.0 kB Without provenance Details for philiprehberger_config_diff-0.4.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for philiprehberger-config-diff 0.4.0
File Interpreter ABI Platform Actions
philiprehberger_config_diff-0.4.0-py3-none-any.whl Python 3 none any Details for philiprehberger_config_diff-0.4.0-py3-none-any.whl

Total release size: 185.9 kB

Release files / philiprehberger_config_diff-0.4.0.tar.gz

Download URL philiprehberger_config_diff-0.4.0.tar.gz
Size 179.0 kB
Tags Source
SHA-256 checksum
How to use checksums
734c85afea25e6379b56464e03566e431a62e341fc5d220cc37ec3a55396ab73
BLAKE2b-256 checksum
How to use checksums
31987b3c967013cc0355dcf79d50481042c902ad146643b02f52dd3f92f30ce8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.13

Release files / philiprehberger_config_diff-0.4.0-py3-none-any.whl

Download URL philiprehberger_config_diff-0.4.0-py3-none-any.whl
Size 6.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
51ac8b869ebdfc2de7fa46b27cb1f4251245f89789652709a544ce3b2f5e29eb
BLAKE2b-256 checksum
How to use checksums
28fcbbf3724c78ea65e0c6134d7e3bdee4738ef66f5f0e21986fcd16a4e73f4b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.13

Security for philiprehberger-config-diff 0.4.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page