{"id":1452,"library":"dictdiffer","title":"Dictdiffer","description":"Dictdiffer is a Python library designed to compute differences between dictionaries and apply patches based on those differences. It handles nested structures, lists, and sets. The current version is 0.9.0, with releases occurring on an as-needed basis.","status":"active","version":"0.9.0","language":"en","source_language":"en","source_url":"https://github.com/inveniosoftware/dictdiffer","tags":["dict","dictionary","diff","patch","compare","data comparison"],"install":[{"cmd":"pip install dictdiffer","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"symbol":"diff","correct":"from dictdiffer import diff"},{"symbol":"patch","correct":"from dictdiffer import patch"},{"symbol":"revert","correct":"from dictdiffer import revert"},{"symbol":"swap","correct":"from dictdiffer import swap"},{"note":"Use this class for more configurable diffing, e.g., ignoring specific keys.","symbol":"DictDiffer","correct":"from dictdiffer import DictDiffer"}],"quickstart":{"code":"from dictdiffer import diff, patch, revert\n\n# Example dictionaries\nold = {'a': 1, 'b': {'c': 2, 'd': [3, 4]}}\nnew = {'a': 10, 'b': {'c': 2, 'd': [3, 5]}, 'e': 6}\n\n# Compute the diff\ndelta = list(diff(old, new))\nprint(f\"Diff operations: {delta}\")\n\n# Apply the patch to the old dictionary\npatched_dict = patch(delta, old)\nprint(f\"Patched dictionary: {patched_dict}\")\n\n# Revert the patch from the new dictionary\nreverted_dict = revert(delta, new)\nprint(f\"Reverted dictionary: {reverted_dict}\")\n\n# Example with ignoring keys\nold_ignore = {'name': 'Alice', 'version': '1.0', 'data': [1,2]}\nnew_ignore = {'name': 'Alice', 'version': '1.1', 'data': [1,2]}\nignored_delta = list(diff(old_ignore, new_ignore, ignore=['version']))\nprint(f\"Diff ignoring 'version': {ignored_delta}\")","lang":"python","description":"This quickstart demonstrates how to use `diff` to find differences between two dictionaries, `patch` to apply those changes, and `revert` to undo them. It also shows a basic example of ignoring specific keys during diffing."},"warnings":[{"fix":"Upgrade to Python 3.5 or newer, or pin `dictdiffer` to a version <0.9.0 if Python 2.x/3.4 compatibility is required (though not recommended).","message":"Dictdiffer v0.9.0 dropped support for Python versions older than 3.5. Ensure your environment meets this minimum requirement when upgrading.","severity":"breaking","affected_versions":"<0.9.0"},{"fix":"Review existing code that processes diff outputs from versions prior to 0.7.0 to ensure it correctly handles the new immutable behavior. This is generally a safer approach, but could break code relying on mutable references.","message":"In v0.7.0, `dictdiffer` started using `deepcopy` internally for all diff operations to prevent results from referencing parts of the original structures. This change ensures that diff objects are immutable and do not change if the original dictionaries are modified later, but it alters previous behavior where direct references might have existed.","severity":"breaking","affected_versions":"<0.7.0"},{"fix":"Upgrade `dictdiffer` to version 0.7.1 or newer to correctly handle keys with dots.","message":"Prior to v0.7.1, dictionary keys containing dots (`.`) could cause unexpected behavior or errors during diff operations. While fixed in v0.7.1, users on older versions should be aware of this limitation.","severity":"gotcha","affected_versions":"<0.7.1"},{"fix":"Upgrade `dictdiffer` to version 0.8.1 or newer to ensure correct diffing and patching of set elements.","message":"Versions prior to v0.8.1 contained a bug that could lead to invalid diff output when comparing sets. This resulted in incorrect patch instructions for set differences.","severity":"gotcha","affected_versions":"<0.8.1"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}