A toolset for deeply merging Python dictionaries.
Project Links
Meta
Author: Yusuke Tsutsumi
Requires Python: >=3.8
Classifiers
Development Status
- 5 - Production/Stable
Programming Language
- Python :: 3 :: Only
- Python :: 3.8
- Python :: 3.9
- Python :: 3.10
- Python :: 3.11
- Python :: 3.12
Intended Audience
- Developers
License
- OSI Approved :: MIT License
Typing
- Typed
A tool 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
Supported Versions
deepmerge is supported on Python 3.8+.
For older Python versions the last supported version of deepmerge is listed below:
3.7 : 1.1.1
2.0
Aug 30, 2024
2.0b0
Jan 29, 2024
1.1.1
Dec 18, 2023
1.1.0
Oct 25, 2022
1.0.4a0
Dec 19, 2021
1.0.2a2
Feb 15, 2022
1.0.2a0
Dec 19, 2021
1.0.1
Dec 19, 2021
1.0.1a0
Dec 19, 2021
1.0.0
Dec 18, 2021
0.3.0
Apr 25, 2021
0.2.1
Mar 10, 2021
0.1.1
Oct 25, 2020
0.1.0
Sep 04, 2019
0.0.5
Feb 16, 2019
0.0.4
Apr 24, 2017
0.0.3
Dec 01, 2016
0.0.2
Nov 21, 2016
0.0.1
Nov 20, 2016
0.0.0
Feb 15, 2022