mergedeep is a Python library providing a deep merge function for dictionaries and other mutable mappings. It offers flexible strategies for handling conflicts, including replacement (default), additive merging for collections like lists, and type-safe replacement. The current version is 1.3.4, and the library is actively maintained with regular releases.
pip install mergedeepVerified import paths — ran on the pinned version, not inferred.
Demonstrates basic deep merging using the default REPLACE strategy and an example of the ADDITIVE strategy for collections. It shows both non-mutating and mutating merge patterns.
To prevent mutation, use `merged_dict = merge({}, original_dict, *sources)`.If you intend to combine (e.g., concatenate or union) collections, explicitly use `strategy=Strategy.ADDITIVE`.
Ensure that types are consistent when using `Strategy.TYPESAFE_REPLACE`, or use `Strategy.REPLACE` for more permissive type handling during replacement.
Install the package using pip: 'pip install mergedeep'.
Ensure the package is installed and use the correct import statement: 'from mergedeep import merge'.
Ensure that the destination and source values are of the same type when using typesafe merge strategies.
from mergedeep import merge, Strategy
dst = {"key": [1, 2]}
src = {"key": {"a", "b"}} # Example: trying to merge a set into a list key
# To resolve, either ensure types are compatible or use a different strategy:
# Option 1: Adjust source type if possible
# src = {"key": [3, 4]}
# merge(dst, src, strategy=Strategy.TYPESAFE_REPLACE)
# Option 2: Use Strategy.REPLACE to overwrite with the new type
merge(dst, src, strategy=Strategy.REPLACE)
print(dst) # Output: {'key': {'a', 'b'}}
# Option 3: Use Strategy.ADDITIVE to combine collections if applicable
# This example still raises TypeError because set and list are incompatible for ADDITIVE
# If both were lists, ADDITIVE would extend the list.
# dst = {"key": [1, 2]}
# src = {"key": [3, 4]}
# merge(dst, src, strategy=Strategy.ADDITIVE)
# print(dst) # Output: {'key': [1, 2, 3, 4]}Ensure that all objects within the dictionaries you are merging are picklable. If an object is inherently not picklable, you must remove it from the dictionaries before calling `mergedeep.merge` or implement custom pre-processing to handle such types.
No dependency data recorded yet.