Skip to main content

Deep merge dictionaries safely with conflict resolution

Project description

philiprehberger-dict-merge

Tests PyPI version License

Deep merge dictionaries safely with conflict resolution.

Installation

pip install philiprehberger-dict-merge

Usage

from philiprehberger_dict_merge import merge, Strategy

base = {"db": {"host": "localhost", "port": 5432}, "debug": False}
override = {"db": {"port": 3306, "name": "mydb"}, "debug": True}

merge(base, override)
# {"db": {"host": "localhost", "port": 3306, "name": "mydb"}, "debug": True}

# Multiple dicts
merge(defaults, config_file, env_overrides)

# Keep first value on conflict
merge(a, b, strategy=Strategy.KEEP_FIRST)

# Append lists instead of replacing
merge(a, b, list_strategy="append")

API

  • merge(*dicts, strategy=Strategy.REPLACE, list_strategy="replace") — Deep merge
  • Strategy.REPLACE — Later values win (default)
  • Strategy.KEEP_FIRST — Earlier values win
  • Strategy.ERROR — Raise on conflict
  • List strategies: "replace", "append", "unique", "concat"

Development

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

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_dict_merge-0.1.5.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

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

philiprehberger_dict_merge-0.1.5-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file philiprehberger_dict_merge-0.1.5.tar.gz.

File metadata

File hashes

Hashes for philiprehberger_dict_merge-0.1.5.tar.gz
Algorithm Hash digest
SHA256 b4011ef4b2d79d49108cf48fa82b6315d8ba993740f2ca875028e0d2c45e2d9a
MD5 97742016099a390570e582d8cfad705d
BLAKE2b-256 75c168fd8c314f250c7b31f535995ceb92a1307fa899a71633585f3f261599a3

See more details on using hashes here.

File details

Details for the file philiprehberger_dict_merge-0.1.5-py3-none-any.whl.

File metadata

File hashes

Hashes for philiprehberger_dict_merge-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 74f63feae6da92ec983ca5820dcd5a3a4f52d65d55681b31f1ec9c6f48ff4ce3
MD5 9bb7b2b1312064a6a9c1e29c0bd0850b
BLAKE2b-256 d35e9147c50b62dc9a454b6326ce818e0b0f81bd37afcc1c50b9a76c72485d81

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