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"])
],
# 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.1.0.tar.gz
(5.2 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3d37f739e74e8a284ee0bd683daaef88acc8438ba048545aefb87ade695a2a34
|
|
| MD5 |
e9c8fba06837c1bd9ffd27f35e28ef1a
|
|
| BLAKE2b-256 |
a30f30d6b361fd10127ba80aa1962e0cb3cc58cfdb2e25e38318b30a02f47b2b
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ae23dd76d3c0d22d33a3fd3980c92d3f0773e4affb48d9b341847d0b0a24e8f8
|
|
| MD5 |
6cd924a37f8eb170ffcd03720e91c373
|
|
| BLAKE2b-256 |
c50c0ae77c296ba6a76e4c5b27f0152854145808107fefab2c7a9fd5c662a55c
|