SQLRules documentation

v1.0.1 Pydantic → SQLAlchemy Python 3.10+

Constraint metadata → WHERE expressions

Compile constraints into WHERE rules

SQLRules turns a safe subset of Pydantic field constraints into deterministic SQLAlchemy expressions—no database connection, plugins for dialect operators. It compiles Field metadata, not model instance values.

Start here → Getting started

Pick the path that matches how you work:

Application developers

Compile constraints from models. Install sqlrules, map a Pydantic model to a table, and pass where(rules) into SQLAlchemy.

Getting started
Plugin authors

Extend the compiler. Register dialect translators for regex, JSON, arrays, and custom operators with a versioned plugin API.

SQLRules Plugin System
Evaluating SQLRules

Fit and non-goals. What SQLRules is, what it refuses to do, and how the API tiers stay stable.

Design philosophy
API reference

Contracts and autodoc. Narrative API tiers plus generated members from the installed package.

Reference

Not a query builder

SQLRules does not connect to a database, generate SQL strings, or turn validated request payloads into WHERE predicates. It only compiles supported constraint metadata into expressions. See design philosophy.

Install: pip install "sqlrules>=1,<2" — optional dialects via pip install "sqlrules-postgresql>=1,<2" (or sqlite / mysql / mssql). pattern needs a dialect plugin.

Documentation map

Questions?

See the FAQ or troubleshooting.