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.4.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.4-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for philiprehberger_dict_merge-0.1.4.tar.gz
Algorithm Hash digest
SHA256 24cc38428a22e991f2782154e11e0fd024a85a47e3d9059d67cbfb2dfd93655a
MD5 b0b010de3f2e4cc9b1dbe4dbbb9fb145
BLAKE2b-256 a0f83990204afb6cbe6de6ca78e41b7d8e23b64af4f97a6d8a44111511a1fd2f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for philiprehberger_dict_merge-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 124fd700ad89ce1ac79e5a6d6232eb2f715c78a5a0dc1536181cdaea67452480
MD5 07db1da9612a4c224677a650d8194fe3
BLAKE2b-256 6135cf1f52c0ea29be4108ed35944d79fad75dfec8c9d0a5e01c327dc0320f02

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