{"id":8065,"library":"datadiff","title":"DataDiff (Python Data Structures)","description":"DataDiff is a Python library (version 2.2.0) designed to provide human-readable diffs of common Python data structures, including lists, tuples, sets, and dictionaries. It recursively compares nested structures and offers special handling for multi-line strings, presenting them in a unified diff format. The library also provides drop-in replacements for some `nose` assertions, displaying clear data differences upon assertion failures. The project has a slower but consistent release cadence.","status":"active","version":"2.2.0","language":"en","source_language":"en","source_url":"http://sourceforge.net/projects/datadiff/","tags":["diff","data comparison","python data structures","testing","debugging"],"install":[{"cmd":"pip install datadiff","lang":"bash","label":"Install stable release"}],"dependencies":[],"imports":[{"note":"This `datadiff` library is for Python data structures. The `data-diff` library (with a hyphen) is a separate tool for database table comparisons and uses different import paths and functionalities.","wrong":"from data_diff import diff_tables","symbol":"diff","correct":"from datadiff import diff"}],"quickstart":{"code":"from datadiff import diff\n\na = dict(foo=1, bar=2, baz=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11])\nb = dict(foo=1, bar=4, baz=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 'changed', 11], qux='new')\n\nresult = diff(a, b)\nprint(result)","lang":"python","description":"This example demonstrates how to use `datadiff.diff` to compare two Python dictionaries, showing changes in values, lists, and new keys."},"warnings":[{"fix":"Verify the PyPI package name (`datadiff` vs. `data-diff`) and import paths (`from datadiff import diff` vs. `from data_diff import connect_to_table`).","message":"This `datadiff` library (no hyphen) is specifically for diffing Python data structures (dicts, lists, sets, strings). There is a similarly named but entirely different library, `data-diff` (with a hyphen), which focuses on diffing database tables. Ensure you are installing and importing the correct library for your use case to avoid confusion.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Test thoroughly in your specific Python 3 environment. For deep, custom object diffing, consider implementing `__eq__` and `__repr__` methods on your custom classes, or converting them to standard data structures before diffing.","message":"While `datadiff` states compatibility with Python 2.6 through Python 3, using it in modern Python 3-only projects might encounter subtle compatibility issues or less optimized behavior compared to Python 3-native diffing tools. Its feature set might not leverage newer Python 3 language features.","severity":"gotcha","affected_versions":"All versions, especially when migrating from Python 2 or mixing with modern Python 3 codebases."}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"If you intend to compare Python data structures, use `from datadiff import diff`. If you intend to compare databases, run `pip install data-diff` and then import `from data_diff import connect_to_table, diff_tables`.","cause":"You have installed `datadiff` (for Python data structures) but are trying to import `data_diff` (with an underscore), which belongs to the database diffing tool `data-diff`.","error":"ModuleNotFoundError: No module named 'data_diff'"},{"fix":"For meaningful diffs of custom objects, ensure your classes implement `__eq__` and `__repr__` methods, or convert your custom objects into standard Python dictionaries or lists before passing them to `datadiff.diff()`.","cause":"`datadiff` is optimized for standard Python collections. For custom objects, it may fall back to default object comparison, which often relies on `id()` or `__repr__()` if `__eq__()` is not properly implemented.","error":"Diff output for custom objects is unhelpful (e.g., shows memory addresses or object representations without semantic differences)."}]}