Introduction
fastapi-filters is a library that provides filtering/sorting feature for FastAPI
applications.
Installation
pip install fastapi-filters
Quickstart
To create filters you need either define them manually using create_filters function or automatically generate them
based on model using create_filters_from_model function.
from typing import List
from fastapi import FastAPI, Depends
from pydantic import BaseModel, Field
# import all you need from fastapi-filters
from fastapi_filters import create_filters, create_filters_from_model, FilterValues
app = FastAPI() # create FastAPI app
class UserOut(BaseModel): # define your model
name: str = Field(..., example="Steve")
surname: str = Field(..., example="Rogers")
age: int = Field(..., example=102)
@app.get("/users")
async def get_users_manual_filters(
# manually define filters
filters: FilterValues = Depends(create_filters(name=str, surname=str, age=int)),
) -> List[UserOut]:
pass
@app.get("/users")
async def get_users_auto_filters(
# or automatically generate filters from pydantic model
filters: FilterValues = Depends(create_filters_from_model(UserOut)),
) -> List[UserOut]:
pass
Currently, fastapi-filters supports SQLAlchemy integration.
from fastapi_filters.ext.sqlalchemy import apply_filters
@app.get("/users")
async def get_users(
db: AsyncSession = Depends(get_db),
filters: FilterValues = Depends(create_filters_from_model(UserOut)),
) -> List[UserOut]:
query = apply_filters(select(UserOut), filters)
return (await db.scalars(query)).all()
Metadata
Release files for fastapi-filters-wbarnha 0.2.10
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| fastapi_filters_wbarnha-0.2.10.tar.gz | 14.5 kB | Without provenance | Details for fastapi_filters_wbarnha-0.2.10.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| fastapi_filters_wbarnha-0.2.10-py3-none-any.whl | Python 3 | none | any | Details for fastapi_filters_wbarnha-0.2.10-py3-none-any.whl |
Total release size: 33.1 kB
Release files / fastapi_filters_wbarnha-0.2.10.tar.gz
| Download URL | fastapi_filters_wbarnha-0.2.10.tar.gz |
|---|---|
| Size | 14.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
95d700522b8830b192f4e4d8a73955ab49899e2a0c5fe558c0368d19a6053067
|
|
BLAKE2b-256 checksum How to use checksums |
3956254a5a33c6a72ae4c59dce36b1587dd5530dc04b70b2112f3c0e00d10c3c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.0.0 CPython/3.12.2
|
Release files / fastapi_filters_wbarnha-0.2.10-py3-none-any.whl
| Download URL | fastapi_filters_wbarnha-0.2.10-py3-none-any.whl |
|---|---|
| Size | 18.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
dd47567e0fb49051196e126d0bf91dd52f2a148e089c4387a0399fd4d0f43fe4
|
|
BLAKE2b-256 checksum How to use checksums |
8053547175ca8f342883f16778cbd483a13cbf4ce90146c5f8562669781d31af
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.0.0 CPython/3.12.2
|
Security for fastapi-filters-wbarnha 0.2.10
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.