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
Install
Section titled “Install”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.