Skip to main content

a toolset to deeply merge python dictionaries.

Project description

https://github.com/toumorokoshi/deepmerge/actions/workflows/python-package.yaml/badge.svg

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

Installation

deepmerge is available on pypi:

pip install deepmerge

Example

Generic Strategy

from deepmerge import always_merger

base = {"foo": ["bar"]}
next = {"foo": ["baz"]}

expected_result = {'foo': ['bar', 'baz']}
result = always_merger.merge(base, next)

assert expected_result == result

Custom Strategy

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"]),
        (set, ["union"])
    ],
    # 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"}

You can also pass in your own merge functions, instead of a string.

For more information, see the docs

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

Uploaded Source

Built Distribution

deepmerge-0.0.0-py2-none-any.whl (7.7 kB view details)

Uploaded Python 2

File details

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

File metadata

  • Download URL: deepmerge-0.0.0.tar.gz
  • Upload date:
  • Size: 15.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for deepmerge-0.0.0.tar.gz
Algorithm Hash digest
SHA256 1088ce7a967c6d44fe338c2068a30b6cc9d356355afb4d3ce290f5256c7f104d
MD5 81913aa4f49368609be5f5b446e0c5fe
BLAKE2b-256 9c5f07d63fef198ec360121a88816f27f9d5bde30895ed18fc1c5b40deab2af7

See more details on using hashes here.

Provenance

File details

Details for the file deepmerge-0.0.0-py2-none-any.whl.

File metadata

  • Download URL: deepmerge-0.0.0-py2-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 2
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for deepmerge-0.0.0-py2-none-any.whl
Algorithm Hash digest
SHA256 aaf7bf3b903226b7a0d9fd3ac1f9f5ba361460a7c1cfa9a4c310f45253ac7175
MD5 25acc037a516286358ecab7aaf658ebb
BLAKE2b-256 537a02754470848e973dfefb61d2f612399e0241a4805978f603040eefeaeb8a

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