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

Function / Class Description
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" List merge modes

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

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for philiprehberger_dict_merge-0.1.6.tar.gz
Algorithm Hash digest
SHA256 afbadb7ddd0cc0bbf61eb2b6423b613b3d90c398ea6aebf7e96aa01367182169
MD5 74dfa973cd4057caabb44404f5300aee
BLAKE2b-256 0c5589e6ea7103da7634dcd634f602c61f992730127cb950cf972ecd11492b4c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for philiprehberger_dict_merge-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 9b58b0c6e134ae58c7719518b972f9b9cdc6088c63cd05b8f932e4b9e894d8c8
MD5 753247777c23122416649c3c8ff3ff24
BLAKE2b-256 983422c9744222ab3f415fcbd360cb8b020c56fc024ed2647a7e1dd1860c693c

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