a toolset to deeply merge python dictionaries.
Project description
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
Tests
$ ./uranium test # runs pytest under the hood
Project details
Release history Release notifications | RSS feed
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.3.0.tar.gz
(17.4 kB
view details)
Built Distribution
File details
Details for the file deepmerge-0.3.0.tar.gz
.
File metadata
- Download URL: deepmerge-0.3.0.tar.gz
- Upload date:
- Size: 17.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f6fd7f1293c535fb599e197e750dbe8674503c5d2a89759b3c72a3c46746d4fd |
|
MD5 | c639024d9cd82e3b7b5a6e617fb9e624 |
|
BLAKE2b-256 | c51530e36a657a86a3a36428421d052893ede3001ab52c01b906290c371e5d3a |
Provenance
File details
Details for the file deepmerge-0.3.0-py2.py3-none-any.whl
.
File metadata
- Download URL: deepmerge-0.3.0-py2.py3-none-any.whl
- Upload date:
- Size: 7.6 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 87166dbe9ba1a3348a45c9d4ada6778f518d41afc0b85aa017ea3041facc3f9c |
|
MD5 | 830d43c994c96ecd9981922f75f15051 |
|
BLAKE2b-256 | 414abc7b0bf4b357f192eb3d3a12aa42f34a5664cc3daf0f7fc4e0ddf133d6e8 |