fastapi-filter
FastAPI filter
What it is and what it does
fastapi-filter is a library that bridges FastAPI request query parameters to database queries. It lets you define filter schemas using Pydantic models, then automatically converts incoming query strings into structured filters that SQLAlchemy or MongoEngine can execute. Instead of manually parsing and building database queries in each endpoint, you declare what fields are filterable and how, and the library handles the rest.
The package is designed for developers building REST APIs who want to expose filtering, sorting, and pagination without writing boilerplate query-building code. It integrates directly into FastAPI's dependency injection system via FilterDepends, so filters are applied as route dependencies. Optional backends let you choose between SQLAlchemy (for SQL databases) and MongoEngine (for MongoDB), or use the base filtering logic with other ORMs.
Use it for:
- Build a REST API endpoint that accepts filter parameters and automatically converts them to database queries.
- Add sorting and pagination to list endpoints without manually parsing query strings and constructing ORDER BY or LIMIT clauses.
- Expose a MongoDB collection via FastAPI with declarative filtering using MongoEngine without writing custom query logic.
- Reduce boilerplate in CRUD endpoints by centralizing filter definitions as reusable Pydantic models.
- Support complex filtering with multiple conditions while keeping endpoint code clean and readable.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Adds declarative filtering, sorting, and pagination to FastAPI endpoints by converting query parameters into database queries for SQLAlchemy and MongoEngine backends.
Yes. Low install friction, active maintenance, no known vulnerabilities, permissive license, and a clear fit for FastAPI projects that need filtering. Install it if you're building FastAPI endpoints with database backends and want to avoid manual query-building boilerplate. The optional backends mean you only add dependencies you actually use.
Install
fastapi-filter on PyPI
pip
pip install fastapi-filteruv
uv add fastapi-filterpoetry
poetry add fastapi-filterInstalling fastapi-filter
Before you install
Low friction install with only fastapi and pydantic as core dependencies. Active maintenance with a recent release 72 days ago and steady repository activity. Supports modern Python versions.
License in practice
MIT license is permissive; you can use this package freely in commercial and private projects with minimal restrictions.
Quickstart
pip install fastapi-filter
from fastapi import FastAPI
from fastapi_filter import FilterDepends
app = FastAPI()
# Define a filter model and use FilterDepends in your route
# to automatically parse and apply filters from query parameters
Requires Python >=3.10 and FastAPI >=0.100. Optional backends (SQLAlchemy >=1.4.36 or MongoEngine >=0.24.1) needed for actual filtering.
Verify before relying
- Exact filtering syntax and operator support (e.g., comparison operators, logical operators) not detailed in excerpt.
- Performance characteristics with large result sets or complex filter expressions.
- Whether ordering and pagination work independently or must be combined with filters.
- Specific examples of filter query parameter syntax and usage patterns.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (<4.0,>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 2 — fastapi, pydantic |
| Maintenance | actively maintained — 72 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 340,345/month — #7,412 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: fastapi_filter-3.0.0-py3-none-any.whl
Tags
More Application Frameworks packages
FastAPI is a Python web framework for building…
permissive · top 100 on PyPI
annotated-docProvides a way to document function parameters,…
permissive · top 100 on PyPI
textualTextual is a Python framework for building…
permissive · top 100 on PyPI
typerTyper builds command-line applications from…
permissive · top 1,000 on PyPI
mcpBuild and connect to Model Context Protocol…
permissive · top 1,000 on PyPI
WerkzeugWerkzeug is a WSGI utility library providing…
permissive · top 1,000 on PyPI
djangorestframework-queryfieldsAllows Django REST framework API clients to…
permissive · top 15,000 on PyPI
fastcrudFastCRUD provides async CRUD operations and…
permissive · top 15,000 on PyPI
magic-filterProvides a filter mechanism based on dynamic…
permissive · top 5,000 on PyPI
sqlalchemy-filtersAdds filtering, sorting, and pagination…
permissive · top 15,000 on PyPI
fastapi-paginationAdds pagination support to FastAPI applications…
permissive · top 5,000 on PyPI
odata-queryParses OData v4 filter strings and transpiles…
permissive · top 15,000 on PyPI
fastapi-users-db-sqlalchemyProvides a SQLAlchemy ORM adapter for FastAPI…
permissive · top 5,000 on PyPI
django-elasticsearch-dsl-drfProvides Django REST framework views,…
copyleft · top 15,000 on PyPI
pygeofilterParses OGC filtering standards (CQL, CQL JSON,…
permissive · top 15,000 on PyPI
fastapi-restfulProvides utilities and base classes to reduce…
permissive · top 15,000 on PyPI