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"

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.2.tar.gz (4.2 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.2-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for philiprehberger_dict_merge-0.1.2.tar.gz
Algorithm Hash digest
SHA256 b51d9114a3783d38bc94cc98a8a5deaa74c5f4215fe39b07b0dc33694b9db48b
MD5 daeef1f07b6c27df8f548324a0914ef5
BLAKE2b-256 850360cb99e8a02cc6e9dc0bfe818193fa86c066e62016e8aecd0bf3d394208e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for philiprehberger_dict_merge-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c679e85ef5fc0c7ed1cd29bf8934d97807ac5faf266cbb162273967df7b5b9e8
MD5 5302db3d8310a0195db2ab8183a7adaa
BLAKE2b-256 33e83458c8c88a5cf6f17b0b2557be14590fd407b0d984aa7fb500cbc6fa96fd

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