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

Uploaded Python 3

File details

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

File metadata

  • Download URL: unboil_fastapi_query-0.1.0.tar.gz
  • Upload date:
  • Size: 42.8 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.0.tar.gz
Algorithm Hash digest
SHA256 6c445941ed2d2537495d962617c5c333d49547bb1fa210a0070b306ab639bbe0
MD5 09ab2391150d1b183afb3bd88e96101f
BLAKE2b-256 a260f8ea570755c3bd8146cff979868bb310b1a21760e3bc895bc808e99aa189

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for unboil_fastapi_query-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f3c58620249fec1e08dca08b82a6ca4043f05267f4b960e07f1c01e1d66fa8d5
MD5 69084098c6819da79a102867f61f7d92
BLAKE2b-256 9f31d51e11d93d7de39e5d0918557685a984aa3f99616c4d62a1fef2b8a9b309

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