Update dependency fastapi to v0.115.0
This MR contains the following updates:
Package | Update | Change |
---|---|---|
fastapi (changelog) | minor |
==0.114.2 -> ==0.115.0
|
⚠ WarningSome dependencies could not be looked up. Check the warning logs for more information.
Release Notes
fastapi/fastapi (fastapi)
v0.115.0
Highlights
Now you can declare Query
, Header
, and Cookie
parameters with Pydantic models.
Query
Parameter Models
Use Pydantic models for Query
parameters:
from typing import Annotated, Literal
from fastapi import FastAPI, Query
from pydantic import BaseModel, Field
app = FastAPI()
class FilterParams(BaseModel):
limit: int = Field(100, gt=0, le=100)
offset: int = Field(0, ge=0)
order_by: Literal["created_at", "updated_at"] = "created_at"
tags: list[str] = []
@​app.get("/items/")
async def read_items(filter_query: Annotated[FilterParams, Query()]):
return filter_query
Read the new docs: Query Parameter Models.
Header
Parameter Models
Use Pydantic models for Header
parameters:
from typing import Annotated
from fastapi import FastAPI, Header
from pydantic import BaseModel
app = FastAPI()
class CommonHeaders(BaseModel):
host: str
save_data: bool
if_modified_since: str | None = None
traceparent: str | None = None
x_tag: list[str] = []
@​app.get("/items/")
async def read_items(headers: Annotated[CommonHeaders, Header()]):
return headers
Read the new docs: Header Parameter Models.
Cookie
Parameter Models
Use Pydantic models for Cookie
parameters:
from typing import Annotated
from fastapi import Cookie, FastAPI
from pydantic import BaseModel
app = FastAPI()
class Cookies(BaseModel):
session_id: str
fatebook_tracker: str | None = None
googall_tracker: str | None = None
@​app.get("/items/")
async def read_items(cookies: Annotated[Cookies, Cookie()]):
return cookies
Read the new docs: Cookie Parameter Models.
Forbid Extra Query (Cookie, Header) Parameters
Use Pydantic models to restrict extra values for Query
parameters (also applies to Header
and Cookie
parameters).
To achieve it, use Pydantic's model_config = {"extra": "forbid"}
:
from typing import Annotated, Literal
from fastapi import FastAPI, Query
from pydantic import BaseModel, Field
app = FastAPI()
class FilterParams(BaseModel):
model_config = {"extra": "forbid"}
limit: int = Field(100, gt=0, le=100)
offset: int = Field(0, ge=0)
order_by: Literal["created_at", "updated_at"] = "created_at"
tags: list[str] = []
@​app.get("/items/")
async def read_items(filter_query: Annotated[FilterParams, Query()]):
return filter_query
This applies to Query
, Header
, and Cookie
parameters, read the new docs:
Features
-
✨ Add support for Pydantic models for parameters usingQuery
,Cookie
,Header
. MR #12199 by @tiangolo.
Translations
-
🌐 Add Portuguese translation fordocs/pt/docs/advanced/security/http-basic-auth.md
. MR #12195 by @ceb10n.
Internal
-
⬆ [pre-commit.ci] pre-commit autoupdate. MR #12204 by @pre-commit-ci[bot].
Configuration
-
If you want to rebase/retry this MR, check this box
This MR has been generated by Renovate Bot.