Skip to main content

relq

relq is a typed SQL query builder for Python 3.13+. It builds SELECT, INSERT, UPDATE, and DELETE statements from declared tables and runs them on SQLite (sqlite3) or PostgreSQL (asyncpg). Those are the only two engines.

Builders are immutable and values are sent as bound parameters. The one exception is the constants in a PostgreSQL conflict arbiter predicate, which are escaped and written into the SQL. The type checker or the compiler rejects an invalid query before it reaches the database.

Get started

uv add "relq[sqlite]"
# or
uv add "relq[postgres]"
import sqlite3

from relq import Column, Table, column, select
from relq_sqlite import SQLiteDatabase


class Users(Table):
    id: Column[int] = column()
    email: Column[str] = column()
    active: Column[bool] = column()


users = Users("users")

connection = sqlite3.connect(":memory:")
connection.execute("create table users (id integer primary key, email text, active integer)")
connection.execute("insert into users values (1, 'ada@example.com', 1), (2, 'bob@example.com', 0)")

query = select(users.id, users.email).from_(users).where(users.active.is_true())
rows = SQLiteDatabase(connection).fetch_all(query)
print(rows)  # [(1, 'ada@example.com')]

rows has the static type list[tuple[int, str]].

Features

  • Typed SELECT, INSERT, UPDATE, and DELETE, with aliases, self-joins, scalar and correlated subqueries, derived tables, CTEs, and set operations that behave the same on both engines.
  • Upserts, aggregates, GROUP BY validation, and window functions.
  • Predicate (bool) and NullablePredicate (bool | None), which keep SQL's UNKNOWN visible in the types.
  • Raw driver tuples, or rows decoded into a dataclass or NamedTuple on request. Decoding never changes the SQL.
  • Materialized CTEs on both engines. Schema-qualified tables and data-modifying CTEs on PostgreSQL.
  • Transactions with savepoints, streaming on PostgreSQL, and a query observer for logging and timing.
  • relq-migrate: forward-only SQL migrations for both engines, with a command that also regenerates the schema module.
  • relq-codegen: generates the table declarations from an existing database.

Queries are built from typed expressions only. relq has no raw SQL fragments. A PostgreSQL-only feature raises an error when compiled for SQLite. The dialects page lists them.

Documentation

The manual covers installation, queries, execution, migrations, and code generation. Start with Get started. The architecture maps the code, and contributing explains how to work on relq.

License

relq is licensed under the Apache License 2.0.

Metadata

Release files for relq 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for relq 0.2.0
File Size Uploaded Provenance Actions
relq-0.2.0.tar.gz 54.9 kB With provenance Details for relq-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for relq 0.2.0
File Interpreter ABI Platform Actions
relq-0.2.0-py3-none-any.whl Python 3 none any Details for relq-0.2.0-py3-none-any.whl

Total release size: 120.6 kB

Release files / relq-0.2.0.tar.gz

Download URL relq-0.2.0.tar.gz
Size 54.9 kB
Tags Source
SHA-256 checksum
How to use checksums
b6a86d1f79b0d961dd9ebd1b359d67ce302e76bcb965f1bbcc27e867dc371367
BLAKE2b-256 checksum
How to use checksums
c9e51e831b404e4e2f98604dbd0f3114eb3cf2099434d1eef154413b4d230857
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 1, 2026.

Transparency log

Release files / relq-0.2.0-py3-none-any.whl

Download URL relq-0.2.0-py3-none-any.whl
Size 65.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
269fdbe385046e08372fd161528ca2bd76abd86600058719f1812fe80a038b2e
BLAKE2b-256 checksum
How to use checksums
d36a86597215c59ac2520b4fe740157d8519b673e14782fcc26e9c49885431fb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 1, 2026.

Transparency log

Security for relq 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for relq-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 1, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page