skillfed

fastapi-filter

FastAPI filter

fastapi-filter v3.0.0 340.3K downloads/30d#7,412 on PyPI328
Permissive license MIT Active released

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-filter

uv

uv add fastapi-filter

poetry

poetry add fastapi-filter

Installing 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

Framework :: FastAPILicense :: OSI Approved :: MIT LicenseNatural Language :: EnglishOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14

Tags

fastapi query filteringfastapi sorting and paginationfastapi database filtersorm query buildermongoengine filtering
fastapiquery-filteringorm-agnostic

More Application Frameworks packages