DeepComparer
raw JSON → 0.4.0 verified Fri May 01 auth: no python
A Python library for deep comparison of nested structures like dicts, lists, and iterables. Current version 0.4.0 (beta). Active development with monthly releases.
pip install deepcomparer Common errors
error ModuleNotFoundError: No module named 'deepcomparer' ↓
cause Library not installed or installed in wrong environment.
fix
Run 'pip install deepcomparer' in the correct Python environment.
error AttributeError: module 'deepcomparer' has no attribute 'DeepComparer' ↓
cause Importing incorrectly (e.g., 'import deepcomparer' then using deepcomparer.DeepComparer) but class is not top-level.
fix
Use 'from deepcomparer import DeepComparer' and then just 'DeepComparer'.
error TypeError: compare() got an unexpected keyword argument 'ignore_order' ↓
cause The compare method does not accept ignore_order parameter in current version.
fix
Check documentation for available options; use sort or preprocess lists before comparison.
error KeyError: 'differences' ↓
cause Calling result.differences() before performing a comparison, or using wrong attribute name.
fix
Ensure you call dc.compare() first and store the result; then call result.differences().
Warnings
breaking Library is in beta (pre-1.0). Breaking changes between minor versions expected; upgrade with caution. ↓
fix Pin to exact version in requirements.txt, e.g. deepcomparer==0.4.0
gotcha Order of keys in dicts does not affect comparison; however, order of list items does. May cause unexpected mismatches if lists are compared element-wise. ↓
fix Ensure lists are sorted before comparison if order is irrelevant.
gotcha Nested iterables other than dict/list (e.g., set, tuple) are compared as-is; sets are compared unordered, tuples ordered. ↓
fix Convert custom iterables to list/dict if deep comparison should treat them same.
Imports
- DeepComparer wrong
import DeepComparercorrectfrom deepcomparer import DeepComparer
Quickstart
from deepcomparer import DeepComparer
dc = DeepComparer()
result = dc.compare(
{'a': 1, 'b': {'c': 2}},
{'a': 1, 'b': {'c': 3}}
)
print(result.differences())