Introduction
fastapi-query-tools is a Python library designed to simplify filtering and sorting in FastAPI applications.
It provides a set of utility functions and data models to help you filter, sort, and order your data to be returned to your clients.
fastapi-query-tools is built on top of the popular fastapi library. It is currently designed to work with SQLAlchemy, but support for other databases may be added in the future.
It is compatible with Python 3.10 and higher.
Features:
- Simplifies filtering and sorting in FastAPI applications.
- Supports a query, a sort by, and an order by system.
- Works with
SQLAlchemy. - Compatible with Python 3.10 and higher.
Installation
pip install fastapi-query-tools
Quickstart
All you need to do is to add the Filter dependency to the endpoint params and call filter_and_sort function
on data you want to filter and/or sort.
from fastapi import FastAPI, Depends
from sqlalchemy import select
# import all you need from fastapi-query-tools
from fastapi_query_tools import Filter, filter_and_sort
app = FastAPI() # create FastAPI app
@app.get('/items')
async def get_items(*, db: Session = Depends(get_db), filter: Filter) -> List[ItemOut]:
stmt = select(Item)
query = filter_and_sort(stmt, filter)
return db.execute(query).scalars().all() # filter and sort data and return
Example Request
curl -X 'GET' \
'http://localhost:8000/api/items?q=item&sort_by=name&order=desc' \
-H 'accept: application/json' \
Where q is a query, sort_by is a field (column) to sort by, and order (asc, desc) is the order of sorting.
Metadata
Release files for fastapi-query-tools 1.0.7
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 | |
|---|---|---|---|---|
| fastapi_query_tools-1.0.7.tar.gz | 5.6 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| fastapi_query_tools-1.0.7-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.3 kB
Release files / fastapi_query_tools-1.0.7.tar.gz
| Download URL | fastapi_query_tools-1.0.7.tar.gz |
|---|---|
| Size | 5.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7973688a3cd534c749306fc9a62e87e5bad100f9e4b81861ff933dcd96dd48f3
|
|
BLAKE2b-256 checksum How to use checksums |
08b1c2484f543920cc778072f48f4158f1f9bc2d488c37e022ed5ff23f36e9f6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.9.19
|
Release files / fastapi_query_tools-1.0.7-py3-none-any.whl
| Download URL | fastapi_query_tools-1.0.7-py3-none-any.whl |
|---|---|
| Size | 5.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
57d42fb54454553cbf017970637db6e1d7c80e0824d849ba9dd814ef75cf7cab
|
|
BLAKE2b-256 checksum How to use checksums |
4624612d0a3dd52ba5d8b2e58bd774ed07621d01d332ac85a3706c27fddf948d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.9.19
|
Security for fastapi-query-tools 1.0.7
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.