{"id":10195,"library":"recursive-diff","title":"Recursive Diff","description":"recursive-diff is a Python library that provides a function to recursively compare two Python data structures (dictionaries, lists, and basic types) and return a detailed diff. It is currently at version 2.1.0 and is actively maintained, with releases addressing bug fixes and minor enhancements.","status":"active","version":"2.1.0","language":"en","source_language":"en","source_url":"https://github.com/danielschade/recursive-diff","tags":["diff","comparison","data structures","json diff","object comparison"],"install":[{"cmd":"pip install recursive-diff","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"note":"As of v2.0.0, the `diff_objects` and `diff_strings` functions were removed. Use `recursive_diff` directly for all data structure comparisons.","wrong":"from recursive_diff import diff_objects","symbol":"recursive_diff","correct":"from recursive_diff import recursive_diff"}],"quickstart":{"code":"from recursive_diff import recursive_diff\n\nobj1 = {\n    \"name\": \"Alice\",\n    \"details\": {\"age\": 30, \"city\": \"New York\", \"preferences\": {\"color\": \"blue\"}},\n    \"items\": [\"apple\", \"banana\"],\n    \"tags\": {\"active\": True}\n}\nobj2 = {\n    \"name\": \"Bob\",\n    \"details\": {\"age\": 31, \"city\": \"London\", \"preferences\": {\"color\": \"red\"}},\n    \"items\": [\"apple\", \"cherry\"],\n    \"tags\": {\"active\": True, \"premium\": True}\n}\n\ndiff = recursive_diff(obj1, obj2)\n\n# The diff is a list of operation dictionaries\n# Example output structure:\n# [\n#   {'op': 'change', 'path': ['name'], 'old': 'Alice', 'new': 'Bob'},\n#   {'op': 'change', 'path': ['details', 'age'], 'old': 30, 'new': 31},\n#   {'op': 'change', 'path': ['details', 'city'], 'old': 'New York', 'new': 'London'},\n#   {'op': 'change', 'path': ['details', 'preferences', 'color'], 'old': 'blue', 'new': 'red'},\n#   {'op': 'remove', 'path': ['items', 1], 'old': 'banana'},\n#   {'op': 'add', 'path': ['items', 1], 'new': 'cherry'},\n#   {'op': 'add', 'path': ['tags', 'premium'], 'new': True}\n# ]\nprint(diff)\n","lang":"python","description":"This quickstart demonstrates how to compare two complex Python dictionaries using `recursive_diff` and interpret the resulting list of operation dictionaries."},"warnings":[{"fix":"Migrate your code to use the main `recursive_diff` function directly. It now handles all data types that were previously covered by the specialized functions. Example: `from recursive_diff import recursive_diff; diff = recursive_diff(obj1, obj2)`.","message":"The API for `diff_objects` and `diff_strings` was removed in version 2.0.0. Attempting to use these functions will result in an AttributeError or ImportError.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Familiarize yourself with the structure of the returned diff operations as documented in the library's README. You will need to iterate through this list to understand and process the differences.","message":"The output of `recursive_diff` is a list of dictionaries, each describing a specific change (add, remove, change) with its path. It is not a traditional string-based diff or a simple boolean.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Update your code to use the main `recursive_diff` function directly. Ensure it is imported as `from recursive_diff import recursive_diff` and called like `recursive_diff(obj1, obj2)`.","cause":"You are attempting to call the `diff_objects` function, which was removed in `recursive-diff` version 2.0.0.","error":"AttributeError: module 'recursive_diff' has no attribute 'diff_objects'"},{"fix":"Change your import statement to `from recursive_diff import recursive_diff`. The main function now handles all types of comparisons.","cause":"You are trying to import `diff_objects` (or `diff_strings`), which is no longer exposed directly from the `recursive_diff` package since version 2.0.0.","error":"ImportError: cannot import name 'diff_objects' from 'recursive_diff' (path/to/recursive_diff/__init__.py)"},{"fix":"Convert sets to lists before passing them to `recursive_diff` if order doesn't matter and you want to see individual element additions/removals. Example: `obj1_list = list(obj1_set)`.","cause":"Attempting to create a diff on a data structure containing sets directly when the library's pathing expects list-like or dict-like access. While the library handles basic elements, complex scenarios with sets might require conversion if specific element-wise diffing is desired.","error":"TypeError: 'set' objects are not subscriptable"}]}