Skip to main content
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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

deepmerge-3.0.tar.gz (22.3 kB view details)

Uploaded Source

Built Distribution

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

deepmerge-3.0-py3-none-any.whl (14.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: deepmerge-3.0.tar.gz
  • Upload date:
  • Size: 22.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for deepmerge-3.0.tar.gz
Algorithm Hash digest
SHA256 14ed69f063de64b7743985c732ccff5d6c34ff4560946e7fbfd99086b853b9ce
MD5 3db8919bcda7d42f733fbf975748bec8
BLAKE2b-256 b76c9f4577a36d5f463a3a3f8322bd65d33e1a1a6b6ba1d692a5ebc3cba19015

See more details on using hashes here.

File details

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

File metadata

  • Download URL: deepmerge-3.0-py3-none-any.whl
  • Upload date:
  • Size: 14.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for deepmerge-3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c8541c3e186dc88d19a5513ad3a0b2d0b22beaa780969fc0c13b995a64265365
MD5 c390b1344a61a5394a00729ec9a93353
BLAKE2b-256 a8d77f19bedd30b90b72865aeec3a29127bed6dee6c9ef0324bb5b4d424bb0e3

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

3.0 This release

2 files

2.1.0

2 files

2.0

2 files

1.1.1

2 files

1.1.0

2 files

1.0.1

2 files

1.0.0

2 files

0.3.0

2 files

0.2.1

2 files

0.1.1

2 files

0.1.0

2 files

0.0.5

2 files

0.0.4

2 files

0.0.3

2 files

0.0.2

2 files

0.0.1

2 files

0.0.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page