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, andDELETE, with aliases, self-joins, scalar and correlated subqueries, derived tables, CTEs, and set operations that behave the same on both engines. - Upserts, aggregates,
GROUP BYvalidation, and window functions. Predicate(bool) andNullablePredicate(bool | None), which keep SQL'sUNKNOWNvisible in the types.- Raw driver tuples, or rows decoded into a dataclass or
NamedTupleon 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.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| relq-0.1.0.tar.gz | 55.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| relq-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 121.4 kB
Release files / relq-0.1.0.tar.gz
| Download URL | relq-0.1.0.tar.gz |
|---|---|
| Size | 55.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fe8e5e7225a7038337bc53f333f66ee5aa0b59999b1e47ad3df6fda949b86a58
|
|
BLAKE2b-256 checksum How to use checksums |
ff35ffcf1664d9f79b3fdaf845f467944e9af808d03f341aad6fddc9f424b672
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Oct 16, 2026.
Transparency logRelease files / relq-0.1.0-py3-none-any.whl
| Download URL | relq-0.1.0-py3-none-any.whl |
|---|---|
| Size | 66.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1a23dbaac88caf95bc8b14bc1e5b9134dad79379c6c95cbc1797a58a8d63a59a
|
|
BLAKE2b-256 checksum How to use checksums |
cd190c07d108208b4cb384015aff34c236ea44f2b9f2babe119cae2c54db504f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Oct 16, 2026.
Transparency log