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.1.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.1-py3-none-any.whl (14.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: deepmerge-3.0.1.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.1.tar.gz
Algorithm Hash digest
SHA256 35b39a4cb92cf328d6eca61cbbf65f68a37c2ceb3085f0f853cbb2e52a59fc23
MD5 73090c37d48920cd8eaeb4a1cf439b3e
BLAKE2b-256 386e5cb3548b4d3112fea529375e55e6f3cdc52b8054e3a66f203b1f888ba885

See more details on using hashes here.

File details

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

File metadata

  • Download URL: deepmerge-3.0.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 35c96f6a68fcf90719a5b31d9f8042ecef6c00fb56836660d33455d0f5cfda65
MD5 512463f147dfe54b4839cd6b25d22f6d
BLAKE2b-256 2091600003aaad107e27553fbc9cbfc57e96fa37e0223d2ef9d7d3a0e8d8d070

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

3.0.1 This release

2 files

3.0

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

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