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

Uploaded Source

Built Distribution

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

deepmerge-1.1.0-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: deepmerge-1.1.0.tar.gz
  • Upload date:
  • Size: 17.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.15

File hashes

Hashes for deepmerge-1.1.0.tar.gz
Algorithm Hash digest
SHA256 4c27a0db5de285e1a7ceac7dbc1531deaa556b627dea4900c8244581ecdfea2d
MD5 7689f466b46247372aa6c29a7edbf3ba
BLAKE2b-256 82d775916d41be4c45a8d9b93d1bb089ac46de0212630641972982023d785d1f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: deepmerge-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.15

File hashes

Hashes for deepmerge-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 59e6ef80b77dc52af3882a1ea78da22bcfc91ae9cdabc0c80729049fe295ff8b
MD5 c0183febcf2634ecc5e4f605a19e2054
BLAKE2b-256 597272489ad8d3fe1cf5e5be93bf27ca4b5c792d552a5f667367b32a671a2076

See more details on using hashes here.

Supported by

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