Debian Codegraph @

docs_src/path_params_numeric_validations/tutorial006_an_py310.py

raw
1 from typing import Annotated
2
3 from fastapi import FastAPI, Path, Query
4
5 app = FastAPI()
6
7
8 @app.get("/items/{item_id}")
9 async def read_items(
10 *,
11 item_id: Annotated[int, Path(title="The ID of the item to get", ge=0, le=1000)],
12 q: str,
13 size: Annotated[float, Query(gt=0, lt=10.5)],
14 ):
15 results = {"item_id": item_id}
16 if q:
17 results.update({"q": q})
18 if size:
19 results.update({"size": size})
20 return results