sqlalchemy-filters
A library to filter SQLAlchemy queries.
What it is and what it does
sqlalchemy-filters is a query-building library that lets you apply filtering, sorting, and pagination to SQLAlchemy query objects using declarative JSON-like specifications rather than imperative ORM calls. It's designed primarily for REST APIs where clients need to express query constraints as structured data (e.g., from URL parameters or request bodies). The library handles single-model queries, multi-model joins with automatic relationship inference, and hybrid properties, and it can defer field loading to reduce database overhead.
The package depends only on sqlalchemy and six, making it lightweight. It supports Python 3.7, 3.8, 3.9, and 3.10 and has been stable since its first release in 2017, though active maintenance ended in April 2023. The repository remains accessible with a recent commit in January 2025, suggesting the code is not abandoned but receives minimal updates. It carries no known security vulnerabilities.
Use it for:
- Build REST API endpoints that accept filter, sort, and pagination parameters without writing custom query logic for each endpoint.
- Expose database queries to clients safely by translating structured filter specifications into SQLAlchemy operations.
- Restrict database field loads to reduce query overhead when clients request only specific columns via a load specification.
- Filter and sort across related models using automatic joins, allowing clients to query by foreign-key relationships without server-side join configuration.
- Apply hybrid properties and methods as filter and sort targets, enabling computed fields in query constraints.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Adds filtering, sorting, and pagination capabilities to SQLAlchemy query objects via declarative specifications, designed for REST API exposure.
Yes, if you are building a REST API on SQLAlchemy and need to translate client-supplied filter/sort/pagination parameters into queries. The low install friction, permissive license, and absence of known vulnerabilities make it safe to adopt. However, accept that maintenance is dormant: no updates since April 2023, and compatibility with newer SQLAlchemy versions is unverified. If you require active support or cutting-edge features, evaluate alternatives first.
Install
sqlalchemy-filters on PyPI
pip
pip install sqlalchemy-filtersuv
uv add sqlalchemy-filterspoetry
poetry add sqlalchemy-filtersInstalling sqlalchemy-filters
Before you install
Low install friction with only two runtime dependencies (sqlalchemy and six). Package is dormant—last release was in April 2023, though the repository remains active with a recent commit in January 2025. Use only if you accept infrequent maintenance.
License in practice
Licensed under Apache License, Version 2.0 (permissive), imposing no restrictions on use or redistribution in proprietary or open-source projects.
Quickstart
pip install sqlalchemy-filters
from sqlalchemy_filters import apply_filters
filter_spec = [{'field': 'name', 'op': '==', 'value': 'example'}]
filtered_query = apply_filters(query, filter_spec)
result = filtered_query.all()
Requires sqlalchemy and Python 3.7 or later; automatic joins depend on sqlalchemy being able to infer foreign-key relationships.
Verify before relying
- Whether the package works with SQLAlchemy 2.0+ (latest major version compatibility not stated in fact sheet)
- Current test coverage and whether dormant status indicates stability or abandonment risk
Package facts
| License | Apache License, Version 2.0 (permissive) |
| Python support | supports the current Python release (>=3.7) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 2 — sqlalchemy, six |
| Maintenance | dormant — 1,219 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 162,440/month — #10,603 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: sqlalchemy_filters-0.13.0-py3-none-any.whl
Tags
More Python Modules packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
PyYAMLPyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
pydanticPydantic validates Python data structures…
permissive · top 100 on PyPI
annotated-typesProvides reusable metadata objects for use with…
permissive · top 100 on PyPI
typing-inspectionProvides runtime tools to inspect and…
permissive · top 100 on PyPI
fastapi-filterAdds declarative filtering, sorting, and…
permissive · top 15,000 on PyPI
sqlalchemy-easy-softdeleteAdds soft-deletion support to SQLAlchemy models…
permissive · top 15,000 on PyPI
sqlalchemy-mixinsProvides Active Record-style mixins for…
permissive · top 15,000 on PyPI
odata-queryParses OData v4 filter strings and transpiles…
permissive · top 15,000 on PyPI
jsonquerylangExecutes queries against JSON data using a…
permissive · top 15,000 on PyPI
SQLAlchemySQLAlchemy is a Python SQL toolkit and Object…
permissive · top 100 on PyPI
sqlalchemy-searchableAdds fulltext search capabilities to SQLAlchemy…
permissive · top 15,000 on PyPI
mock-alchemyProvides mock helpers for SQLAlchemy sessions…
permissive · top 15,000 on PyPI
fastapi-paginationAdds pagination support to FastAPI applications…
permissive · top 5,000 on PyPI
sqlalchemy-reprAdds automatic, human-readable repr() output to…
unclear · top 15,000 on PyPI