daff (data diff) is a Python library for comparing tables, producing a summary of their differences, and applying such summaries as patch files. It is optimized for comparing tables that share a common origin, effectively tracking changes between versions of the 'same' table. The library is actively maintained with frequent updates.
Install & Compatibility
Where this runs
tested against v1.4.2 · 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
muslpy 3.10–3.925 runs
installs and imports cleanly · install 0.0s · import 0.062s · 18.5MB
glibcpy 3.10–3.925 runs
installs and imports cleanly · install 1.7s · import 0.058s · 19MB
17MB installed
● package 17MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to compare two Python list-of-lists tables using `daff`, generate a diff, and render it as an HTML string for visualization. It uses `PythonTableView` to adapt standard Python data structures for `daff`'s comparison algorithms.
import daff
data1 = [
['Country', 'Capital'],
['Ireland', 'Dublin'],
['France', 'Paris'],
['Spain', 'Barcelona']
]
data2 = [
['Country', 'Code', 'Capital'],
['Ireland', 'ie', 'Dublin'],
['France', 'fr', 'Paris'],
['Spain', 'es', 'Madrid'],
['Germany', 'de', 'Berlin']
]
# Create table views for the data
table1 = daff.PythonTableView(data1)
table2 = daff.PythonTableView(data2)
# Compare tables to get alignment information
alignment = daff.Coopy.compareTables(table1, table2).align()
# Prepare an empty table to hold the diff results
data_diff = []
table_diff = daff.PythonTableView(data_diff)
flags = daff.CompareFlags()
highlighter = daff.TableDiff(alignment, flags)
highlighter.hilite(table_diff)
# Render the diff to HTML for visualization
diff_render = daff.DiffRender()
diff_render.usePrettyArrows(False) # Optional: control arrow style
diff_render.render(table_diff)
table_diff_html = diff_render.html()
print("Original Table 1:", data1)
print("Modified Table 2:", data2)
print("\nHTML Diff:\n", table_diff_html)
daff --version
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'daff'
The 'daff' library is not installed in the Python environment where the code is being run.
fixInstall the daff library using pip: `pip install daff`
TypeError: 'int' object is not iterable
This typically occurs when passing incorrectly structured data (e.g., a flat list of numbers instead of a list of lists/rows) to `daff.PythonTableView` or similar table construction methods, as the library expects an iterable of iterables for rows and cells.
fixEnsure that the input data to daff's table view functions is a list of lists, where each inner list represents a row and contains cell values. Example: `data = [['header1', 'header2'], [1, 2], [3, 4]]`.
FileNotFoundError: [Errno 2] No such file or directory
When using the `daff` command-line tool or its Python functions that read from files (e.g., `daff.diff_tables_from_csv`), this error occurs if the specified input CSV or other data files do not exist at the given path.
fixVerify that the file paths provided to the `daff` command or functions are correct and that the files exist in the specified locations.
Audit
Dependencies
sqlite3optionalUsed for diffing SQLite databases; updated in v1.3.37. It's an optional dependency handled internally.