Registry / serialization / dictdiffer

dictdiffer

JSON →
library0.10.0pypypi✓ verified 26d ago

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.

pip install dictdiffer
INSTALL
IMPORT
SIG · DICTDIFFER
D
dictdiffer
serializationpythonv0.10.0
Install
1.6s avg
Import
10ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.10.0 · 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.103.95 runs
installs and imports cleanly · install 0.0s · import 0.002s · 17.9MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.6s · import 0.004s · 18MB
16MB installed
● package 16MB
Code
Verified usage

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

diff
from dictdiffer import diff
patch
from dictdiffer import patch
revert
from dictdiffer import revert
swap
from dictdiffer import swap
DictDiffer
from dictdiffer import DictDiffer
Use this class for more configurable diffing, e.g., ignoring specific keys.

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.

from dictdiffer import diff, patch, revert # Example dictionaries old = {'a': 1, 'b': {'c': 2, 'd': [3, 4]}} new = {'a': 10, 'b': {'c': 2, 'd': [3, 5]}, 'e': 6} # Compute the diff delta = list(diff(old, new)) print(f"Diff operations: {delta}") # Apply the patch to the old dictionary patched_dict = patch(delta, old) print(f"Patched dictionary: {patched_dict}") # Revert the patch from the new dictionary reverted_dict = revert(delta, new) print(f"Reverted dictionary: {reverted_dict}") # Example with ignoring keys old_ignore = {'name': 'Alice', 'version': '1.0', 'data': [1,2]} new_ignore = {'name': 'Alice', 'version': '1.1', 'data': [1,2]} ignored_delta = list(diff(old_ignore, new_ignore, ignore=['version'])) print(f"Diff ignoring 'version': {ignored_delta}")
Debug
Known issues
breakingDictdiffer v0.9.0 dropped support for Python versions older than 3.5. Ensure your environment meets this minimum requirement when upgrading.
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).
affects: <0.9.0
breakingIn 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.
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.
affects: <0.7.0
gotchaPrior 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.
fix
Upgrade `dictdiffer` to version 0.7.1 or newer to correctly handle keys with dots.
affects: <0.7.1
gotchaVersions 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.
fix
Upgrade `dictdiffer` to version 0.8.1 or newer to ensure correct diffing and patching of set elements.
affects: <0.8.1
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'dictdiffer'
The `dictdiffer` library has not been installed in your Python environment.
fix
pip install dictdiffer
NameError: name 'diff' is not defined
The `diff` function was called without being properly imported from the `dictdiffer` library.
fix
from dictdiffer import diff, patch, swap, revert
TypeError: unhashable type: 'list'
This error occurs when attempting to use Python's built-in set operations to compare dictionaries that contain unhashable types like lists, which `dictdiffer` is designed to handle.
fix
Use `dictdiffer.diff()` directly, as it correctly handles nested lists and other unhashable types. Example: `from dictdiffer import diff; differences = list(diff(dict1, dict2))`
KeyError: index out of bounds on patch
This error typically arises when attempting to `patch` a dictionary, especially with differences involving lists, where the patch instructions refer to an index that no longer exists in the destination list, often due to prior modifications or an inconsistent `diff_result`.
fix
Ensure the `diff_result` is applied to a destination dictionary that is consistent with the 'first' dictionary used to generate the diff, and that no intermediate changes have made list indices invalid. Verify the structure of the `diff_result` if manually generated.
Upgrade
Version history
0.10.0latest on PyPI · released Jul 16, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
12 hits · last 30 days
node
10
OpenAI (training)
1
Resources
dictdiffer — pip install dictdiffer · libregistry