SQLCompyre is a simple Python package that allows you to find and explore the differences between SQL tables, schemas, and entire databases. It provides both a Python interface and a CLI, allowing it to be used for both ad-hoc comparisons as well as in-depth analyses.
SQLCompyre is designed to be dialect-agnostic and should, thus, work with most database systems out-of-the-box.
Given a connection to a database, this snippet will print a report of the differences between two tables:
import sqlalchemy as sa
import sqlcompyre as sc
engine = sa.create_engine("<your_connection_string>")
comparison = sc.compare_tables(engine, "<left table name>", "<right table name>")
report = comparison.summary_report()
print(report)
To find more examples and get started, please visit the documentation.
SQLCompyre can be installed via pip
or conda
:
pip install sqlcompyre
# or
micromamba install sqlcompyre
# or
conda install sqlcompyre
Details on its usage can be found in the documentation.
This project is managed by pixi. You can install the package in development mode using:
git clone https://github.com/quantco/sqlcompyre
cd sqlcompyre
pixi run pre-commit-install
pixi run postinstall
-
Make sure you have
msodbcsql18
installed, or install it here -
Make sure you have
Docker
installed, or install it here -
Create a local test database with the following command:
docker compose up
- Set environment variable
export DB_CONNECTION_STRING="mssql+pyodbc://sa:Passw0rd@localhost:1435/master?driver=ODBC+Driver+18+for+SQL+Server&Encrypt=no"
- Navigate to the main directory of this repository and run pytest.
pixi run test