Releases: fastapi/fastapi
0.109.2
0.109.1
Security fixes
- ⬆️ Upgrade minimum version of
python-multipart
to>=0.0.7
to fix a vulnerability when using form data with a ReDos attack. You can also simply upgradepython-multipart
.
Read more in theadvisory: Content-Type Header ReDoS.
Features
Refactors
- ✅ Refactor tests for duplicate operation ID generation for compatibility with other tools running the FastAPI test suite. PR#10876by@emmettbutler.
- ♻️ Simplify string format with f-strings in
fastapi/utils.py
.PR#10576by@eukub. - 🔧 Fix Ruff configuration unintentionally enabling and re-disabling mccabe complexity check. PR#10893by@jiridanek.
- ✅ Re-enable test in
tests/test_tutorial/test_header_params/test_tutorial003.py
after fix in Starlette. PR#10904by@ooknimm.
Docs
- 📝 Tweak wording in
help-fastapi.md
.PR#11040by@tiangolo. - 📝 Tweak docs for Behind a Proxy. PR#11038by@tiangolo.
- 📝 Add External Link: 10 Tips for adding SQLAlchemy to FastAPI. PR#11036by@Donnype.
- 📝 Add External Link: Tips on migrating from Flask to FastAPI and vice-versa. PR#11029by@jtemporal.
- 📝 Deprecate old tutorials: Peewee, Couchbase, encode/databases. PR#10979by@tiangolo.
- ✏️ Fix typo in
fastapi/security/oauth2.py
.PR#10972by@RafalSkolasinski. - 📝 Update
HTTPException
details indocs/en/docs/tutorial/handling-errors.md
.PR#5418by@papb. - ✏️ A few tweaks in
docs/de/docs/tutorial/first-steps.md
.PR#10959by@nilslindemann. - ✏️ Fix link in
docs/en/docs/advanced/async-tests.md
.PR#10960by@nilslindemann. - ✏️ Fix typos for Spanish documentation. PR#10957by@jlopezlira.
- 📝 Add warning about lifespan functions and backwards compatibility with events. PR#10734by@jacob-indigo.
- ✏️ Fix broken link in
docs/tutorial/sql-databases.md
in several languages. PR#10716by@theoohoho. - ✏️ Remove broken links from
external_links.yml
.PR#10943by@Torabek. - 📝 Update template docs with more info about
url_for
.PR#5937by@EzzEddin. - 📝 Update usage of Token model in security docs. PR#9313by@piotrszacilowski.
- ✏️ Update highlighted line in
docs/en/docs/tutorial/bigger-applications.md
.PR#5490by@papb. - 📝 Add External Link: Explore How to Effectively Use JWT With FastAPI. PR#10212by@aanchlia.
- 📝 Add hyperlink to
docs/en/docs/tutorial/static-files.md
.PR#10243by@hungtsetse. - 📝 Add External Link: Instrument a FastAPI service adding tracing with OpenTelemetry and send/show traces in Grafana Tempo. PR#9440by@softwarebloat.
- 📝 Review and rewording of
en/docs/contributing.md
.PR#10480by@nilslindemann. - 📝 Add External Link: ML serving and monitoring with FastAPI and Evidently. PR#9701by@mnrozhkov.
- 📝 Reword in docs, from "have in mind" to "keep in mind". PR#10376by@malicious.
- 📝 Add External Link: Talk by Jeny Sadadia. PR#10265by@JenySadadia.
- 📝 Add location info to
tutorial/bigger-applications.md
.PR#10552by@nilslindemann. - ✏️ Fix Pydantic method name in
docs/en/docs/advanced/path-operation-advanced-configuration.md
.PR#10826by@ahmedabdou14.
Translations
- 🌐 Add Spanish translation for
docs/es/docs/external-links.md
.PR#10933by@pablocm83. - 🌐 Update Korean translation for
docs/ko/docs/tutorial/first-steps.md
,docs/ko/docs/tutorial/index.md
,docs/ko/docs/tutorial/path-params.md
,anddocs/ko/docs/tutorial/query-params.md
.PR#4218by@SnowSuno. - 🌐 Add Chinese translation for
docs/zh/docs/tutorial/dependencies/dependencies-with-yield.md
.PR#10870by@zhiquanchi. - 🌐 Add Chinese translation for
docs/zh/docs/deployment/concepts.md
.PR#10282by@xzmeng. - 🌐 Add Azerbaijani translation for
docs/az/docs/index.md
.PR#11047by@aykhans. - 🌐 Add Korean translation for
docs/ko/docs/tutorial/middleware.md
.PR#2829by@JeongHyeongKim. - 🌐 Add German translation for
docs/de/docs/tutorial/body-nested-models.md
.PR#10313by@nilslindemann. - 🌐 Add Persian translation for
docs/fa/docs/tutorial/middleware.md
.PR#9695by@mojtabapaso. - 🌐 Update Farsi translation for
docs/fa/docs/index.md
.PR#10216by@theonlykingpin. - 🌐 Add German translation for
docs/de/docs/tutorial/body-fields.md
.PR#10310by@nilslindemann. - 🌐 Add German translation for
docs/de/docs/tutorial/body.md
.PR#10295by@nilslindemann. - 🌐 Add German translation for
docs/de/docs/tutorial/body-multiple-params.md
.PR#10308by@nilslindemann. - 🌐 Add Japanese translation for
docs/ja/docs/tutorial/security/get-current-user.md
.PR#2681by@sh0nk. - 🌐 Add Chinese translation for
docs/zh/docs/advanced/advanced-dependencies.md
.PR#3798by@jaystone776. - 🌐 Add Chinese translation for
docs/zh/docs/advanced/events.md
.PR#3815by@jaystone776. - 🌐 Add Chinese translation for
docs/zh/docs/advanced/behind-a-proxy.md
.PR#3820by@jaystone776. - 🌐 Add Chinese translation for
docs/zh/docs/advanced/testing-events.md
.PR#3818by@jaystone776. - 🌐 Add Chinese translation for
docs/zh/docs/advanced/testing-websockets.md
.PR#3817by@jaystone776. - 🌐 Add Chinese translation for
docs/zh/docs/advanced/testing-database.md
.PR#3821by@jaystone776. - 🌐 Add Chinese translation for
docs/zh/docs/deployment/deta.md
.PR#3837by@jaystone776. - 🌐 Add Chinese translation for
docs/zh/docs/history-design-future.md
.PR#3832by@jaystone776. - 🌐 Add Chinese translation for
docs/zh/docs/project-generation.md
.PR#3831by@jaystone776. - 🌐 Add Chinese translation for
docs/zh/docs/deployment/docker.md
.PR [#10296](https://gi...
0.109.0
Features
Upgrades
- ⬆️ Upgrade Starlette to
>=0.29.0,<0.33.0
,update docs and usage of templates with new Starlette arguments. Remove pin of AnyIO>=3.7.1,<4.0.0
,add support for AnyIO 4.x.x. PR#10846by@tiangolo.
Docs
- ✏️ Fix typo in
docs/en/docs/alternatives.md
.PR#10931by@s111d. - 📝 Replace
email
withusername
indocs_src/security/tutorial007
code examples. PR#10649by@nilslindemann. - 📝 Add VS Code tutorial link. PR#10592by@nilslindemann.
- 📝 Add notes about Pydantic v2's new
.model_dump()
.PR#10929by@tiangolo. - 📝 Fix broken link in
docs/en/docs/tutorial/sql-databases.md
.PR#10765by@HurSungYun. - 📝 Add External Link: FastAPI application monitoring made easy. PR#10917by@tiangolo.
- ✨ Generate automatic language names for docs translations. PR#5354by@jakul.
- ✏️ Fix typos in
docs/en/docs/alternatives.md
anddocs/en/docs/tutorial/dependencies/index.md
.PR#10906by@s111d. - ✏️ Fix typos in
docs/en/docs/tutorial/dependencies/dependencies-with-yield.md
.PR#10834by@Molkree. - 📝 Add article: "Building a RESTful API with FastAPI: Secure Signup and Login Functionality Included". PR#9733by@dxphilo.
- 📝 Add warning about lifecycle events with
AsyncClient
.PR#4167by@andrew-chang-dewitt. - ✏️ Fix typos in
/docs/reference/exceptions.md
and/en/docs/reference/status.md
.PR#10809by@clarencepenz. - ✏️ Fix typo in
openapi-callbacks.md
.PR#10673by@kayjan. - ✏️ Fix typo in
fastapi/routing.py
.PR#10520by@sepsh. - 📝 Replace HTTP code returned in case of existing user error in docs for testing. PR#4482by@TristanMarion.
- 📝 Add blog for FastAPI & Supabase. PR#6018by@theinfosecguy.
- 📝 Update example source files for SQL databases with SQLAlchemy. PR#9508by@s-mustafa.
- 📝 Update code examples in docs for body, replace name
create_item
withupdate_item
when appropriate. PR#5913by@OttoAndrey. - ✏️ Fix typo in dependencies with yield source examples. PR#10847by@tiangolo.
Translations
- 🌐 Add Bengali translation for
docs/bn/docs/index.md
.PR#9177by@Fahad-Md-Kamal. - ✏️ Update Python version in
index.md
in several languages. PR#10711by@tamago3keran. - 🌐 Add Russian translation for
docs/ru/docs/tutorial/request-forms-and-files.md
.PR#10347by@AlertRED. - 🌐 Add Ukrainian translation for
docs/uk/docs/index.md
.PR#10362by@rostik1410. - ✏️ Update Python version in
docs/ko/docs/index.md
.PR#10680by@Eeap. - 🌐 Add Persian translation for
docs/fa/docs/features.md
.PR#5887by@amirilf. - 🌐 Add Chinese translation for
docs/zh/docs/advanced/additional-responses.md
.PR#10325by@ShuibeiC. - 🌐 Fix typos in Russian translations for
docs/ru/docs/tutorial/background-tasks.md
,docs/ru/docs/tutorial/body-nested-models.md
,docs/ru/docs/tutorial/debugging.md
,docs/ru/docs/tutorial/testing.md
.PR#10311by@AlertRED. - 🌐 Add Russian translation for
docs/ru/docs/tutorial/request-files.md
.PR#10332by@AlertRED. - 🌐 Add Chinese translation for
docs/zh/docs/deployment/server-workers.md
.PR#10292by@xzmeng. - 🌐 Add Chinese translation for
docs/zh/docs/deployment/cloud.md
.PR#10291by@xzmeng. - 🌐 Add Chinese translation for
docs/zh/docs/deployment/manually.md
.PR#10279by@xzmeng. - 🌐 Add Chinese translation for
docs/zh/docs/deployment/https.md
.PR#10277by@xzmeng. - 🌐 Add Chinese translation for
docs/zh/docs/deployment/index.md
.PR#10275by@xzmeng. - 🌐 Add German translation for
docs/de/docs/tutorial/first-steps.md
.PR#9530by@fhabers21. - 🌐 Update Turkish translation for
docs/tr/docs/index.md
.PR#10444by@hasansezertasan. - 🌐 Add Chinese translation for
docs/zh/docs/learn/index.md
.PR#10479by@KAZAMA-DREAM. - 🌐 Add Russian translation for
docs/ru/docs/learn/index.md
.PR#10539by@AlertRED. - 🌐 Update SQLAlchemy instruction in Chinese translation
docs/zh/docs/tutorial/sql-databases.md
.PR#9712by@Royc30ne. - 🌐 Add Turkish translation for
docs/tr/docs/external-links.md
.PR#10549by@hasansezertasan. - 🌐 Add Spanish translation for
docs/es/docs/learn/index.md
.PR#10885by@pablocm83. - 🌐 Add Ukrainian translation for
docs/uk/docs/tutorial/body-fields.md
.PR#10670by@ArtemKhymenko. - 🌐 Add Hungarian translation for
/docs/hu/docs/index.md
.PR#10812by@takacs. - 🌐 Add Turkish translation for
docs/tr/docs/newsletter.md
.PR#10550by@hasansezertasan. - 🌐 Add Spanish translation for
docs/es/docs/help/index.md
.PR#10907by@pablocm83. - 🌐 Add Spanish translation for
docs/es/docs/about/index.md
.PR#10908by@pablocm83. - 🌐 Add Spanish translation for
docs/es/docs/resources/index.md
.PR#10909by@pablocm83.
Internal
- 👥 Update FastAPI People. PR#10871by@tiangolo.
- 👷 Upgrade custom GitHub Action comment-docs-preview-in-pr. PR#10916by@tiangolo.
- ⬆️ Upgrade GitHub Action latest-changes. PR#10915by@tiangolo.
- 👷 Upgrade GitHub Action label-approved. PR#10913by@tiangolo.
- ⬆️ Upgrade GitHub Action label-approved. PR#10905by@tiangolo.
0.108.0
0.107.0
0.106.0
Breaking Changes
Using resources from dependencies withyield
in background tasks is no longer supported.
This change is what supports the new features, read below. 🤓
Dependencies withyield
,HTTPException
and Background Tasks
Dependencies withyield
now can raiseHTTPException
and other exceptions afteryield
.🎉
Read the new docs here:Dependencies withyield
andHTTPException
.
fromfastapiimportDepends,FastAPI,HTTPException
fromtyping_extensionsimportAnnotated
app=FastAPI()
data={
"plumbus":{"description":"Freshly pickled plumbus","owner":"Morty"},
"portal-gun":{"description":"Gun to create portals","owner":"Rick"},
}
classOwnerError(Exception):
pass
defget_username():
try:
yield"Rick"
exceptOwnerErrorase:
raiseHTTPException(status_code=400,detail=f "Onwer error:{e}")
@app.get("/items/{item_id}")
defget_item(item_id:str,username:Annotated[str,Depends(get_username)]):
ifitem_idnotindata:
raiseHTTPException(status_code=404,detail="Item not found")
item=data[item_id]
ifitem["owner"]!=username:
raiseOwnerError(username)
returnitem
Before FastAPI 0.106.0, raising exceptions afteryield
was not possible, the exit code in dependencies withyield
was executedafterthe response was sent, soException Handlerswould have already run.
This was designed this way mainly to allow using the same objects "yielded" by dependencies inside of background tasks, because the exit code would be executed after the background tasks were finished.
Nevertheless, as this would mean waiting for the response to travel through the network while unnecessarily holding a resource in a dependency with yield (for example a database connection), this was changed in FastAPI 0.106.0.
Additionally, a background task is normally an independent set of logic that should be handled separately, with its own resources (e.g. its own database connection).
If you used to rely on this behavior, now you should create the resources for background tasks inside the background task itself, and use internally only data that doesn't depend on the resources of dependencies withyield
.
For example, instead of using the same database session, you would create a new database session inside of the background task, and you would obtain the objects from the database using this new session. And then instead of passing the object from the database as a parameter to the background task function, you would pass the ID of that object and then obtain the object again inside the background task function.
The sequence of execution before FastAPI 0.106.0 was like the diagram in theRelease Notes for FastAPI 0.106.0.
The new execution flow can be found in the docs:Execution of dependencies withyield
.
0.105.0
Features
- ✨ Add support for multiple Annotated annotations, e.g.
Annotated[str, Field(), Query()]
.PR#10773by@tiangolo.
Refactors
Docs
Internal
- 🔧 Update sponsors, add Scalar. PR#10728by@tiangolo.
- 🔧 Update sponsors, add PropelAuth. PR#10760by@tiangolo.
- 👷 Update build docs, verify README on CI. PR#10750by@tiangolo.
- 🔧 Update sponsors, remove Fern. PR#10729by@tiangolo.
- 🔧 Update sponsors, add Codacy. PR#10677by@tiangolo.
- 🔧 Update sponsors, add Reflex. PR#10676by@tiangolo.
- 📝 Update release notes, move and check latest-changes. PR#10588by@tiangolo.
- 👷 Upgrade latest-changes GitHub Action. PR#10587by@tiangolo.
0.104.1
Fixes
- 📌 Pin Swagger UI version to 5.9.0 temporarily to handle a bug crashing it in 5.9.1. PR#10529by@alejandraklachquin.
- This is not really a bug in FastAPI but in Swagger UI, nevertheless pinning the version will work while a solution is found on theSwagger UI side.
Docs
- 📝 Update data structure and render for external-links. PR#10495by@tiangolo.
- ✏️ Fix link to SPDX license identifier in
docs/en/docs/tutorial/metadata.md
.PR#10433by@worldworm. - 📝 Update example validation error from Pydantic v1 to match Pydantic v2 in
docs/en/docs/tutorial/path-params.md
.PR#10043by@giuliowaitforitdavide. - ✏️ Fix typos in emoji docs and in some source examples. PR#10438by@afuetterer.
- ✏️ Fix typo in
docs/en/docs/reference/dependencies.md
.PR#10465by@suravshresth. - ✏️ Fix typos and rewordings in
docs/en/docs/tutorial/body-nested-models.md
.PR#10468by@yogabonito. - 📝 Update docs, remove references to removed
pydantic.Required
indocs/en/docs/tutorial/query-params-str-validations.md
.PR#10469by@yogabonito. - ✏️ Fix typo in
docs/en/docs/reference/index.md
.PR#10467by@tarsil. - 🔥 Remove unnecessary duplicated docstrings. PR#10484by@tiangolo.
Internal
- ✏️ Update Pydantic links to dotenv support. PR#10511by@White-Mask.
- ✏️ Update links in
docs/en/docs/async.md
anddocs/zh/docs/async.md
to make them relative. PR#10498by@hasnatsajid. - ✏️ Fix links in
docs/em/docs/async.md
.PR#10507by@hasnatsajid. - ✏️ Fix typo in
docs/em/docs/index.md
,Python 3.8. PR#10521by@kerriop. - ⬆ Bump pillow from 9.5.0 to 10.1.0. PR#10446by@dependabot[bot].
- ⬆ Update mkdocs-material requirement from <9.0.0,>=8.1.4 to >=8.1.4,<10.0.0. PR#5862by@dependabot[bot].
- ⬆ Bump mkdocs-material from 9.1.21 to 9.4.7. PR#10545by@dependabot[bot].
- 👷 Install MkDocs Material Insiders only when secrets are available, for Dependabot. PR#10544by@tiangolo.
- 🔧 Update sponsors badges, Databento. PR#10519by@tiangolo.
- 👷 Adopt Ruff format. PR#10517by@tiangolo.
- 🔧 Add
CITATION.cff
file for academic citations. PR#10496by@tiangolo. - 🐛 Fix overriding MKDocs theme lang in hook. PR#10490by@tiangolo.
- 🔥 Drop/close Gitter chat. Questions should go to GitHub Discussions, free conversations to Discord.. PR#10485by@tiangolo.
0.104.0
Features
- ✨ Add reference (code API) docs with PEP 727, add subclass with custom docstrings for
BackgroundTasks
,refactor docs structure. PR#10392by@tiangolo.New docs atFastAPI Reference - Code API.
Upgrades
Internal
- ⬆ Bump dawidd6/action-download-artifact from 2.27.0 to 2.28.0. PR#10268by@dependabot[bot].
- ⬆ Bump actions/checkout from 3 to 4. PR#10208by@dependabot[bot].
- ⬆ Bump pypa/gh-action-pypi-publish from 1.8.6 to 1.8.10. PR#10061by@dependabot[bot].
- 🔧 Update sponsors, Bump.sh images. PR#10381by@tiangolo.
- 👥 Update FastAPI People. PR#10363by@tiangolo.
0.103.2
Refactors
- ⬆️ Upgrade compatibility with Pydantic v2.4, new renamed functions and JSON Schema input/output models with default values. PR#10344by@tiangolo.
Translations
- 🌐 Add Ukrainian translation for
docs/uk/docs/tutorial/extra-data-types.md
.PR#10132by@ArtemKhymenko. - 🌐 Fix typos in French translations for
docs/fr/docs/advanced/path-operation-advanced-configuration.md
,docs/fr/docs/alternatives.md
,docs/fr/docs/async.md
,docs/fr/docs/features.md
,docs/fr/docs/help-fastapi.md
,docs/fr/docs/index.md
,docs/fr/docs/python-types.md
,docs/fr/docs/tutorial/body.md
,docs/fr/docs/tutorial/first-steps.md
,docs/fr/docs/tutorial/query-params.md
.PR#10154by@s-rigaud. - 🌐 Add Chinese translation for
docs/zh/docs/async.md
.PR#5591by@mkdir700. - 🌐 Update Chinese translation for
docs/tutorial/security/simple-oauth2.md
.PR#3844by@jaystone776. - 🌐 Add Korean translation for
docs/ko/docs/deployment/cloud.md
.PR#10191by@Sion99. - 🌐 Add Japanese translation for
docs/ja/docs/deployment/https.md
.PR#10298by@tamtam-fitness. - 🌐 Fix typo in Russian translation for
docs/ru/docs/tutorial/body-fields.md
.PR#10224by@AlertRED. - 🌐 Add Polish translation for
docs/pl/docs/help-fastapi.md
.PR#10121by@romabozhanovgithub. - 🌐 Add Russian translation for
docs/ru/docs/tutorial/header-params.md
.PR#10226by@AlertRED. - 🌐 Add Chinese translation for
docs/zh/docs/deployment/versions.md
.PR#10276by@xzmeng.
Internal
- 🔧 Update sponsors, remove Flint. PR#10349by@tiangolo.
- 🔧 Rename label "awaiting review" to "awaiting-review" to simplify search queries. PR#10343by@tiangolo.
- 🔧 Update sponsors, enable Svix (revert#10228). PR#10253by@tiangolo.
- 🔧 Update sponsors, remove Svix. PR#10228by@tiangolo.
- 🔧 Update sponsors, add Bump.sh. PR#10227by@tiangolo.