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.0.tar.gz (5.2 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.0-py2.py3-none-any.whl (9.3 kB view details)

Uploaded Python 2Python 3

File details

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

File metadata

  • Download URL: deepmerge-0.1.0.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.0

File hashes

Hashes for deepmerge-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3d37f739e74e8a284ee0bd683daaef88acc8438ba048545aefb87ade695a2a34
MD5 e9c8fba06837c1bd9ffd27f35e28ef1a
BLAKE2b-256 a30f30d6b361fd10127ba80aa1962e0cb3cc58cfdb2e25e38318b30a02f47b2b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: deepmerge-0.1.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 9.3 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.0

File hashes

Hashes for deepmerge-0.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 ae23dd76d3c0d22d33a3fd3980c92d3f0773e4affb48d9b341847d0b0a24e8f8
MD5 6cd924a37f8eb170ffcd03720e91c373
BLAKE2b-256 c50c0ae77c296ba6a76e4c5b27f0152854145808107fefab2c7a9fd5c662a55c

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