FastAPI-Query-Conditions is a dependency that parses a query string into conditions using operators enclosed in square brackets
Project description
fastapi-query-conditions
Introduction
FastAPI-Query-Conditions is a dependency that parses a query string into conditions using operators enclosed in square brackets.
For example, if you send a request to /orders?amount[gte]=1000&amount[lt]=2000
, you can use the query string as parsed conditions like this:
{"gte":1000,"lt":2000}
Install
> pip install fastapi-query-conditions
Quick Start
from typing import Dict
from fastapi import Depends, FastAPI
from fastapi_query_conditions import query_conditions
app = FastAPI()
@app.get("/items")
def read_root(amount: Dict[str, int] = Depends(query_conditions(field='amount', factory=int))):
print(amount)
return amount
Then, if you send a request to /items?amount[gte]=1000&amount[lt]=2000
, you can check the following results.
{'gte': 1000, 'lt': 2000}
Also, you can use various factory functions for your query parameter.
from typing import Dict
from fastapi import Depends, FastAPI
from fastapi_query_conditions import query_conditions
from datetime import datetime
app = FastAPI()
@app.get("/orders")
def read_root(time: Dict[str, int] = Depends(query_conditions(field='time', factory=datetime.fromisoformat))):
print(time)
return time
Then, if you send a request to /orders?time[gte]=2022-10-18T12:00&time[lt]=2022-10-18T12:30
, you can check the following results.
{'gte': datetime.datetime(2022, 10, 18, 12, 0), 'lt': datetime.datetime(2022, 10, 18, 12, 30)}
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
File details
Details for the file fastapi-query-conditions-1.0.1.tar.gz
.
File metadata
- Download URL: fastapi-query-conditions-1.0.1.tar.gz
- Upload date:
- Size: 2.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9d73f0eba882feaca1c817b9ef0d690da5c8d21606d00eefc93f90b92c3c4483 |
|
MD5 | 9598559295fc4cfc86cdc444fbbc6b8b |
|
BLAKE2b-256 | 224b4c75cdea99ff67c442a36e172a452901689c7e95ac8f1a18bd042e6de953 |
Provenance
File details
Details for the file fastapi_query_conditions-1.0.1-py3-none-any.whl
.
File metadata
- Download URL: fastapi_query_conditions-1.0.1-py3-none-any.whl
- Upload date:
- Size: 3.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | eab2917fe35d43c074f8a882a4a897fa56c0e50468af6c3fd87047abbcfdaf52 |
|
MD5 | 63aa9a620384f228783ede771acbc987 |
|
BLAKE2b-256 | 16cecdd7405131b1388e74462079cbbd0b7e7b29d92a36fab31d3041e36e59a2 |