Releases: fastapi/fastapi
0.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 using
Query
,Cookie
,Header
. PR #12199 by @tiangolo.
Translations
- 🌐 Add Portuguese translation for
docs/pt/docs/advanced/security/http-basic-auth.md
. PR #12195 by @ceb10n.
Internal
- ⬆ [pre-commit.ci] pre-commit autoupdate. PR #12204 by @pre-commit-ci[bot].
0.114.2
Fixes
- 🐛 Fix form field regression with
alias
. PR #12194 by @Wurstnase.
Translations
- 🌐 Add Portuguese translation for
docs/pt/docs/tutorial/request-form-models.md
. PR #12175 by @ceb10n. - 🌐 Add Chinese translation for
docs/zh/docs/project-generation.md
. PR #12170 by @waketzheng. - 🌐 Add Dutch translation for
docs/nl/docs/python-types.md
. PR #12158 by @maxscheijen.
Internal
0.114.1
Refactors
- ⚡️ Improve performance in request body parsing with a cache for internal model fields. PR #12184 by @tiangolo.
Docs
Translations
- 🌐 Add Portuguese translation for
docs/pt/docs/virtual-environments.md
. PR #12163 by @marcelomarkus. - 🌐 Add Portuguese translation for
docs/pt/docs/environment-variables.md
. PR #12162 by @marcelomarkus. - 🌐 Add Portuguese translation for
docs/pt/docs/tutorial/testing.md
. PR #12164 by @marcelomarkus. - 🌐 Add Portuguese translation for
docs/pt/docs/tutorial/debugging.md
. PR #12165 by @marcelomarkus. - 🌐 Add Korean translation for
docs/ko/docs/project-generation.md
. PR #12157 by @BORA040126.
Internal
- ⬆ Bump tiangolo/issue-manager from 0.5.0 to 0.5.1. PR #12173 by @dependabot[bot].
- ⬆ [pre-commit.ci] pre-commit autoupdate. PR #12176 by @pre-commit-ci[bot].
- 👷 Update
issue-manager.yml
. PR #12159 by @tiangolo. - ✏️ Fix typo in
fastapi/params.py
. PR #12143 by @surreal30.
0.114.0
You can restrict form fields to only include those declared in a Pydantic model and forbid any extra field sent in the request using Pydantic's model_config = {"extra": "forbid"}
:
from typing import Annotated
from fastapi import FastAPI, Form
from pydantic import BaseModel
app = FastAPI()
class FormData(BaseModel):
username: str
password: str
model_config = {"extra": "forbid"}
@app.post("/login/")
async def login(data: Annotated[FormData, Form()]):
return data
Read the new docs: Form Models - Forbid Extra Form Fields.
Features
Docs
Internal
0.113.0
Now you can declare form fields with Pydantic models:
from typing import Annotated
from fastapi import FastAPI, Form
from pydantic import BaseModel
app = FastAPI()
class FormData(BaseModel):
username: str
password: str
@app.post("/login/")
async def login(data: Annotated[FormData, Form()]):
return data
Read the new docs: Form Models.
Features
Internal
0.112.4
This release is mainly a big internal refactor to enable adding support for Pydantic models for Form
fields, but that feature comes in the next release.
This release shouldn't affect apps using FastAPI in any way. You don't even have to upgrade to this version yet. It's just a checkpoint. 🤓
Refactors
- ♻️ Refactor deciding if
embed
body fields, do not overwrite fields, compute once per router, refactor internals in preparation for Pydantic models inForm
,Query
and others. PR #12117 by @tiangolo.
Internal
0.112.3
This release is mainly internal refactors, it shouldn't affect apps using FastAPI in any way. You don't even have to upgrade to this version yet. There are a few bigger releases coming right after. 🚀
Refactors
- ♻️ Refactor internal
check_file_field()
, rename toensure_multipart_is_installed()
to clarify its purpose. PR #12106 by @tiangolo. - ♻️ Rename internal
create_response_field()
tocreate_model_field()
as it's used for more than response models. PR #12103 by @tiangolo. - ♻️ Refactor and simplify internal data from
solve_dependencies()
using dataclasses. PR #12100 by @tiangolo. - ♻️ Refactor and simplify internal
analyze_param()
to structure data with dataclasses instead of tuple. PR #12099 by @tiangolo. - ♻️ Refactor and simplify dependencies data structures with dataclasses. PR #12098 by @tiangolo.
Docs
- 📝 Add External Link: Techniques and applications of SQLAlchemy global filters in FastAPI. PR #12109 by @TheShubhendra.
- 📝 Add note about
time.perf_counter()
in middlewares. PR #12095 by @tiangolo. - 📝 Tweak middleware code sample
time.time()
totime.perf_counter()
. PR #11957 by @domdent. - 🔧 Update sponsors: Coherence. PR #12093 by @tiangolo.
- 📝 Fix async test example not to trigger DeprecationWarning. PR #12084 by @marcinsulikowski.
- 📝 Update
docs_src/path_params_numeric_validations/tutorial006.py
. PR #11478 by @MuhammadAshiqAmeer. - 📝 Update comma in
docs/en/docs/async.md
. PR #12062 by @Alec-Gillis. - 📝 Update docs about serving FastAPI: ASGI servers, Docker containers, etc.. PR #12069 by @tiangolo.
- 📝 Clarify
response_class
parameter, validations, and returning a response directly. PR #12067 by @tiangolo. - 📝 Fix minor typos and issues in the documentation. PR #12063 by @svlandeg.
- 📝 Add note in Docker docs about ensuring graceful shutdowns and lifespan events with
CMD
exec form. PR #11960 by @GPla.
Translations
- 🌐 Add Dutch translation for
docs/nl/docs/features.md
. PR #12101 by @maxscheijen. - 🌐 Add Portuguese translation for
docs/pt/docs/advanced/testing-events.md
. PR #12108 by @ceb10n. - 🌐 Add Portuguese translation for
docs/pt/docs/advanced/security/index.md
. PR #12114 by @ceb10n. - 🌐 Add Dutch translation for
docs/nl/docs/index.md
. PR #12042 by @svlandeg. - 🌐 Update Chinese translation for
docs/zh/docs/how-to/index.md
. PR #12070 by @synthpop123.
Internal
- ⬆ [pre-commit.ci] pre-commit autoupdate. PR #12115 by @pre-commit-ci[bot].
- ⬆ Bump pypa/gh-action-pypi-publish from 1.10.0 to 1.10.1. PR #12120 by @dependabot[bot].
- ⬆ Bump pillow from 10.3.0 to 10.4.0. PR #12105 by @dependabot[bot].
- 💚 Set
include-hidden-files
toTrue
when using theupload-artifact
GH action. PR #12118 by @svlandeg. - ⬆ Bump pypa/gh-action-pypi-publish from 1.9.0 to 1.10.0. PR #12112 by @dependabot[bot].
- 🔧 Update sponsors link: Coherence. PR #12097 by @tiangolo.
- 🔧 Update labeler config to handle sponsorships data. PR #12096 by @tiangolo.
- 🔧 Update sponsors, remove Kong. PR #12085 by @tiangolo.
- ⬆ [pre-commit.ci] pre-commit autoupdate. PR #12076 by @pre-commit-ci[bot].
- 👷 Update
latest-changes
GitHub Action. PR #12073 by @tiangolo.
0.112.2
Fixes
- 🐛 Fix
allow_inf_nan
option for Param and Body classes. PR #11867 by @giunio-prc. - 🐛 Ensure that
app.include_router
merges nested lifespans. PR #9630 by @Lancetnik.
Refactors
- 🎨 Fix typing annotation for semi-internal
FastAPI.add_api_route()
. PR #10240 by @ordinary-jamie. - ⬆️ Upgrade version of Ruff and reformat. PR #12032 by @tiangolo.
Docs
- 📝 Fix a typo in
docs/en/docs/virtual-environments.md
. PR #12064 by @aymenkrifa. - 📝 Add docs about Environment Variables and Virtual Environments. PR #12054 by @tiangolo.
- 📝 Add Asyncer mention in async docs. PR #12037 by @tiangolo.
- 📝 Move the Features docs to the top level to improve the main page menu. PR #12036 by @tiangolo.
- ✏️ Fix import typo in reference example for
Security
. PR #11168 by @0shah0. - 📝 Highlight correct line in tutorial
docs/en/docs/tutorial/body-multiple-params.md
. PR #11978 by @svlandeg. - 🔥 Remove Sentry link from Advanced Middleware docs. PR #12031 by @alejsdev.
- 📝 Clarify management tasks for translations, multiples files in one PR. PR #12030 by @tiangolo.
- 📝 Edit the link to the OpenAPI "Responses Object" and "Response Object" sections in the "Additional Responses in OpenAPI" section. PR #11996 by @VaitoSoi.
- 🔨 Specify
email-validator
dependency with dash. PR #11515 by @jirikuncar. - 🌐 Add Spanish translation for
docs/es/docs/project-generation.md
. PR #11947 by @alejsdev. - 📝 Fix minor typo. PR #12026 by @MicaelJarniac.
- 📝 Several docs improvements, tweaks, and clarifications. PR #11390 by @nilslindemann.
- 📝 Add missing
compresslevel
parameter on docs forGZipMiddleware
. PR #11350 by @junah201. - 📝 Fix inconsistent response code when item already exists in docs for testing. PR #11818 by @lokomilo.
- 📝 Update
docs/en/docs/tutorial/body.md
with Python 3.10 union type example. PR #11415 by @rangzen.
Translations
- 🌐 Add Portuguese translation for
docs/pt/docs/tutorial/request_file.md
. PR #12018 by @Joao-Pedro-P-Holanda. - 🌐 Add Japanese translation for
docs/ja/docs/learn/index.md
. PR #11592 by @ukwhatn. - 📝 Update Spanish translation docs for consistency. PR #12044 by @alejsdev.
- 🌐 Update Chinese translation for
docs/zh/docs/tutorial/dependencies/dependencies-with-yield.md
. PR #12028 by @xuvjso. - 📝 Update FastAPI People, do not translate to have the most recent info. PR #12034 by @tiangolo.
- 🌐 Update Urdu translation for
docs/ur/docs/benchmarks.md
. PR #10046 by @AhsanSheraz.
Internal
- ⬆ [pre-commit.ci] pre-commit autoupdate. PR #12046 by @pre-commit-ci[bot].
- 🔧 Update coverage config files. PR #12035 by @tiangolo.
- 🔨 Standardize shebang across shell scripts. PR #11942 by @gitworkflows.
- ⬆ Update sqlalchemy requirement from <1.4.43,>=1.3.18 to >=1.3.18,<2.0.33. PR #11979 by @dependabot[bot].
- 🔊 Remove old ignore warnings. PR #11950 by @tiangolo.
- ⬆️ Upgrade griffe-typingdoc for the docs. PR #12029 by @tiangolo.
- 🙈 Add .coverage* to
.gitignore
. PR #11940 by @gitworkflows. - ⚙️ Record and show test coverage contexts (what test covers which line). PR #11518 by @slafs.
0.112.1
Upgrades
- ⬆️ Allow Starlette 0.38.x, update the pin to
>=0.37.2,<0.39.0
. PR #11876 by @musicinmybrain.
Docs
- 📝 Update docs section about "Don't Translate these Pages". PR #12022 by @tiangolo.
- 📝 Add documentation for non-translated pages and scripts to verify them. PR #12020 by @tiangolo.
- 📝 Update docs about discussions questions. PR #11985 by @tiangolo.
Translations
- 🌐 Add Portuguese translation for
docs/pt/docs/tutorial/bigger-applications.md
. PR #11971 by @marcelomarkus. - 🌐 Add Portuguese translation for
docs/pt/docs/advanced/testing-websockets.md
. PR #11994 by @ceb10n. - 🌐 Add Portuguese translation for
docs/pt/docs/advanced/testing-dependencies.md
. PR #11995 by @ceb10n. - 🌐 Add Portuguese translation for
docs/pt/docs/advanced/using-request-directly.md
. PR #11956 by @ceb10n. - 🌐 Add French translation for
docs/fr/docs/tutorial/body-multiple-params.md
. PR #11796 by @pe-brian. - 🌐 Update Chinese translation for
docs/zh/docs/tutorial/query-params.md
. PR #11557 by @caomingpei. - 🌐 Update typo in Chinese translation for
docs/zh/docs/advanced/testing-dependencies.md
. PR #11944 by @bestony. - 🌐 Add Portuguese translation for
docs/pt/docs/advanced/sub-applications.md
anddocs/pt/docs/advanced/behind-a-proxy.md
. PR #11856 by @marcelomarkus. - 🌐 Add Portuguese translation for
docs/pt/docs/tutorial/cors.md
anddocs/pt/docs/tutorial/middleware.md
. PR #11916 by @wesinalves. - 🌐 Add French translation for
docs/fr/docs/tutorial/path-params-numeric-validations.md
. PR #11788 by @pe-brian.
Internal
- ⬆ Bump pypa/gh-action-pypi-publish from 1.8.14 to 1.9.0. PR #11727 by @dependabot[bot].
- 🔧 Add changelog URL to
pyproject.toml
, shows in PyPI. PR #11152 by @Pierre-VF. - 👷 Do not sync labels as it overrides manually added labels. PR #12024 by @tiangolo.
- 👷🏻 Update Labeler GitHub Actions. PR #12019 by @tiangolo.
- 🔧 Update configs for MkDocs for languages and social cards. PR #12016 by @tiangolo.
- 👷 Update permissions and config for labeler GitHub Action. PR #12008 by @tiangolo.
- 👷🏻 Add GitHub Action label-checker. PR #12005 by @tiangolo.
- 👷 Add label checker GitHub Action. PR #12004 by @tiangolo.
- 👷 Update GitHub Action add-to-project. PR #12002 by @tiangolo.
- 🔧 Update labeler GitHub Action. PR #12001 by @tiangolo.
- 👷 Add GitHub Action labeler. PR #12000 by @tiangolo.
- 👷 Add GitHub Action add-to-project. PR #11999 by @tiangolo.
- 📝 Update admonitions in docs missing. PR #11998 by @tiangolo.
- 🔨 Update docs.py script to enable dirty reload conditionally. PR #11986 by @tiangolo.
- 🔧 Update MkDocs instant previews. PR #11982 by @tiangolo.
- 🐛 Fix deploy docs previews script to handle mkdocs.yml files. PR #11984 by @tiangolo.
- 💡 Add comment about custom Termynal line-height. PR #11976 by @tiangolo.
- 👷 Add alls-green for test-redistribute. PR #11974 by @tiangolo.
- 👷 Update docs-previews to handle no docs changes. PR #11975 by @tiangolo.
- 🔨 Refactor script
deploy_docs_status.py
to account for deploy URLs with or without trailing slash. PR #11965 by @tiangolo. - 🔒️ Update permissions for deploy-docs action. PR #11964 by @tiangolo.
- 👷🏻 Add deploy docs status and preview links to PRs. PR #11961 by @tiangolo.
- 🔧 Update docs setup with latest configs and plugins. PR #11953 by @tiangolo.
- 🔇 Ignore warning from attrs in Trio. PR #11949 by @tiangolo.
0.112.0
Breaking Changes
- ♻️ Add support for
pip install "fastapi[standard]"
with standard dependencies andpython -m fastapi
. PR #11935 by @tiangolo.
Summary
Install with:
pip install "fastapi[standard]"
Other Changes
- This adds support for calling the CLI as:
python -m fastapi
- And it upgrades
fastapi-cli[standard] >=0.0.5
.
Technical Details
Before this, fastapi
would include the standard dependencies, with Uvicorn and the fastapi-cli
, etc.
And fastapi-slim
would not include those standard dependencies.
Now fastapi
doesn't include those standard dependencies unless you install with pip install "fastapi[standard]"
.
Before, you would install pip install fastapi
, now you should include the standard
optional dependencies (unless you want to exclude one of those): pip install "fastapi[standard]"
.
This change is because having the standard optional dependencies installed by default was being inconvenient to several users, and having to install instead fastapi-slim
was not being a feasible solution.
Discussed here: #11522 and here: #11525
Docs
- ✏️ Fix typos in docs. PR #11926 by @jianghuyiyuan.
- 📝 Tweak management docs. PR #11918 by @tiangolo.
- 🚚 Rename GitHub links from tiangolo/fastapi to fastapi/fastapi. PR #11913 by @tiangolo.
- 📝 Add docs about FastAPI team and project management. PR #11908 by @tiangolo.
- 📝 Re-structure docs main menu. PR #11904 by @tiangolo.
- 📝 Update Speakeasy URL. PR #11871 by @ndimares.
Translations
- 🌐 Update Portuguese translation for
docs/pt/docs/alternatives.md
. PR #11931 by @ceb10n. - 🌐 Add Russian translation for
docs/ru/docs/tutorial/dependencies/sub-dependencies.md
. PR #10515 by @AlertRED. - 🌐 Add Portuguese translation for
docs/pt/docs/advanced/response-change-status-code.md
. PR #11863 by @ceb10n. - 🌐 Add Portuguese translation for
docs/pt/docs/reference/background.md
. PR #11849 by @lucasbalieiro. - 🌐 Add Portuguese translation for
docs/pt/docs/tutorial/dependencies/dependencies-with-yield.md
. PR #11848 by @Joao-Pedro-P-Holanda. - 🌐 Add Portuguese translation for
docs/pt/docs/reference/apirouter.md
. PR #11843 by @lucasbalieiro.
Internal
- 🔧 Update sponsors: add liblab. PR #11934 by @tiangolo.
- 👷 Update GitHub Action label-approved permissions. PR #11933 by @tiangolo.
- 👷 Refactor GitHub Action to comment docs deployment URLs and update token. PR #11925 by @tiangolo.
- 👷 Update tokens for GitHub Actions. PR #11924 by @tiangolo.
- 👷 Update token permissions to comment deployment URL in docs. PR #11917 by @tiangolo.
- 👷 Update token permissions for GitHub Actions. PR #11915 by @tiangolo.
- 👷 Update GitHub Actions token usage. PR #11914 by @tiangolo.
- 👷 Update GitHub Action to notify translations with label
approved-1
. PR #11907 by @tiangolo. - 🔧 Update sponsors, remove Reflex. PR #11875 by @tiangolo.
- 🔧 Update sponsors: remove TalkPython. PR #11861 by @tiangolo.
- 🔨 Update docs Termynal scripts to not include line nums for local dev. PR #11854 by @tiangolo.