Skip to main content

A toolset for deeply merging Python dictionaries.

Project description

https://img.shields.io/pypi/v/deepmerge.svg https://img.shields.io/pypi/status/deepmerge.svg https://img.shields.io/pypi/pyversions/pillar.svg https://img.shields.io/github/license/toumorokoshi/deepmerge.svg https://github.com/toumorokoshi/deepmerge/actions/workflows/python-package.yaml/badge.svg

A tool 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

Supported Versions

deepmerge is supported on Python 3.8+.

For older Python versions the last supported version of deepmerge is listed below:

  • 3.7 : 1.1.1

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

Uploaded Source

Built Distribution

deepmerge-2.0-py3-none-any.whl (13.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: deepmerge-2.0.tar.gz
  • Upload date:
  • Size: 19.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.19

File hashes

Hashes for deepmerge-2.0.tar.gz
Algorithm Hash digest
SHA256 5c3d86081fbebd04dd5de03626a0607b809a98fb6ccba5770b62466fe940ff20
MD5 49f75a0780f287d95ce6eb7e02a44237
BLAKE2b-256 a83ab0ba594708f1ad0bc735884b3ad854d3ca3bdc1d741e56e40bbda6263499

See more details on using hashes here.

File details

Details for the file deepmerge-2.0-py3-none-any.whl.

File metadata

  • Download URL: deepmerge-2.0-py3-none-any.whl
  • Upload date:
  • Size: 13.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.19

File hashes

Hashes for deepmerge-2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6de9ce507115cff0bed95ff0ce9ecc31088ef50cbdf09bc90a09349a318b3d00
MD5 3423a06cf071f65c9970f9ddef4226dd
BLAKE2b-256 2d82e5d2c1c67d19841e9edc74954c827444ae826978499bde3dfc1d007c8c11

See more details on using hashes here.

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