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.1.tar.gz (42.9 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.1-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

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

Hashes for unboil_fastapi_query-0.1.1.tar.gz
Algorithm Hash digest
SHA256 496dc8585156369261d86b3f2508e7a82debdba6dd015940a387056342746bbd
MD5 faaa9ec7150a1d1b797664ef3cb306c0
BLAKE2b-256 abe6543b5e35974cac1253d81ecc34b337f583dc86c0e9e1d79c418b26df6ccc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for unboil_fastapi_query-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9a3a0695066d4772d79c114c7ac94c168996ce4b189e3170649fc975450da4d0
MD5 6e76ddd66eff7672a31690e27468bc2b
BLAKE2b-256 d73fb5e3387cb0f2e4ab8b4954dac6a81585d9d9da8911a962fe912bcf5b8adc

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