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

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for philiprehberger_dict_merge-0.1.3.tar.gz
Algorithm Hash digest
SHA256 bcf289edb884e6b5df44bd0cfa251e4800136b0c0aee75f6f14ec179202c273e
MD5 5ec96002458306bcc8d4860b6aff7103
BLAKE2b-256 ec852ad8997ed95d8521671c2ceba138ae641f0745a94170cdac3287fb52293d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for philiprehberger_dict_merge-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 166db8b3d2468cfb1be6540765c1637f6627c6e99695fc1280ab12ed35daa631
MD5 9a89ba3d1e00a9e2e21814674c6e9780
BLAKE2b-256 7fac824f5fcb288a741ec08b0e1a1c646bb8f6a78cf8845032d7cc699cda2f5d

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