Deep Merge

0.0.4 · active · verified Fri Apr 17

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.

Common errors

Warnings

Install

Imports

Quickstart

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.

view raw JSON →