Skip to main content

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

  1. Define your SQLAlchemy models as usual.
  2. 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]
)
  1. Use QueryDepends in 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()
  1. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

unboil_fastapi_query-0.1.2.tar.gz (43.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

unboil_fastapi_query-0.1.2-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file unboil_fastapi_query-0.1.2.tar.gz.

File metadata

  • Download URL: unboil_fastapi_query-0.1.2.tar.gz
  • Upload date:
  • Size: 43.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for unboil_fastapi_query-0.1.2.tar.gz
Algorithm Hash digest
SHA256 51c077c3e73b5f0c7a1bd79c17ae0a9217c7a73466d078aaaf027ed6d337cb4c
MD5 1832f194e8f1551d25de310399414333
BLAKE2b-256 a1d474099f0f3177712e26c992a49010d08b0bd63f67b31b588951358239c74c

See more details on using hashes here.

File details

Details for the file unboil_fastapi_query-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for unboil_fastapi_query-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5f5b4e49048f6315eae093e5fd2f9df66c84e26df370c75fdaa22977bdefd80f
MD5 c296055cc30450691ca746b035f77c65
BLAKE2b-256 b52435fcf993060af1ddd749cb6501a1f2c17125f98956976308fbaf2ee9bded

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page