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.4.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

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

Uploaded Python 2Python 3

File details

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

File metadata

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

File hashes

Hashes for deepmerge-0.0.4.tar.gz
Algorithm Hash digest
SHA256 c7023d26328a192d6c140fe8ffa7de3ea365434dc28745fa535f030a559d58d5
MD5 82702a431e45ea9ce727edea4033ba97
BLAKE2b-256 57176e03ca57487261d938041a3c34549e3ff59e5b1606947e537183bbdd11d4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for deepmerge-0.0.4-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 9d130b2a6ebdc565f3f07339a8a1bc6e2ff094e5bb0821b40b4755287190d32c
MD5 3d7724608dfa2738f8289c684162426b
BLAKE2b-256 ce5ea55b8b199172f234e6c9984de596fd8e3bda056d50b4207f2fb48ceeb07e

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