Skip to main content

a toolset to deeply merge python dictionaries.

Project description

https://travis-ci.org/toumorokoshi/deepmerge.svg?branch=masterhttps://travis-ci.org/toumorokoshi/deepmerge.svg?branch=master

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"])
    ],
    # 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

Tests

$ ./uranium test # runs pytest under the hood

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

Uploaded Source

Built Distribution

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

deepmerge-0.1.1-py2.py3-none-any.whl (7.0 kB view details)

Uploaded Python 2Python 3

File details

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

File metadata

  • Download URL: deepmerge-0.1.1.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.0 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.5

File hashes

Hashes for deepmerge-0.1.1.tar.gz
Algorithm Hash digest
SHA256 fa1d44269786bcc12d30a7471b0b39478aa37a43703b134d7f12649792f92c1f
MD5 4e61f63d3af575873212bcda07784518
BLAKE2b-256 16b76cb91924c1c702b9258ef320befa4084af7c2320d9dd09aa096688ee521d

See more details on using hashes here.

File details

Details for the file deepmerge-0.1.1-py2.py3-none-any.whl.

File metadata

  • Download URL: deepmerge-0.1.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 7.0 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.0 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.5

File hashes

Hashes for deepmerge-0.1.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 190e133a6657303db37f9bb302aa853d8d2b15a0e055d41b99a362598e79206a
MD5 061a1cd99534c8d6e4889abb6a90618a
BLAKE2b-256 025b65182f7f7f835e5b86aa16a7a9565ffbb00daad280156ebb03a8b39f5203

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