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
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-1.1.0.tar.gz
(17.8 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-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4c27a0db5de285e1a7ceac7dbc1531deaa556b627dea4900c8244581ecdfea2d
|
|
| MD5 |
7689f466b46247372aa6c29a7edbf3ba
|
|
| BLAKE2b-256 |
82d775916d41be4c45a8d9b93d1bb089ac46de0212630641972982023d785d1f
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
59e6ef80b77dc52af3882a1ea78da22bcfc91ae9cdabc0c80729049fe295ff8b
|
|
| MD5 |
c0183febcf2634ecc5e4f605a19e2054
|
|
| BLAKE2b-256 |
597272489ad8d3fe1cf5e5be93bf27ca4b5c792d552a5f667367b32a671a2076
|