Skip to main content

deepmerge

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

Metadata

Release files for deepmerge 4.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for deepmerge 4.0.1
File Size Uploaded Provenance Actions
deepmerge-4.0.1.tar.gz 25.9 kB Without provenance Details for deepmerge-4.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for deepmerge 4.0.1
File Interpreter ABI Platform Actions
deepmerge-4.0.1-py3-none-any.whl Python 3 none any Details for deepmerge-4.0.1-py3-none-any.whl

Total release size: 44.4 kB

Release files / deepmerge-4.0.1.tar.gz

Download URL deepmerge-4.0.1.tar.gz
Size 25.9 kB
Tags Source
SHA-256 checksum
How to use checksums
202ddf31db72511b14999f3a80e2067c410ee56a32a2030316a9fe529b6d7438
BLAKE2b-256 checksum
How to use checksums
6494acf80bc1cbe186855567e286b62e3e813089aafac3921ffd16e07f70a443
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release files / deepmerge-4.0.1-py3-none-any.whl

Download URL deepmerge-4.0.1-py3-none-any.whl
Size 18.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6da2dd853cc51abb3968436b22bc0e9e72783c563e8116157822f81a50092b00
BLAKE2b-256 checksum
How to use checksums
5ee4692e0366d5987fec62c796facca4817fdf78be30a31fefed7f9439b71179
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Security for deepmerge 4.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page