{"id":9651,"library":"deep-merge","title":"Deep Merge","description":"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.","status":"active","version":"0.0.4","language":"en","source_language":"en","source_url":"https://github.com/halfak/deep_merge","tags":["dictionary","merge","utility","dict-merge","deep-copy"],"install":[{"cmd":"pip install deep-merge","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"note":"The primary merge function is exposed directly.","wrong":"import deep_merge; deep_merge.merge(...)","symbol":"merge","correct":"from deep_merge import merge"}],"quickstart":{"code":"from deep_merge import merge\n\nd1 = {'a': 1, 'b': {'c': 2}, 'list_key': [1, 2]}\nd2 = {'b': {'d': 3}, 'e': 4, 'list_key': [3, 4]}\n\n# NOTE: d1 will be modified in-place by the merge function.\n# If you need to preserve d1, pass a copy: merge(d1.copy(), d2)\n\nmerged_dict = merge(d1, d2)\n\nprint(merged_dict)\n# Expected output: {'a': 1, 'b': {'c': 2, 'd': 3}, 'list_key': [1, 2, 3, 4], 'e': 4}\n# Note how 'list_key' lists are appended.","lang":"python","description":"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."},"warnings":[{"fix":"If you need to preserve the original target dictionary, pass a copy to `merge`: `merged_dict = merge(original_dict.copy(), source_dict)`.","message":"The `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.","severity":"gotcha","affected_versions":"All versions (0.0.1+)"},{"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.","message":"When 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.","severity":"gotcha","affected_versions":"All versions (0.0.1+)"},{"fix":"Understand that non-dict/non-list values are overwritten. Plan accordingly if your nested structures contain types that require custom merging behavior.","message":"Only 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.","severity":"gotcha","affected_versions":"All versions (0.0.1+)"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"The `merge` function is directly exposed. Use `from deep_merge import merge` and then call `merge()`.","cause":"Attempting to call `deep_merge.merge()` after `import deep_merge`.","error":"AttributeError: module 'deep_merge' has no attribute 'merge'"},{"fix":"Pass a copy of your dictionary if you wish to preserve the original: `merged_dict = merge(my_original_dict.copy(), other_dict)`.","cause":"The `merge` function performs an in-place modification of the first argument (the 'target' dictionary).","error":"My original dictionary was modified unexpectedly after calling merge!"},{"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.","cause":"The library's design for lists is to concatenate them (`target_list + source_list`), not to perform deep or intelligent merging of list elements.","error":"Lists are being appended, not truly merged (e.g., unique items not preserved)."}]}