Registry / data / collate-data-diff

collate-data-diff

JSON →
library0.11.15pypypi✓ verified 23d ago

collate-data-diff (also known as data-diff) is a Python library and command-line tool designed to efficiently compare and find differences between rows across two databases or tables. It focuses on performance and scalability for large datasets, providing a fast and accurate way to detect data discrepancies. The current version is 0.11.10, and it maintains an active release cadence with frequent updates.

pip install collate-data-diff
INSTALL
IMPORT
SIG · COLLATE-DATA-DIFF
C
collate-data-diff
datapythonv0.11.15
Install
Import
Disk
Pass rate
0/ 10
Env Coverage0 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.11.15 · 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
glibc
py 3.10
✕ build_error
1/2 runs
py 3.11
✕ build_error
1/2 runs
py 3.12
✕ build_error
1/2 runs
py 3.13
✕ build_error
1/2 runs
py 3.9
1/2 runs
1/2 runs
Code
Verified usage

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

diff_tables
from data_diff import diff_tables
TableSegment
from data_diff import TableSegment
connect_to_uri
from data_diff import connect_to_uri

This quickstart demonstrates how to use `data-diff` programmatically to compare two tables in in-memory SQLite databases. It requires `collate-data-diff`, `pandas` (for creating dummy dataframes), and `sqlalchemy` (for database connectivity). Install with `pip install collate-data-diff[sqlite] pandas sqlalchemy`.

import pandas as pd import sqlalchemy as sa from data_diff import diff_tables, TableSegment, connect_to_uri # Create two in-memory SQLite databases for demonstration uri_1 = "sqlite:///:memory:" engine_1 = sa.create_engine(uri_1) conn_1 = engine_1.connect() uri_2 = "sqlite:///:memory:" engine_2 = sa.create_engine(uri_2) conn_2 = engine_2.connect() # Create dummy data in pandas DataFrames df1 = pd.DataFrame({ 'id': [1, 2, 3, 4], 'name': ['Alice', 'Bob', 'Charlie', 'David'], 'value': [10, 20, 30, 40] }) df2 = pd.DataFrame({ 'id': [1, 2, 3, 5], # id 4 removed, id 5 added 'name': ['Alice', 'Bob Changed', 'Charlie', 'Eve'], # Bob's name changed 'value': [10, 25, 30, 50] # Bob's value changed }) # Populate tables in the in-memory databases df1.to_sql('table_a', conn_1, index=False, if_exists='replace') df2.to_sql('table_b', conn_2, index=False, if_exists='replace') # Connect to the in-memory databases using data_diff's `connect_to_uri` db1 = connect_to_uri(uri_1) db2 = connect_to_uri(uri_2) # Define TableSegment objects, specifying the key_columns for efficient diffing table1 = TableSegment(db1, 'table_a', key_columns='id') table2 = TableSegment(db2, 'table_b', key_columns='id') # Perform the diff and print results print("Differences found:") diff_results = list(diff_tables(table1, table2)) for d in diff_results: print(d) # Expected Output: # (- , 4, 'David', 40) # Row removed from table_a # (+ , 5, 'Eve', 50) # Row added to table_b # (- , 2, 'Bob', 20) # Original row for ID 2 # (+ , 2, 'Bob Changed', 25) # Modified row for ID 2
data-diff --version
Debug
Known issues
breakingThe behavior of iterating over diff results changed in v0.11.0. Previously, `diff_tables` would yield individual tuples representing row changes. From v0.11.0 onwards, it now yields lists of tuples for individual changes (e.g., `(- , 4, 'David', 40)` is now `('-', 4, 'David', 40)`).
fix
Adjust code that processes the output of `diff_tables` to expect single changes as lists of tuples, rather than direct tuples.
affects: >=0.11.0
gotchaSQL Server support is limited, and users might encounter issues or incomplete functionality compared to other supported databases.
fix
Review the official documentation for current limitations and workarounds for SQL Server if it is a critical part of your data stack.
affects: All versions
gotchaFor efficient diffing, it is crucial to specify `key_columns` when creating `TableSegment` objects. Without explicit key columns, `data-diff` may perform a full-table scan or fall back to less efficient diffing strategies.
fix
Always provide the `key_columns` argument (e.g., `key_columns='id'`) when initializing `TableSegment` for tables with primary or unique keys.
affects: All versions
gotchaDatabase-specific drivers are required via extra installs (e.g., `pip install "collate-data-diff[postgresql]"`). Failure to install the correct extras will lead to connection errors for that database type.
fix
Install the necessary database extras for your specific database(s) using `pip install "collate-data-diff[<db_name>]"`.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'prestodb'
The necessary database driver for PrestoDB (or any other database) has not been installed for the `collate-data-diff` library.
fix
Install the required database driver using pip, e.g., `pip install 'collate-data-diff[presto]'` for PrestoDB. Replace `presto` with the appropriate database driver if you are using a different database like `mysql`, `postgresql`, `snowflake`, etc.
Unable to access database
The `collate-data-diff` tool or library could not establish a connection to one of the specified databases, often due to incorrect connection string details, network issues, or database server being unreachable or refusing the connection.
fix
Verify the database connection string, credentials (username, password), host, and port. Ensure the database server is running and accessible from where `collate-data-diff` is being executed. Check firewall rules if applicable.
Cannot resolve the collation conflict between "collation1" and "collation2" in the equal to operation.
This error occurs when comparing string columns from two different databases or tables that have incompatible collation settings, typically in SQL Server environments.
fix
Explicitly cast or specify the collation for the differing columns in your SQL queries or configuration to ensure they are compared using the same collation. For example, `ON a.ColumnName COLLATE SQL_Latin1_General_CP1_CI_AS = b.ColumnName COLLATE SQL_Latin1_General_CP1_CI_AS`.
TypeError: '<' not supported between instances of 'str' and 'int'
This Python error arises when `collate-data-diff` attempts to compare or operate on columns with incompatible data types, such as comparing a string column with an integer column, particularly when these are used as primary or key columns.
fix
Ensure that the columns being compared across both tables have compatible data types. If types differ (e.g., an ID column is `VARCHAR` in one table and `INT` in another), cast one of the columns to match the other's type in your database view or using a `WHERE` clause, or ensure the library's configuration correctly handles type conversions for the specific columns.
Upgrade
Version history
0.11.15latest on PyPI · released Aug 11, 2026
Audit
Dependencies
pythonrequiredRequires Python 3.10 or newer, but less than Python 4.0.
collate-data-diff[postgresql]optionalOptional dependency for PostgreSQL connectivity.
collate-data-diff[mysql]optionalOptional dependency for MySQL connectivity.
collate-data-diff[snowflake]optionalOptional dependency for Snowflake connectivity.
collate-data-diff[redshift]optionalOptional dependency for Redshift connectivity.
collate-data-diff[mssql]optionalOptional dependency for SQL Server connectivity.
collate-data-diff[sqlite]optionalOptional dependency for SQLite connectivity (implicitly via sqlalchemy).
Agent activity
22 hits · last 30 days
node
17
Amazon
1
OpenAI (training)
1
Resources
collate-data-diff — pip install collate-data-diff · libregistry