--- id: fastapi-filter version: "3.0.0" license: MIT license_treatment: permissive maintenance: active --- # fastapi-filter — FastAPI filter License: permissive · Maintenance: active · Downloads: 340.3K/mo ## 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 above — 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 pip install fastapi-filter uv add fastapi-filter 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_current - Install friction: low - Maintenance: active - Downloads: 340.3K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags fastapi query filtering, fastapi sorting and pagination, fastapi database filters, orm query builder, mongoengine filtering, fastapi, query-filtering, orm-agnostic [View on SkillFed](https://skillfed.io/packages/fastapi-filter) · [View on PyPI](https://pypi.org/project/fastapi-filter/)