Skip to main content

fastapi-sqlalchemy-querykit

Deny-by-default declarative filtering, sorting, and searching for FastAPI + SQLAlchemy 2.0 (async-safe). A field is filterable, sortable, or searchable only if the model explicitly declares it — the opposite of the open-by-default library this is derived from.

pip install fastapi-sqlalchemy-querykit

Distribution: fastapi-sqlalchemy-querykit · import package: querybuilder. Full docs in docs/.

Why

  • Deny by default. Undeclared fields return a generic 400, never a silent query.
  • Declare policy on the model. A Queryable mixin lists the allowed fields once; endpoints may narrow but never widen.
  • Correct relationships. Filters and search across relationships compile to correlated EXISTS (.has() / .any()) — no row fan-out, no DISTINCT, to-many supported; two paths to the same model never collide. Sorting uses path-keyed joins.
  • Type-aware & enum-safe. Operators are validated against the column type; enums match by value (Postgres-safe).
  • Caller-owned base scope. The builder is purely additive — it never adds or inspects your own WHERE (tenant, soft-delete, visibility).

Quick example

from querybuilder import Queryable, QueryParams, build_query

class User(Base, Queryable):
    __filterable__ = frozenset({"status", "username", "age", "organization.name"})
    __sortable__   = frozenset({"created_at", "username"})
    __searchable__ = frozenset({"username", "organization.name"})

# inside your data/query layer
async def list_users(db, params: QueryParams):
    stmt = build_query(User, params)                 # filters + search + sort
    stmt = stmt.where(User.is_deleted.is_(False))     # caller-owned base scope
    return (await db.execute(stmt)).scalars().all()
GET /users?filters={"status":{"$eq":"active"},"organization.name":{"$contains":"acme"}}&sort=created_at:desc&search=jdoe

The filter travels as one JSON object, {field: {operator: value}}, with $and / $or for grouping and a dot for relationship traversal (organization.name).

Operators

$eq $ne $gt $gte $lt $lte $in $nin · $contains $ncontains $startswith $endswith · $isnull $isnotnull · logical $and $or.

String comparisons are case-insensitive by default (case_sensitive=true to opt out). Enum filters resolve the operand to the matching member, so you filter by the enum value regardless of how SQLAlchemy stores it.

Endpoint-level narrowing

The model declares the maximum; an endpoint may expose a subset (never a superset):

stmt = build_query(User, params, allowed_filters={"status", "username"})

Documentation

Build the docs site locally: pip install -e ".[docs]" && mkdocs serve.

Development

python -m venv .venv && source .venv/bin/activate
pip install -e ".[dev]"
pytest

License

MIT. Derivative work of fastapi-querybuilder by bhadri01 — see LICENSE and NOTICE.

Metadata

Release files for fastapi-sqlalchemy-querykit 0.3.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 fastapi-sqlalchemy-querykit 0.3.0
File Size Uploaded Provenance Actions
fastapi_sqlalchemy_querykit-0.3.0.tar.gz 45.3 kB With provenance Details for fastapi_sqlalchemy_querykit-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for fastapi-sqlalchemy-querykit 0.3.0
File Interpreter ABI Platform Actions
fastapi_sqlalchemy_querykit-0.3.0-py3-none-any.whl Python 3 none any Details for fastapi_sqlalchemy_querykit-0.3.0-py3-none-any.whl

Total release size: 74.5 kB

Release files / fastapi_sqlalchemy_querykit-0.3.0.tar.gz

Download URL fastapi_sqlalchemy_querykit-0.3.0.tar.gz
Size 45.3 kB
Tags Source
SHA-256 checksum
How to use checksums
4016aa77efe8220cf1620b251f14ce21e85a4b0da994aa96a1afbe838e05d088
BLAKE2b-256 checksum
How to use checksums
6601873f9965f7fffac7ce8c854a0f83efb141da9d3659797314047cf3944cb5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jun 16, 2026.

Transparency log

Release files / fastapi_sqlalchemy_querykit-0.3.0-py3-none-any.whl

Download URL fastapi_sqlalchemy_querykit-0.3.0-py3-none-any.whl
Size 29.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1ac5701ae885b81989e0b1c09ec121613cc7af645fc8ebc29bcd815eafd68a01
BLAKE2b-256 checksum
How to use checksums
21732b471073f713707236e35e20db951f18e835dc95229fe11d32ed602fd1ce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jun 16, 2026.

Transparency log

Security for fastapi-sqlalchemy-querykit 0.3.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 fastapi_sqlalchemy_querykit-0.3.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 Jun 16, 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