Registry / serialization / deep-merge

deep-merge

JSON →
library0.0.4pypypi✓ verified 90d ago

Deep Merge is a lightweight Python utility for recursively merging dictionaries. It's designed for simplicity and handles nested dictionaries and lists with specific strategies. The current version is 0.0.4, with releases occurring periodically but not on a fixed schedule.

pip install deep-merge
INSTALL
IMPORT
SIG · DEEP-MERGE
D
deep-merge
serializationpythonv0.0.4
Install
1.5s avg
Import
—
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v0.0.4 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.8MB
glibc
py 3.10–3.910 runs
installs and imports cleanly · install 1.5s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

merge
✓ from deep_merge import merge
✗ import deep_merge; deep_merge.merge(...)
The primary merge function is exposed directly.

This example demonstrates how to import and use the `merge` function. It highlights the in-place modification of the first dictionary and the list appending behavior.

from deep_merge import merge d1 = {'a': 1, 'b': {'c': 2}, 'list_key': [1, 2]} d2 = {'b': {'d': 3}, 'e': 4, 'list_key': [3, 4]} # NOTE: d1 will be modified in-place by the merge function. # If you need to preserve d1, pass a copy: merge(d1.copy(), d2) merged_dict = merge(d1, d2) print(merged_dict) # Expected output: {'a': 1, 'b': {'c': 2, 'd': 3}, 'list_key': [1, 2, 3, 4], 'e': 4} # Note how 'list_key' lists are appended.
Debug
Known issues
gotchaThe `merge` function modifies the first dictionary (the 'target') in-place. It does not return a new dictionary unless the 'target' dictionary is a copy itself.
fix
If you need to preserve the original target dictionary, pass a copy to `merge`: `merged_dict = merge(original_dict.copy(), source_dict)`.
affects: All versions (0.0.1+)
gotchaWhen merging lists, `deep-merge` simply appends the source list to the target list. It does not perform any deep merging or unique item handling for list elements.
fix
Be aware of this behavior. If you need custom list merging logic (e.g., merging unique items, or overwriting), you will need to implement it separately or use a different library.
affects: All versions (0.0.1+)
gotchaOnly dictionaries and lists have special merging logic. For other data types (e.g., integers, strings, tuples, sets), the value from the source dictionary will simply overwrite the value in the target dictionary.
fix
Understand that non-dict/non-list values are overwritten. Plan accordingly if your nested structures contain types that require custom merging behavior.
affects: All versions (0.0.1+)
Errors
Common errors & fixes
AttributeError: module 'deep_merge' has no attribute 'merge'
Attempting to call `deep_merge.merge()` after `import deep_merge`.
fix
The `merge` function is directly exposed. Use `from deep_merge import merge` and then call `merge()`.
My original dictionary was modified unexpectedly after calling merge!
The `merge` function performs an in-place modification of the first argument (the 'target' dictionary).
fix
Pass a copy of your dictionary if you wish to preserve the original: `merged_dict = merge(my_original_dict.copy(), other_dict)`.
Lists are being appended, not truly merged (e.g., unique items not preserved).
The library's design for lists is to concatenate them (`target_list + source_list`), not to perform deep or intelligent merging of list elements.
fix
This is expected behavior for `deep-merge`. If you require more sophisticated list merging, consider pre-processing your lists or using a library with configurable list merge strategies.
Upgrade
Version history
0.0.4latest on PyPI · released Mar 27, 2018
Audit
Dependencies

No dependency data recorded yet.

Agent activity
13 hits · last 30 days
node
12
OpenAI (training)
1
Resources