Skip to main content

a toolset to deeply merge python dictionaries.

Project description

A tools to handle merging of nested data structures in python.

example

from deepmerge import Merger

my_merger = Merger(
    # pass in a list of tuple, with the
    # strategies you are looking to apply
    # to each type.
    [
        (list, ["append"]),
        (dict, ["merge"])
    ],
    # next, choose the fallback strategies,
    # applied to all other types:
    ["override"],
    # finally, choose the strategies in
    # the case where the types conflict:
    ["override"]
)
base = {"foo": ["bar"]}
next = {"bar": "baz"}
my_merger.merge(base, next)
assert base == {"foo": ["bar"], "bar": "baz"}

Strategies are passed as a list, and the merge runs through each strategy sequentially, and raises an exception if none are able to resolve the merge.

You can also pass in your own merge functions, instead of a string. Your function should take the arguments of (merger, path, base_value, value_to_merge_in).

A default merge does not exist, due to the numerous choices that have to be made for every merger. However, some very generic mergers are supplied:

  • always_merger: will never raise a merge exception, and will merge when possible.

  • merge_or_raise: will merge when possible, raise an exception when there is a conflict.

The best resource for now is the unit tests.

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

deepmerge-0.0.3.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

deepmerge-0.0.3-py2.py3-none-any.whl (9.0 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file deepmerge-0.0.3.tar.gz.

File metadata

  • Download URL: deepmerge-0.0.3.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for deepmerge-0.0.3.tar.gz
Algorithm Hash digest
SHA256 53db04ce38edaa6af0395feb5ff4854c5280b9b8d0c94519181808826da49c73
MD5 d4146da42c32b068492f7afbe19027b0
BLAKE2b-256 47a0a4c957cfa23b7332083823167c21cdf179b51953ea1d2c56d7109c77a55f

See more details on using hashes here.

Provenance

File details

Details for the file deepmerge-0.0.3-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for deepmerge-0.0.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 45385fe1cd4c4d30fbb90e1e9de9ad59287fe74c7914c20c3de4be8f8b7e4f3a
MD5 87828535dbc719860315d64c807dec5a
BLAKE2b-256 c3706bb7ac3528eda6e8002f0a2bddbf038e307b0ab0877d6f1f9ed23cefe076

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page