A library providing tools for easily querying a FastAPI application.
Project description
unboil-fastapi-query
Easily add advanced filtering and sorting to your FastAPI endpoints using SQLAlchemy.
Installation
pip install unboil-fastapi-query
Quick Start
- Define your SQLAlchemy models as usual.
- Build a query model using
build_query:
from unboil_fastapi_query import build_query, FilterOperation
ExampleQuery = build_query(
filters={
Example.id: FilterOperation.EQ,
Example.name: "*", # allow all operations
},
sortables=[Example.name]
)
- Use
QueryDependsin your FastAPI endpoint:
from unboil_fastapi_query import QueryDepends
@app.get("/", response_model=list[ExampleRead])
def list(query = QueryDepends(ExampleQuery)):
with Session(engine) as session:
stmt = select(Example)
stmt = apply_query(stmt, query)
result = session.execute(stmt)
return result.scalars().all()
- Enjoy automatic filtering and sorting via query parameters:
/api?filter.name.eq=Alice/api?sort=sort.name.asc
Example
See examples/main.py for a complete example.
Testing
Run tests with:
pytest
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file unboil_fastapi_query-0.1.1.tar.gz.
File metadata
- Download URL: unboil_fastapi_query-0.1.1.tar.gz
- Upload date:
- Size: 42.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
496dc8585156369261d86b3f2508e7a82debdba6dd015940a387056342746bbd
|
|
| MD5 |
faaa9ec7150a1d1b797664ef3cb306c0
|
|
| BLAKE2b-256 |
abe6543b5e35974cac1253d81ecc34b337f583dc86c0e9e1d79c418b26df6ccc
|
File details
Details for the file unboil_fastapi_query-0.1.1-py3-none-any.whl.
File metadata
- Download URL: unboil_fastapi_query-0.1.1-py3-none-any.whl
- Upload date:
- Size: 4.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9a3a0695066d4772d79c114c7ac94c168996ce4b189e3170649fc975450da4d0
|
|
| MD5 |
6e76ddd66eff7672a31690e27468bc2b
|
|
| BLAKE2b-256 |
d73fb5e3387cb0f2e4ab8b4954dac6a81585d9d9da8911a962fe912bcf5b8adc
|