Getting Started
SqlProof is a Python property-based testing library for PostgreSQL. It generates random valid datasets that respect your schema constraints, runs your properties against them, and reports the minimal counterexample when one fails.
Prerequisites
Section titled “Prerequisites”- Python 3.11+
- PostgreSQL 13+ or Docker, if using testcontainers
- PostgreSQL client library (
libpq) on the host running Python
Install
Section titled “Install”On Debian/Ubuntu, install build-essential libpq-dev. On macOS, run
brew install libpq and put $(brew --prefix libpq)/bin on PATH.
On Windows, install PostgreSQL’s client tools and put the directory
containing libpq.dll on PATH. PyGreSQL uses these tools even when the
database runs in Docker.
Quick Start
Section titled “Quick Start”Given a schema file:
Write a pytest property:
Run it:
Connection Modes
Section titled “Connection Modes”SqlProof supports two primary connection modes:
| Mode | Options | Docker needed? | When to use |
|---|---|---|---|
| Testcontainers | schema_file only |
Yes | Local development with no external DB |
| Connection string | connection_string + schema |
No | CI Postgres, staging, Supabase, Render |
What Happens Under the Hood
Section titled “What Happens Under the Hood”- Schema parsing reads your
.sqlfile or introspects a live DB. - Topological sort orders tables by FK dependencies.
- Data generation maps Postgres types to Hypothesis strategies.
- Run isolation inserts generated data, runs your property, then rolls back or drops the run schema.
- Shrinking uses Hypothesis to minimize failing counterexamples.