Release Notes¶
Latest Changes¶
Docs¶
- ๐ Replace HTTP code returned in case of existing user error in docs for testing. PR #4482 by @TristanMarion.
- ๐ Add blog for FastAPI & Supabase. PR #6018 by @theinfosecguy.
- ๐ Update example source files for SQL databases with SQLAlchemy. PR #9508 by @s-mustafa.
- ๐ Update code examples in docs for body, replace name
create_item
withupdate_item
when appropriate. PR #5913 by @OttoAndrey. - โ๏ธ Fix typo in dependencies with yield source examples. PR #10847 by @tiangolo.
Translations¶
- ๐ Add Chinese translation for
docs/zh/docs/advanced/additional-responses.md
. PR #10325 by @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 #10311 by @AlertRED. - ๐ Add Russian translation for
docs/ru/docs/tutorial/request-files.md
. PR #10332 by @AlertRED. - ๐ Add Chinese translation for
docs/zh/docs/deployment/server-workers.md
. PR #10292 by @xzmeng. - ๐ Add Chinese translation for
docs/zh/docs/deployment/cloud.md
. PR #10291 by @xzmeng. - ๐ Add Chinese translation for
docs/zh/docs/deployment/manually.md
. PR #10279 by @xzmeng. - ๐ Add Chinese translation for
docs/zh/docs/deployment/https.md
. PR #10277 by @xzmeng. - ๐ Add Chinese translation for
docs/zh/docs/deployment/index.md
. PR #10275 by @xzmeng. - ๐ Add German translation for
docs/de/docs/tutorial/first-steps.md
. PR #9530 by @fhabers21. - ๐ Update Turkish translation for
docs/tr/docs/index.md
. PR #10444 by @hasansezertasan. - ๐ Add Chinese translation for
docs/zh/docs/learn/index.md
. PR #10479 by @KAZAMA-DREAM. - ๐ Add Russian translation for
docs/ru/docs/learn/index.md
. PR #10539 by @AlertRED. - ๐ Update SQLAlchemy instruction in Chinese translation
docs/zh/docs/tutorial/sql-databases.md
. PR #9712 by @Royc30ne. - ๐ Add Turkish translation for
docs/tr/docs/external-links.md
. PR #10549 by @hasansezertasan. - ๐ Add Spanish translation for
docs/es/docs/learn/index.md
. PR #10885 by @pablocm83. - ๐ Add Ukrainian translation for
docs/uk/docs/tutorial/body-fields.md
. PR #10670 by @ArtemKhymenko. - ๐ Add Hungarian translation for
/docs/hu/docs/index.md
. PR #10812 by @takacs. - ๐ Add Turkish translation for
docs/tr/docs/newsletter.md
. PR #10550 by @hasansezertasan. - ๐ Add Spanish translation for
docs/es/docs/help/index.md
. PR #10907 by @pablocm83. - ๐ Add Spanish translation for
docs/es/docs/about/index.md
. PR #10908 by @pablocm83. - ๐ Add Spanish translation for
docs/es/docs/resources/index.md
. PR #10909 by @pablocm83.
Internal¶
- ๐ท Upgrade custom GitHub Action comment-docs-preview-in-pr. PR #10916 by @tiangolo.
- โฌ๏ธ Upgrade GitHub Action latest-changes. PR #10915 by @tiangolo.
- ๐ท Upgrade GitHub Action label-approved. PR #10913 by @tiangolo.
- โฌ๏ธ Upgrade GitHub Action label-approved. PR #10905 by @tiangolo.
0.108.0¶
Upgrades¶
- โฌ๏ธ Upgrade Starlette to
>=0.29.0,<0.33.0
, update docs and usage of templates with new Starlette arguments. PR #10846 by @tiangolo.
0.107.0¶
Upgrades¶
Docs¶
- ๐ Add docs: Node.js script alternative to update OpenAPI for generated clients. PR #10845 by @alejsdev.
- ๐ Restructure Docs section in Contributing page. PR #10844 by @alejsdev.
0.106.0¶
Breaking Changes¶
Using resources from dependencies with yield
in background tasks is no longer supported.
This change is what supports the new features, read below. ๐ค
Dependencies with yield
, HTTPException
and Background Tasks¶
Dependencies with yield
now can raise HTTPException
and other exceptions after yield
. ๐
Read the new docs here: Dependencies with yield
and HTTPException
.
from fastapi import Depends, FastAPI, HTTPException
from typing_extensions import Annotated
app = FastAPI()
data = {
"plumbus": {"description": "Freshly pickled plumbus", "owner": "Morty"},
"portal-gun": {"description": "Gun to create portals", "owner": "Rick"},
}
class OwnerError(Exception):
pass
def get_username():
try:
yield "Rick"
except OwnerError as e:
raise HTTPException(status_code=400, detail=f"Owner error: {e}")
@app.get("/items/{item_id}")
def get_item(item_id: str, username: Annotated[str, Depends(get_username)]):
if item_id not in data:
raise HTTPException(status_code=404, detail="Item not found")
item = data[item_id]
if item["owner"] != username:
raise OwnerError(username)
return item
Before FastAPI 0.106.0, raising exceptions after yield
was not possible, the exit code in dependencies with yield
was executed after the response was sent, so Exception Handlers would 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 with yield
.
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 this diagram:
Time flows from top to bottom. And each column is one of the parts interacting or executing code.
sequenceDiagram
participant client as Client
participant handler as Exception handler
participant dep as Dep with yield
participant operation as Path Operation
participant tasks as Background tasks
Note over client,tasks: Can raise exception for dependency, handled after response is sent
Note over client,operation: Can raise HTTPException and can change the response
client ->> dep: Start request
Note over dep: Run code up to yield
opt raise
dep -->> handler: Raise HTTPException
handler -->> client: HTTP error response
dep -->> dep: Raise other exception
end
dep ->> operation: Run dependency, e.g. DB session
opt raise
operation -->> dep: Raise HTTPException
dep -->> handler: Auto forward exception
handler -->> client: HTTP error response
operation -->> dep: Raise other exception
dep -->> handler: Auto forward exception
end
operation ->> client: Return response to client
Note over client,operation: Response is already sent, can't change it anymore
opt Tasks
operation -->> tasks: Send background tasks
end
opt Raise other exception
tasks -->> dep: Raise other exception
end
Note over dep: After yield
opt Handle other exception
dep -->> dep: Handle exception, can't change response. E.g. close DB session.
end
The new execution flow can be found in the docs: Execution of dependencies with yield
.
Features¶
- โจ Add support for raising exceptions (including
HTTPException
) in dependencies withyield
in the exit code, do not support them in background tasks. PR #10831 by @tiangolo.
Internal¶
0.105.0¶
Features¶
- โจ Add support for multiple Annotated annotations, e.g.
Annotated[str, Field(), Query()]
. PR #10773 by @tiangolo.
Refactors¶
Docs¶
Internal¶
- ๐ง Update sponsors, add Scalar. PR #10728 by @tiangolo.
- ๐ง Update sponsors, add PropelAuth. PR #10760 by @tiangolo.
- ๐ท Update build docs, verify README on CI. PR #10750 by @tiangolo.
- ๐ง Update sponsors, remove Fern. PR #10729 by @tiangolo.
- ๐ง Update sponsors, add Codacy. PR #10677 by @tiangolo.
- ๐ง Update sponsors, add Reflex. PR #10676 by @tiangolo.
- ๐ Update release notes, move and check latest-changes. PR #10588 by @tiangolo.
- ๐ท Upgrade latest-changes GitHub Action. PR #10587 by @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 #10529 by @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 the Swagger UI side.
Docs¶
- ๐ Update data structure and render for external-links. PR #10495 by @tiangolo.
- โ๏ธ Fix link to SPDX license identifier in
docs/en/docs/tutorial/metadata.md
. PR #10433 by @worldworm. - ๐ Update example validation error from Pydantic v1 to match Pydantic v2 in
docs/en/docs/tutorial/path-params.md
. PR #10043 by @giuliowaitforitdavide. - โ๏ธ Fix typos in emoji docs and in some source examples. PR #10438 by @afuetterer.
- โ๏ธ Fix typo in
docs/en/docs/reference/dependencies.md
. PR #10465 by @suravshresth. - โ๏ธ Fix typos and rewordings in
docs/en/docs/tutorial/body-nested-models.md
. PR #10468 by @yogabonito. - ๐ Update docs, remove references to removed
pydantic.Required
indocs/en/docs/tutorial/query-params-str-validations.md
. PR #10469 by @yogabonito. - โ๏ธ Fix typo in
docs/en/docs/reference/index.md
. PR #10467 by @tarsil. - ๐ฅ Remove unnecessary duplicated docstrings. PR #10484 by @tiangolo.
Internal¶
- โ๏ธ Update Pydantic links to dotenv support. PR #10511 by @White-Mask.
- โ๏ธ Update links in
docs/en/docs/async.md
anddocs/zh/docs/async.md
to make them relative. PR #10498 by @hasnatsajid. - โ๏ธ Fix links in
docs/em/docs/async.md
. PR #10507 by @hasnatsajid. - โ๏ธ Fix typo in
docs/em/docs/index.md
, Python 3.8. PR #10521 by @kerriop. - โฌ Bump pillow from 9.5.0 to 10.1.0. PR #10446 by @dependabot[bot].
- โฌ Update mkdocs-material requirement from <9.0.0,>=8.1.4 to >=8.1.4,<10.0.0. PR #5862 by @dependabot[bot].
- โฌ Bump mkdocs-material from 9.1.21 to 9.4.7. PR #10545 by @dependabot[bot].
- ๐ท Install MkDocs Material Insiders only when secrets are available, for Dependabot. PR #10544 by @tiangolo.
- ๐ง Update sponsors badges, Databento. PR #10519 by @tiangolo.
- ๐ท Adopt Ruff format. PR #10517 by @tiangolo.
- ๐ง Add
CITATION.cff
file for academic citations. PR #10496 by @tiangolo. - ๐ Fix overriding MKDocs theme lang in hook. PR #10490 by @tiangolo.
- ๐ฅ Drop/close Gitter chat. Questions should go to GitHub Discussions, free conversations to Discord.. PR #10485 by @tiangolo.
0.104.0¶
Features¶
- โจ Add reference (code API) docs with PEP 727, add subclass with custom docstrings for
BackgroundTasks
, refactor docs structure. PR #10392 by @tiangolo. New docs at FastAPI Reference - Code API.
Upgrades¶
Internal¶
- โฌ Bump dawidd6/action-download-artifact from 2.27.0 to 2.28.0. PR #10268 by @dependabot[bot].
- โฌ Bump actions/checkout from 3 to 4. PR #10208 by @dependabot[bot].
- โฌ Bump pypa/gh-action-pypi-publish from 1.8.6 to 1.8.10. PR #10061 by @dependabot[bot].
- ๐ง Update sponsors, Bump.sh images. PR #10381 by @tiangolo.
- ๐ฅ Update FastAPI People. PR #10363 by @tiangolo.
0.103.2¶
Refactors¶
- โฌ๏ธ Upgrade compatibility with Pydantic v2.4, new renamed functions and JSON Schema input/output models with default values. PR #10344 by @tiangolo.
Translations¶
- ๐ Add Ukrainian translation for
docs/uk/docs/tutorial/extra-data-types.md
. PR #10132 by @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 #10154 by @s-rigaud. - ๐ Add Chinese translation for
docs/zh/docs/async.md
. PR #5591 by @mkdir700. - ๐ Update Chinese translation for
docs/tutorial/security/simple-oauth2.md
. PR #3844 by @jaystone776. - ๐ Add Korean translation for
docs/ko/docs/deployment/cloud.md
. PR #10191 by @Sion99. - ๐ Add Japanese translation for
docs/ja/docs/deployment/https.md
. PR #10298 by @tamtam-fitness. - ๐ Fix typo in Russian translation for
docs/ru/docs/tutorial/body-fields.md
. PR #10224 by @AlertRED. - ๐ Add Polish translation for
docs/pl/docs/help-fastapi.md
. PR #10121 by @romabozhanovgithub. - ๐ Add Russian translation for
docs/ru/docs/tutorial/header-params.md
. PR #10226 by @AlertRED. - ๐ Add Chinese translation for
docs/zh/docs/deployment/versions.md
. PR #10276 by @xzmeng.
Internal¶
- ๐ง Update sponsors, remove Flint. PR #10349 by @tiangolo.
- ๐ง Rename label "awaiting review" to "awaiting-review" to simplify search queries. PR #10343 by @tiangolo.
- ๐ง Update sponsors, enable Svix (revert #10228). PR #10253 by @tiangolo.
- ๐ง Update sponsors, remove Svix. PR #10228 by @tiangolo.
- ๐ง Update sponsors, add Bump.sh. PR #10227 by @tiangolo.
0.103.1¶
Fixes¶
- ๐ Pin AnyIO to < 4.0.0 to handle an incompatibility while upgrading to Starlette 0.31.1. PR #10194 by @tiangolo.
Docs¶
- โ๏ธ Fix validation parameter name in docs, from
regex
topattern
. PR #10085 by @pablodorrio. - โ๏ธ Fix indent format in
docs/en/docs/deployment/server-workers.md
. PR #10066 by @tamtam-fitness. - โ๏ธ Fix Pydantic examples in tutorial for Python types. PR #9961 by @rahulsalgare.
- โ๏ธ Fix link to Pydantic docs in
docs/en/docs/tutorial/extra-data-types.md
. PR #10155 by @hasnatsajid. - โ๏ธ Fix typo in
docs/en/docs/tutorial/handling-errors.md
. PR #10170 by @poupapaa. - โ๏ธ Fix typo in
docs/en/docs/tutorial/dependencies/dependencies-in-path-operation-decorators.md
. PR #10172 by @ragul-kachiappan.
Translations¶
- ๐ Remove duplicate line in translation for
docs/pt/docs/tutorial/path-params.md
. PR #10126 by @LecoOliveira. - ๐ Add Yoruba translation for
docs/yo/docs/index.md
. PR #10033 by @AfolabiOlaoluwa. - ๐ Add Ukrainian translation for
docs/uk/docs/python-types.md
. PR #10080 by @rostik1410. - ๐ Add Vietnamese translations for
docs/vi/docs/tutorial/first-steps.md
anddocs/vi/docs/tutorial/index.md
. PR #10088 by @magiskboy. - ๐ Add Ukrainian translation for
docs/uk/docs/alternatives.md
. PR #10060 by @whysage. - ๐ Add Ukrainian translation for
docs/uk/docs/tutorial/index.md
. PR #10079 by @rostik1410. - โ๏ธ Fix typos in
docs/en/docs/how-to/separate-openapi-schemas.md
anddocs/en/docs/tutorial/schema-extra-example.md
. PR #10189 by @xzmeng. - ๐ Add Chinese translation for
docs/zh/docs/advanced/generate-clients.md
. PR #9883 by @funny-cat-happy.
Refactors¶
- โ๏ธ Fix typos in comment in
fastapi/applications.py
. PR #10045 by @AhsanSheraz. - โ Add missing test for OpenAPI examples, it was missing in coverage. PR #10188 by @tiangolo.
Internal¶
0.103.0¶
Features¶
- โจ Add support for
openapi_examples
in all FastAPI parameters. PR #10152 by @tiangolo.- New docs: OpenAPI-specific examples.
Docs¶
- ๐ Add note to docs about Separate Input and Output Schemas with FastAPI version. PR #10150 by @tiangolo.
0.102.0¶
Features¶
- โจ Add support for disabling the separation of input and output JSON Schemas in OpenAPI with Pydantic v2 with
separate_input_output_schemas=False
. PR #10145 by @tiangolo.- New docs Separate OpenAPI Schemas for Input and Output or Not.
- This PR also includes a new setup (internal tools) for generating screenshots for the docs.
Refactors¶
Docs¶
- ๐ Add new docs section, How To - Recipes, move docs that don't have to be read by everyone to How To. PR #10114 by @tiangolo.
- ๐ Update Advanced docs, add links to sponsor courses. PR #10113 by @tiangolo.
- ๐ Update docs for generating clients. PR #10112 by @tiangolo.
- ๐ Tweak MkDocs and add redirects. PR #10111 by @tiangolo.
- ๐ Restructure docs for cloud providers, include links to sponsors. PR #10110 by @tiangolo.
Internal¶
0.101.1¶
Fixes¶
- โจ Add
ResponseValidationError
printable details, to show up in server error logs. PR #10078 by @tiangolo.
Refactors¶
- โ๏ธ Fix typo in deprecation warnings in
fastapi/params.py
. PR #9854 by @russbiggs. - โ๏ธ Fix typos in comments on internal code in
fastapi/concurrency.py
andfastapi/routing.py
. PR #9590 by @ElliottLarsen.
Docs¶
- โ๏ธ Fix typo in release notes. PR #9835 by @francisbergin.
- ๐ Add external article: Build an SMS Spam Classifier Serverless Database with FaunaDB and FastAPI. PR #9847 by @adejumoridwan.
- ๐ Fix typo in
docs/en/docs/contributing.md
. PR #9878 by @VicenteMerino. - ๐ Fix code highlighting in
docs/en/docs/tutorial/bigger-applications.md
. PR #9806 by @theonlykingpin.
Translations¶
- ๐ Add Japanese translation for
docs/ja/docs/deployment/concepts.md
. PR #10062 by @tamtam-fitness. - ๐ Add Japanese translation for
docs/ja/docs/deployment/server-workers.md
. PR #10064 by @tamtam-fitness. - ๐ Update Japanese translation for
docs/ja/docs/deployment/docker.md
. PR #10073 by @tamtam-fitness. - ๐ Add Ukrainian translation for
docs/uk/docs/fastapi-people.md
. PR #10059 by @rostik1410. - ๐ Add Ukrainian translation for
docs/uk/docs/tutorial/cookie-params.md
. PR #10032 by @rostik1410. - ๐ Add Russian translation for
docs/ru/docs/deployment/docker.md
. PR #9971 by @Xewus. - ๐ Add Vietnamese translation for
docs/vi/docs/python-types.md
. PR #10047 by @magiskboy. - ๐ Add Russian translation for
docs/ru/docs/tutorial/dependencies/global-dependencies.md
. PR #9970 by @dudyaosuplayer. - ๐ Add Urdu translation for
docs/ur/docs/benchmarks.md
. PR #9974 by @AhsanSheraz.
Internal¶
- ๐ง Add sponsor Porter. PR #10051 by @tiangolo.
- ๐ง Update sponsors, add Jina back as bronze sponsor. PR #10050 by @tiangolo.
- โฌ Bump mypy from 1.4.0 to 1.4.1. PR #9756 by @dependabot[bot].
- โฌ Bump mkdocs-material from 9.1.17 to 9.1.21. PR #9960 by @dependabot[bot].
0.101.0¶
Features¶
- โจ Enable Pydantic's serialization mode for responses, add support for Pydantic's
computed_field
, better OpenAPI for response models, proper required attributes, better generated clients. PR #10011 by @tiangolo.
Refactors¶
- โ Fix tests for compatibility with pydantic 2.1.1. PR #9943 by @dmontagu.
- โ
Fix test error in Windows for
jsonable_encoder
. PR #9840 by @iudeen.
Upgrades¶
Translations¶
- ๐ Add Russian translation for
docs/ru/docs/tutorial/security/index.md
. PR #9963 by @eVery1337. - ๐ Remove Vietnamese note about missing translation. PR #9957 by @tiangolo.
Internal¶
- ๐ท Add GitHub Actions step dump context to debug external failures. PR #10008 by @tiangolo.
- ๐ง Restore MkDocs Material pin after the fix. PR #10001 by @tiangolo.
- ๐ง Update the Question template to ask for the Pydantic version. PR #10000 by @tiangolo.
- ๐ Update MkDocs Material dependencies. PR #9986 by @tiangolo.
- ๐ฅ Update FastAPI People. PR #9999 by @tiangolo.
- ๐ณ Update Dockerfile with compatibility versions, to upgrade later. PR #9998 by @tiangolo.
- โ Add pydantic-settings to FastAPI People dependencies. PR #9988 by @tiangolo.
- โป๏ธ Update FastAPI People logic with new Pydantic. PR #9985 by @tiangolo.
- ๐ฑ Update sponsors, Fern badge. PR #9982 by @tiangolo.
- ๐ท Deploy docs to Cloudflare Pages. PR #9978 by @tiangolo.
- ๐ง Update sponsor Fern. PR #9979 by @tiangolo.
- ๐ท Update CI debug mode with Tmate. PR #9977 by @tiangolo.
0.100.1¶
Fixes¶
- ๐ Replace
MultHostUrl
toAnyUrl
for compatibility with older versions of Pydantic v1. PR #9852 by @Kludex.
Docs¶
Translations¶
- ๐ Add Ukrainian translation for
docs/uk/docs/tutorial/body.md
. PR #4574 by @ss-o-furda. - ๐ Add Vietnamese translation for
docs/vi/docs/features.md
anddocs/vi/docs/index.md
. PR #3006 by @magiskboy. - ๐ Add Korean translation for
docs/ko/docs/async.md
. PR #4179 by @NinaHwang. - ๐ Add Chinese translation for
docs/zh/docs/tutorial/background-tasks.md
. PR #9812 by @wdh99. - ๐ Add French translation for
docs/fr/docs/tutorial/query-params-str-validations.md
. PR #4075 by @Smlep. - ๐ Add French translation for
docs/fr/docs/tutorial/index.md
. PR #2234 by @JulianMaurin. - ๐ Add French translation for
docs/fr/docs/contributing.md
. PR #2132 by @JulianMaurin. - ๐ Add French translation for
docs/fr/docs/benchmarks.md
. PR #2155 by @clemsau. - ๐ Update Chinese translations with new source files. PR #9738 by @mahone3297.
- ๐ Add Russian translation for
docs/ru/docs/tutorial/request-forms.md
. PR #9841 by @dedkot01. - ๐ Update Chinese translation for
docs/zh/docs/tutorial/handling-errors.md
. PR #9485 by @Creat55.
Internal¶
- ๐ง Update sponsors, add Fern. PR #9956 by @tiangolo.
- ๐ท Update FastAPI People token. PR #9844 by @tiangolo.
- ๐ฅ Update FastAPI People. PR #9775 by @tiangolo.
- ๐ท Update MkDocs Material token. PR #9843 by @tiangolo.
- ๐ท Update token for latest changes. PR #9842 by @tiangolo.
0.100.0¶
โจ Support for Pydantic v2 โจ
Pydantic version 2 has the core re-written in Rust and includes a lot of improvements and features, for example:
- Improved correctness in corner cases.
- Safer types.
- Better performance and less energy consumption.
- Better extensibility.
- etc.
...all this while keeping the same Python API. In most of the cases, for simple models, you can simply upgrade the Pydantic version and get all the benefits. ๐
In some cases, for pure data validation and processing, you can get performance improvements of 20x or more. This means 2,000% or more. ๐คฏ
When you use FastAPI, there's a lot more going on, processing the request and response, handling dependencies, executing your own code, and particularly, waiting for the network. But you will probably still get some nice performance improvements just from the upgrade.
The focus of this release is compatibility with Pydantic v1 and v2, to make sure your current apps keep working. Later there will be more focus on refactors, correctness, code improvements, and then performance improvements. Some third-party early beta testers that ran benchmarks on the beta releases of FastAPI reported improvements of 2x - 3x. Which is not bad for just doing pip install --upgrade fastapi pydantic
. This was not an official benchmark and I didn't check it myself, but it's a good sign.
Migration¶
Check out the Pydantic migration guide.
For the things that need changes in your Pydantic models, the Pydantic team built bump-pydantic
.
A command line tool that will process your code and update most of the things automatically for you. Make sure you have your code in git first, and review each of the changes to make sure everything is correct before committing the changes.
Pydantic v1¶
This version of FastAPI still supports Pydantic v1. And although Pydantic v1 will be deprecated at some point, it will still be supported for a while.
This means that you can install the new Pydantic v2, and if something fails, you can install Pydantic v1 while you fix any problems you might have, but having the latest FastAPI.
There are tests for both Pydantic v1 and v2, and test coverage is kept at 100%.
Changes¶
-
There are new parameter fields supported by Pydantic
Field()
for:Path()
Query()
Header()
Cookie()
Body()
Form()
File()
-
The new parameter fields are:
default_factory
alias_priority
validation_alias
serialization_alias
discriminator
strict
multiple_of
allow_inf_nan
max_digits
decimal_places
json_schema_extra
...you can read about them in the Pydantic docs.
- The parameter
regex
has been deprecated and replaced bypattern
.- You can read more about it in the docs for Query Parameters and String Validations: Add regular expressions.
- New Pydantic models use an improved and simplified attribute
model_config
that takes a simple dict instead of an internal classConfig
for their configuration.- You can read more about it in the docs for Declare Request Example Data.
- The attribute
schema_extra
for the internal classConfig
has been replaced by the keyjson_schema_extra
in the newmodel_config
dict.- You can read more about it in the docs for Declare Request Example Data.
- When you install
"fastapi[all]"
it now also includes:pydantic-settings
- for settings management.pydantic-extra-types
- for extra types to be used with Pydantic.
-
Now Pydantic Settings is an additional optional package (included in
"fastapi[all]"
). To use settings you should now importfrom pydantic_settings import BaseSettings
instead of importing frompydantic
directly.- You can read more about it in the docs for Settings and Environment Variables.
-
PR #9816 by @tiangolo, included all the work done (in multiple PRs) on the beta branch (
main-pv2
).
0.99.1¶
Fixes¶
- ๐ Fix JSON Schema accepting bools as valid JSON Schemas, e.g.
additionalProperties: false
. PR #9781 by @tiangolo.
Docs¶
0.99.0¶
Features¶
-
โจ Add support for OpenAPI 3.1.0. PR #9770 by @tiangolo.
- New support for documenting webhooks, read the new docs here: Advanced User Guide: OpenAPI Webhooks.
- Upgrade OpenAPI 3.1.0, this uses JSON Schema 2020-12.
- Upgrade Swagger UI to version 5.x.x, that supports OpenAPI 3.1.0.
- Updated
examples
field inQuery()
,Cookie()
,Body()
, etc. based on the latest JSON Schema and OpenAPI. Now it takes a list of examples and they are included directly in the JSON Schema, not outside. Read more about it (including the historical technical details) in the updated docs: Tutorial: Declare Request Example Data.
-
โจ Add support for
deque
objects and children injsonable_encoder
. PR #9433 by @cranium.
Docs¶
Translations¶
- ๐ Add Persian translation for
docs/fa/docs/advanced/sub-applications.md
. PR #9692 by @mojtabapaso. - ๐ Add Russian translation for
docs/ru/docs/tutorial/response-model.md
. PR #9675 by @glsglsgls.
Internal¶
- ๐จ Enable linenums in MkDocs Material during local live development to simplify highlighting code. PR #9769 by @tiangolo.
- โฌ Update httpx requirement from <0.24.0,>=0.23.0 to >=0.23.0,<0.25.0. PR #9724 by @dependabot[bot].
- โฌ Bump mkdocs-material from 9.1.16 to 9.1.17. PR #9746 by @dependabot[bot].
- ๐ฅ Remove missing translation dummy pages, no longer necessary. PR #9751 by @tiangolo.
- โฌ [pre-commit.ci] pre-commit autoupdate. PR #9259 by @pre-commit-ci[bot].
- โจ Add Material for MkDocs Insiders features and cards. PR #9748 by @tiangolo.
- ๐ฅ Remove languages without translations. PR #9743 by @tiangolo.
- โจ Refactor docs for building scripts, use MkDocs hooks, simplify (remove) configs for languages. PR #9742 by @tiangolo.
- ๐จ Add MkDocs hook that renames sections based on the first index file. PR #9737 by @tiangolo.
- ๐ท Make cron jobs run only on main repo, not on forks, to avoid error notifications from missing tokens. PR #9735 by @tiangolo.
- ๐ง Update MkDocs for other languages. PR #9734 by @tiangolo.
- ๐ท Refactor Docs CI, run in multiple workers with a dynamic matrix to optimize speed. PR #9732 by @tiangolo.
- ๐ฅ Remove old internal GitHub Action watch-previews that is no longer needed. PR #9730 by @tiangolo.
- โฌ๏ธ Upgrade MkDocs and MkDocs Material. PR #9729 by @tiangolo.
- ๐ท Build and deploy docs only on docs changes. PR #9728 by @tiangolo.
0.98.0¶
Features¶
Docs¶
- ๐ Update docs on Pydantic using ujson internally. PR #5804 by @mvasilkov.
- โ Rewording in
docs/en/docs/tutorial/debugging.md
. PR #9581 by @ivan-abc. - ๐ Add german blog post (Domain-driven Design mit Python und FastAPI). PR #9261 by @msander.
- โ๏ธ Tweak wording in
docs/en/docs/tutorial/security/index.md
. PR #9561 by @jyothish-mohan. - ๐ Update
Annotated
notes indocs/en/docs/tutorial/schema-extra-example.md
. PR #9620 by @Alexandrhub. - โ๏ธ Fix typo
Annotation
->Annotated
indocs/en/docs/tutorial/query-params-str-validations.md
. PR #9625 by @mccricardo. - ๐ Use in memory database for testing SQL in docs. PR #1223 by @HarshaLaxman.
Translations¶
- ๐ Add Russian translation for
docs/ru/docs/tutorial/metadata.md
. PR #9681 by @TabarakoAkula. - ๐ Fix typo in Spanish translation for
docs/es/docs/tutorial/first-steps.md
. PR #9571 by @lilidl-nft. - ๐ Add Russian translation for
docs/tutorial/path-operation-configuration.md
. PR #9696 by @TabarakoAkula. - ๐ Add Chinese translation for
docs/zh/docs/advanced/security/index.md
. PR #9666 by @lordqyxz. - ๐ Add Chinese translations for
docs/zh/docs/advanced/settings.md
. PR #9652 by @ChoyeonChern. - ๐ Add Chinese translations for
docs/zh/docs/advanced/websockets.md
. PR #9651 by @ChoyeonChern. - ๐ Add Chinese translation for
docs/zh/docs/tutorial/testing.md
. PR #9641 by @wdh99. - ๐ Add Russian translation for
docs/tutorial/extra-models.md
. PR #9619 by @ivan-abc. - ๐ Add Russian translation for
docs/tutorial/cors.md
. PR #9608 by @ivan-abc. - ๐ Add Polish translation for
docs/pl/docs/features.md
. PR #5348 by @mbroton. - ๐ Add Russian translation for
docs/ru/docs/tutorial/body-nested-models.md
. PR #9605 by @Alexandrhub.
Internal¶
- โฌ Bump ruff from 0.0.272 to 0.0.275. PR #9721 by @dependabot[bot].
- โฌ Update uvicorn[standard] requirement from <0.21.0,>=0.12.0 to >=0.12.0,<0.23.0. PR #9463 by @dependabot[bot].
- โฌ Bump mypy from 1.3.0 to 1.4.0. PR #9719 by @dependabot[bot].
- โฌ Update pre-commit requirement from <3.0.0,>=2.17.0 to >=2.17.0,<4.0.0. PR #9251 by @dependabot[bot].
- โฌ Bump pypa/gh-action-pypi-publish from 1.8.5 to 1.8.6. PR #9482 by @dependabot[bot].
- โ๏ธ Fix tooltips for light/dark theme toggler in docs. PR #9588 by @pankaj1707k.
- ๐ง Set minimal hatchling version needed to build the package. PR #9240 by @mgorny.
- ๐ Add repo link to PyPI. PR #9559 by @JacobCoffee.
- โ๏ธ Fix typos in data for tests. PR #4958 by @ryanrussell.
- ๐ง Update sponsors, add Flint. PR #9699 by @tiangolo.
- ๐ท Lint in CI only once, only with one version of Python, run tests with all of them. PR #9686 by @tiangolo.
0.97.0¶
Features¶
- โจ Add support for
dependencies
in WebSocket routes. PR #4534 by @paulo-raca. - โจ Add exception handler for
WebSocketRequestValidationError
(which also allows to override it). PR #6030 by @kristjanvalur.
Refactors¶
- โฌ๏ธ Upgrade and fully migrate to Ruff, remove isort, includes a couple of tweaks suggested by the new version of Ruff. PR #9660 by @tiangolo.
- โป๏ธ Update internal type annotations and upgrade mypy. PR #9658 by @tiangolo.
- โป๏ธ Simplify
AsyncExitStackMiddleware
as without Python 3.6AsyncExitStack
is always available. PR #9657 by @tiangolo.
Upgrades¶
Internal¶
- ๐ Update CI cache to fix installs when dependencies change. PR #9659 by @tiangolo.
- โฌ๏ธ Separate requirements for development into their own requirements.txt files, they shouldn't be extras. PR #9655 by @tiangolo.
0.96.1¶
Fixes¶
- ๐ Fix
HTTPException
header type annotations. PR #9648 by @tiangolo. - ๐ Fix OpenAPI model fields int validations,
gte
toge
. PR #9635 by @tiangolo.
Upgrades¶
- ๐ Update minimum version of Pydantic to >=1.7.4. This fixes an issue when trying to use an old version of Pydantic. PR #9567 by @Kludex.
Refactors¶
- โป Remove
media_type
fromORJSONResponse
as it's inherited from the parent class. PR #5805 by @Kludex. - โป Instantiate
HTTPException
only when needed, optimization refactor. PR #5356 by @pawamoy.
Docs¶
Translations¶
- ๐ Fix spelling in Indonesian translation of
docs/id/docs/tutorial/index.md
. PR #5635 by @purwowd. - ๐ Add Russian translation for
docs/ru/docs/tutorial/index.md
. PR #5896 by @Wilidon. - ๐ Add Chinese translations for
docs/zh/docs/advanced/response-change-status-code.md
anddocs/zh/docs/advanced/response-headers.md
. PR #9544 by @ChoyeonChern. - ๐ Add Russian translation for
docs/ru/docs/tutorial/schema-extra-example.md
. PR #9621 by @Alexandrhub.
Internal¶
- ๐ง Add sponsor Platform.sh. PR #9650 by @tiangolo.
- ๐ท Add custom token to Smokeshow and Preview Docs for download-artifact, to prevent API rate limits. PR #9646 by @tiangolo.
- ๐ท Add custom tokens for GitHub Actions to avoid rate limits. PR #9647 by @tiangolo.
0.96.0¶
Features¶
- โก Update
create_cloned_field
to use a global cache and improve startup performance. PR #4645 by @madkinsz and previous original PR by @huonw.
Docs¶
- ๐ Update Deta deployment tutorial for compatibility with Deta Space. PR #6004 by @mikBighne98.
- โ๏ธ Fix typo in Deta deployment tutorial. PR #9501 by @lemonyte.
Translations¶
- ๐ Add Russian translation for
docs/tutorial/body.md
. PR #3885 by @solomein-sv. - ๐ Add Russian translation for
docs/ru/docs/tutorial/static-files.md
. PR #9580 by @Alexandrhub. - ๐ Add Russian translation for
docs/ru/docs/tutorial/query-params.md
. PR #9584 by @Alexandrhub. - ๐ Add Russian translation for
docs/ru/docs/tutorial/first-steps.md
. PR #9471 by @AGolicyn. - ๐ Add Russian translation for
docs/ru/docs/tutorial/debugging.md
. PR #9579 by @Alexandrhub. - ๐ Add Russian translation for
docs/ru/docs/tutorial/path-params.md
. PR #9519 by @AGolicyn. - ๐ Add Chinese translation for
docs/zh/docs/tutorial/static-files.md
. PR #9436 by @wdh99. - ๐ Update Spanish translation including new illustrations in
docs/es/docs/async.md
. PR #9483 by @andresbermeoq. - ๐ Add Russian translation for
docs/ru/docs/tutorial/path-params-numeric-validations.md
. PR #9563 by @ivan-abc. - ๐ Add Russian translation for
docs/ru/docs/deployment/concepts.md
. PR #9577 by @Xewus. - ๐ Add Russian translation for
docs/ru/docs/tutorial/body-multiple-params.md
. PR #9586 by @Alexandrhub.
Internal¶
- ๐ฅ Update FastAPI People. PR #9602 by @github-actions[bot].
- ๐ง Update sponsors, remove InvestSuite. PR #9612 by @tiangolo.
0.95.2¶
- โฌ๏ธ Upgrade Starlette version to
>=0.27.0
for a security release. PR #9541 by @tiangolo. Details on Starlette's security advisory.
Translations¶
- ๐ Add Portuguese translation for
docs/pt/docs/advanced/events.md
. PR #9326 by @oandersonmagalhaes. - ๐ Add Russian translation for
docs/ru/docs/deployment/manually.md
. PR #9417 by @Xewus. - ๐ Add setup for translations to Lao. PR #9396 by @TheBrown.
- ๐ Add Russian translation for
docs/ru/docs/tutorial/testing.md
. PR #9403 by @Xewus. - ๐ Add Russian translation for
docs/ru/docs/deployment/https.md
. PR #9428 by @Xewus. - โ Fix command to install requirements in Windows. PR #9445 by @MariiaRomanuik.
- ๐ Add French translation for
docs/fr/docs/advanced/response-directly.md
. PR #9415 by @axel584. - ๐ Initiate Czech translation setup. PR #9288 by @3p1463k.
- โ Fix typo in Portuguese docs for
docs/pt/docs/index.md
. PR #9337 by @lucasbalieiro. - ๐ Add Russian translation for
docs/ru/docs/tutorial/response-status-code.md
. PR #9370 by @nadia3373.
Internal¶
- ๐ Fix
flask.escape
warning for internal tests. PR #9468 by @samuelcolvin. - โ Refactor 2 tests, for consistency and simplification. PR #9504 by @tiangolo.
- โ Refactor OpenAPI tests, prepare for Pydantic v2. PR #9503 by @tiangolo.
- โฌ Bump dawidd6/action-download-artifact from 2.26.0 to 2.27.0. PR #9394 by @dependabot[bot].
- ๐ Disable setup-python pip cache in CI. PR #9438 by @tiangolo.
- โฌ Bump pypa/gh-action-pypi-publish from 1.6.4 to 1.8.5. PR #9346 by @dependabot[bot].
0.95.1¶
Fixes¶
- ๐ Fix using
Annotated
in routers or path operations decorated multiple times. PR #9315 by @sharonyogev.
Docs¶
- ๐ ๐ ๐ ๐ข Translate docs to Emoji ๐ฅณ ๐ ๐ฅ ๐คฏ ๐คฏ. PR #5385 by @LeeeeT.
- ๐ Add notification message warning about old versions of FastAPI not supporting
Annotated
. PR #9298 by @grdworkin. - ๐ Fix typo in
docs/en/docs/advanced/behind-a-proxy.md
. PR #5681 by @Leommjr. - โ Fix wrong import from typing module in Persian translations for
docs/fa/docs/index.md
. PR #6083 by @Kimiaattaei. - โ๏ธ Fix format, remove unnecessary asterisks in
docs/en/docs/help-fastapi.md
. PR #9249 by @armgabrielyan. - โ Fix typo in
docs/en/docs/tutorial/query-params-str-validations.md
. PR #9272 by @nicornk. - โ Fix typo/bug in inline code example in
docs/en/docs/tutorial/query-params-str-validations.md
. PR #9273 by @tim-habitat. - โ Fix typo in
docs/en/docs/tutorial/path-params-numeric-validations.md
. PR #9282 by @aadarsh977. - โ Fix typo: 'wll' to 'will' in
docs/en/docs/tutorial/query-params-str-validations.md
. PR #9380 by @dasstyxx.
Translations¶
- ๐ Add French translation for
docs/fr/docs/advanced/index.md
. PR #5673 by @axel584. - ๐ Add Portuguese translation for
docs/pt/docs/tutorial/body-nested-models.md
. PR #4053 by @luccasmmg. - ๐ Add Russian translation for
docs/ru/docs/alternatives.md
. PR #5994 by @Xewus. - ๐ Add Portuguese translation for
docs/pt/docs/tutorial/extra-models.md
. PR #5912 by @LorhanSohaky. - ๐ Add Portuguese translation for
docs/pt/docs/tutorial/path-operation-configuration.md
. PR #5936 by @LorhanSohaky. - ๐ Add Russian translation for
docs/ru/docs/contributing.md
. PR #6002 by @stigsanek. - ๐ Add Korean translation for
docs/tutorial/dependencies/classes-as-dependencies.md
. PR #9176 by @sehwan505. - ๐ Add Russian translation for
docs/ru/docs/project-generation.md
. PR #9243 by @Xewus. - ๐ Add French translation for
docs/fr/docs/index.md
. PR #9265 by @frabc. - ๐ Add Russian translation for
docs/ru/docs/tutorial/query-params-str-validations.md
. PR #9267 by @dedkot01. - ๐ Add Russian translation for
docs/ru/docs/benchmarks.md
. PR #9271 by @Xewus.
Internal¶
- ๐ง Update sponsors: remove Jina. PR #9388 by @tiangolo.
- ๐ง Update sponsors, add databento, remove Ines's course and StriveWorks. PR #9351 by @tiangolo.
0.95.0¶
Highlights¶
This release adds support for dependencies and parameters using Annotated
and recommends its usage. โจ
This has several benefits, one of the main ones is that now the parameters of your functions with Annotated
would not be affected at all.
If you call those functions in other places in your code, the actual default values will be kept, your editor will help you notice missing required arguments, Python will require you to pass required arguments at runtime, you will be able to use the same functions for different things and with different libraries (e.g. Typer will soon support Annotated
too, then you could use the same function for an API and a CLI), etc.
Because Annotated
is standard Python, you still get all the benefits from editors and tools, like autocompletion, inline errors, etc.
One of the biggest benefits is that now you can create Annotated
dependencies that are then shared by multiple path operation functions, this will allow you to reduce a lot of code duplication in your codebase, while keeping all the support from editors and tools.
For example, you could have code like this:
def get_current_user(token: str):
# authenticate user
return User()
@app.get("/items/")
def read_items(user: User = Depends(get_current_user)):
...
@app.post("/items/")
def create_item(*, user: User = Depends(get_current_user), item: Item):
...
@app.get("/items/{item_id}")
def read_item(*, user: User = Depends(get_current_user), item_id: int):
...
@app.delete("/items/{item_id}")
def delete_item(*, user: User = Depends(get_current_user), item_id: int):
...
There's a bit of code duplication for the dependency:
user: User = Depends(get_current_user)
...the bigger the codebase, the more noticeable it is.
Now you can create an annotated dependency once, like this:
CurrentUser = Annotated[User, Depends(get_current_user)]
And then you can reuse this Annotated
dependency:
CurrentUser = Annotated[User, Depends(get_current_user)]
@app.get("/items/")
def read_items(user: CurrentUser):
...
@app.post("/items/")
def create_item(user: CurrentUser, item: Item):
...
@app.get("/items/{item_id}")
def read_item(user: CurrentUser, item_id: int):
...
@app.delete("/items/{item_id}")
def delete_item(user: CurrentUser, item_id: int):
...
...and CurrentUser
has all the typing information as User
, so your editor will work as expected (autocompletion and everything), and FastAPI will be able to understand the dependency defined in Annotated
. ๐
Roughly all the docs have been rewritten to use Annotated
as the main way to declare parameters and dependencies. All the examples in the docs now include a version with Annotated
and a version without it, for each of the specific Python versions (when there are small differences/improvements in more recent versions). There were around 23K new lines added between docs, examples, and tests. ๐
The key updated docs are:
- Python Types Intro:
- Tutorial:
Special thanks to @nzig for the core implementation and to @adriangb for the inspiration and idea with Xpresso! ๐
Features¶
Docs¶
- ๐ Tweak tip recommending
Annotated
in docs. PR #9270 by @tiangolo. - ๐ Update order of examples, latest Python version first, and simplify version tab names. PR #9269 by @tiangolo.
- ๐ Update all docs to use
Annotated
as the main recommendation, with new examples and tests. PR #9268 by @tiangolo.
0.94.1¶
Fixes¶
0.94.0¶
Upgrades¶
- โฌ Upgrade python-multipart to support 0.0.6. PR #9212 by @musicinmybrain.
- โฌ๏ธ Upgrade Starlette version, support new
lifespan
with state. PR #9239 by @tiangolo.
Docs¶
Translations¶
Internal¶
- โ Add
pydantic
to PyPI classifiers. PR #5914 by @yezz123. - โฌ Bump black from 22.10.0 to 23.1.0. PR #5953 by @dependabot[bot].
- โฌ Bump types-ujson from 5.6.0.0 to 5.7.0.1. PR #6027 by @dependabot[bot].
- โฌ Bump dawidd6/action-download-artifact from 2.24.3 to 2.26.0. PR #6034 by @dependabot[bot].
- โฌ [pre-commit.ci] pre-commit autoupdate. PR #5709 by @pre-commit-ci[bot].
0.93.0¶
Features¶
- โจ Add support for
lifespan
async context managers (supersedingstartup
andshutdown
events). Initial PR #2944 by @uSpike.
Now, instead of using independent startup
and shutdown
events, you can define that logic in a single function with yield
decorated with @asynccontextmanager
(an async context manager).
For example:
from contextlib import asynccontextmanager
from fastapi import FastAPI
def fake_answer_to_everything_ml_model(x: float):
return x * 42
ml_models = {}
@asynccontextmanager
async def lifespan(app: FastAPI):
# Load the ML model
ml_models["answer_to_everything"] = fake_answer_to_everything_ml_model
yield
# Clean up the ML models and release the resources
ml_models.clear()
app = FastAPI(lifespan=lifespan)
@app.get("/predict")
async def predict(x: float):
result = ml_models["answer_to_everything"](x)
return {"result": result}
Note: This is the recommended way going forward, instead of using startup
and shutdown
events.
Read more about it in the new docs: Advanced User Guide: Lifespan Events.
Docs¶
Translations¶
- ๐ Tamil translations - initial setup. PR #5564 by @gusty1g.
- ๐ Add French translation for
docs/fr/docs/advanced/path-operation-advanced-configuration.md
. PR #9221 by @axel584. - ๐ Add French translation for
docs/tutorial/debugging.md
. PR #9175 by @frabc. - ๐ Initiate Armenian translation setup. PR #5844 by @har8.
- ๐ Add French translation for
deployment/manually.md
. PR #3693 by @rjNemo.
Internal¶
- ๐ท Update translation bot messages. PR #9206 by @tiangolo.
- ๐ท Update translations bot to use Discussions, and notify when a PR is done. PR #9183 by @tiangolo.
- ๐ง Update sponsors-badges. PR #9182 by @tiangolo.
- ๐ฅ Update FastAPI People. PR #9181 by @github-actions[bot].
- ๐ Log GraphQL errors in FastAPI People, because it returns 200, with a payload with an error. PR #9171 by @tiangolo.
- ๐ Fix/workaround GitHub Actions in Docker with git for FastAPI People. PR #9169 by @tiangolo.
- โป๏ธ Refactor FastAPI Experts to use only discussions now that questions are migrated. PR #9165 by @tiangolo.
- โฌ๏ธ Upgrade analytics. PR #6025 by @tiangolo.
- โฌ๏ธ Upgrade and re-enable installing Typer-CLI. PR #6008 by @tiangolo.
0.92.0¶
๐จ This is a security fix. Please upgrade as soon as possible.
Upgrades¶
- โฌ๏ธ Upgrade Starlette to 0.25.0. PR #5996 by @tiangolo.
- This solves a vulnerability that could allow denial of service attacks by using many small multipart fields/files (parts), consuming high CPU and memory.
- Only applications using forms (e.g. file uploads) could be affected.
- For most cases, upgrading won't have any breaking changes.
0.91.0¶
Upgrades¶
- โฌ๏ธ Upgrade Starlette version to
0.24.0
and refactor internals for compatibility. PR #5985 by @tiangolo.- This can solve nuanced errors when using middlewares. Before Starlette
0.24.0
, a new instance of each middleware class would be created when a new middleware was added. That normally was not a problem, unless the middleware class expected to be created only once, with only one instance, that happened in some cases. This upgrade would solve those cases (thanks @adriangb! Starlette PR #2017). Now the middleware class instances are created once, right before the first request (the first time the app is called). - If you depended on that previous behavior, you might need to update your code. As always, make sure your tests pass before merging the upgrade.
- This can solve nuanced errors when using middlewares. Before Starlette
0.90.1¶
Upgrades¶
Docs¶
- โ Tweak wording to clarify
docs/en/docs/project-generation.md
. PR #5930 by @chandra-deb. - โ Update Pydantic GitHub URLs. PR #5952 by @yezz123.
- ๐ Add opinion from Cisco. PR #5981 by @tiangolo.
Translations¶
Internal¶
- โ Update
zip-docs.sh
internal script, remove extra space. PR #5931 by @JuanPerdomo00.
0.90.0¶
Upgrades¶
Docs¶
- ๐ Add article "Tortoise ORM / FastAPI ๆดๅๅฟซ้็ญ่จ" to External Links. PR #5496 by @Leon0824.
- ๐ฅ Update FastAPI People. PR #5954 by @github-actions[bot].
- ๐ Micro-tweak help docs. PR #5960 by @tiangolo.
- ๐ง Update new issue chooser to direct to GitHub Discussions. PR #5948 by @tiangolo.
- ๐ Recommend GitHub Discussions for questions. PR #5944 by @tiangolo.
Translations¶
- ๐ Add Russian translation for
docs/ru/docs/tutorial/body-fields.md
. PR #5898 by @simatheone. - ๐ Add Russian translation for
docs/ru/docs/help-fastapi.md
. PR #5970 by @tiangolo. - ๐ Add Portuguese translation for
docs/pt/docs/tutorial/static-files.md
. PR #5858 by @batlopes. - ๐ Add Portuguese translation for
docs/pt/docs/tutorial/encoder.md
. PR #5525 by @felipebpl. - ๐ Add Russian translation for
docs/ru/docs/contributing.md
. PR #5870 by @Xewus.
Internal¶
- โฌ๏ธ Upgrade Ubuntu version for docs workflow. PR #5971 by @tiangolo.
- ๐ง Update sponsors badges. PR #5943 by @tiangolo.
- โจ Compute FastAPI Experts including GitHub Discussions. PR #5941 by @tiangolo.
- โฌ๏ธ Upgrade isort and update pre-commit. PR #5940 by @tiangolo.
- ๐ง Add template for questions in Discussions. PR #5920 by @tiangolo.
- ๐ง Update Sponsor Budget Insight to Powens. PR #5916 by @tiangolo.
- ๐ง Update GitHub Sponsors badge data. PR #5915 by @tiangolo.
0.89.1¶
Fixes¶
- ๐ Ignore Response classes on return annotation. PR #5855 by @Kludex. See the new docs in the PR below.
Docs¶
- ๐ Update docs and examples for Response Model with Return Type Annotations, and update runtime error. PR #5873 by @tiangolo. New docs at Response Model - Return Type: Other Return Type Annotations.
- ๐ Add External Link: FastAPI lambda container: serverless simplified. PR #5784 by @rafrasenberg.
Translations¶
- ๐ Add Turkish translation for
docs/tr/docs/tutorial/first_steps.md
. PR #5691 by @Kadermiyanyedi.
0.89.0¶
Features¶
- โจ Add support for function return type annotations to declare the
response_model
. Initial PR #1436 by @uriyyo.
Now you can declare the return type / response_model
in the function return type annotation:
from fastapi import FastAPI
from pydantic import BaseModel
app = FastAPI()
class Item(BaseModel):
name: str
price: float
@app.get("/items/")
async def read_items() -> list[Item]:
return [
Item(name="Portal Gun", price=42.0),
Item(name="Plumbus", price=32.0),
]
FastAPI will use the return type annotation to perform:
- Data validation
- Automatic documentation
- It could power automatic client generators
- Data filtering
Before this version it was only supported via the response_model
parameter.
Read more about it in the new docs: Response Model - Return Type.
Docs¶
- ๐ Add External Link: Authorization on FastAPI with Casbin. PR #5712 by @Xhy-5000.
- โ Fix typo in
docs/en/docs/async.md
. PR #5785 by @Kingdageek. - โ Fix typo in
docs/en/docs/deployment/concepts.md
. PR #5824 by @kelbyfaessler.
Translations¶
- ๐ Add Russian translation for
docs/ru/docs/fastapi-people.md
. PR #5577 by @Xewus. - ๐ Fix typo in Chinese translation for
docs/zh/docs/benchmarks.md
. PR #4269 by @15027668g. - ๐ Add Korean translation for
docs/tutorial/cors.md
. PR #3764 by @NinaHwang.
Internal¶
- โฌ Update coverage[toml] requirement from <7.0,>=6.5.0 to >=6.5.0,<8.0. PR #5801 by @dependabot[bot].
- โฌ Update uvicorn[standard] requirement from <0.19.0,>=0.12.0 to >=0.12.0,<0.21.0 for development. PR #5795 by @dependabot[bot].
- โฌ Bump dawidd6/action-download-artifact from 2.24.2 to 2.24.3. PR #5842 by @dependabot[bot].
- ๐ฅ Update FastAPI People. PR #5825 by @github-actions[bot].
- โฌ Bump types-ujson from 5.5.0 to 5.6.0.0. PR #5735 by @dependabot[bot].
- โฌ Bump pypa/gh-action-pypi-publish from 1.5.2 to 1.6.4. PR #5750 by @dependabot[bot].
- ๐ท Add GitHub Action gate/check. PR #5492 by @webknjaz.
- ๐ง Update sponsors, add Svix. PR #5848 by @tiangolo.
- ๐ง Remove Doist sponsor. PR #5847 by @tiangolo.
- โฌ Update sqlalchemy requirement from <=1.4.41,>=1.3.18 to >=1.3.18,<1.4.43. PR #5540 by @dependabot[bot].
- โฌ Bump nwtgck/actions-netlify from 1.2.4 to 2.0.0. PR #5757 by @dependabot[bot].
- ๐ท Refactor CI artifact upload/download for docs previews. PR #5793 by @tiangolo.
- โฌ Bump pypa/gh-action-pypi-publish from 1.5.1 to 1.5.2. PR #5714 by @dependabot[bot].
- ๐ฅ Update FastAPI People. PR #5722 by @github-actions[bot].
- ๐ง Update sponsors, disable course bundle. PR #5713 by @tiangolo.
- โฌ Update typer[all] requirement from <0.7.0,>=0.6.1 to >=0.6.1,<0.8.0. PR #5639 by @dependabot[bot].
0.88.0¶
Upgrades¶
- โฌ Bump Starlette to version
0.22.0
to fix bad encoding for query parameters in newTestClient
. PR #5659 by @azogue.
Docs¶
- โ๏ธ Fix typo in docs for
docs/en/docs/advanced/middleware.md
. PR #5376 by @rifatrakib.
Translations¶
Internal¶
- ๐ท Tweak build-docs to improve CI performance. PR #5699 by @tiangolo.
- โฌ [pre-commit.ci] pre-commit autoupdate. PR #5566 by @pre-commit-ci[bot].
- โฌ๏ธ Upgrade Ruff. PR #5698 by @tiangolo.
- ๐ท Remove pip cache for Smokeshow as it depends on a requirements.txt. PR #5700 by @tiangolo.
- ๐ Fix pip cache for Smokeshow. PR #5697 by @tiangolo.
- ๐ท Fix and tweak CI cache handling. PR #5696 by @tiangolo.
- ๐ท Update
setup-python
action in tests to use new caching feature. PR #5680 by @madkinsz. - โฌ Bump black from 22.8.0 to 22.10.0. PR #5569 by @dependabot[bot].
0.87.0¶
Highlights of this release:
- Upgraded Starlette
- Now the
TestClient
is based on HTTPX instead of Requests. ๐ - There are some possible breaking changes in the
TestClient
usage, but @Kludex built bump-testclient to help you automatize migrating your tests. Make sure you are using Git and that you can undo any unnecessary changes (false positive changes, etc) before usingbump-testclient
.
- Now the
- New WebSocketException (and docs), re-exported from Starlette.
- Upgraded and relaxed dependencies for package extras
all
(including new Uvicorn version), when you install"fastapi[all]"
. - New docs about how to Help Maintain FastAPI.
Features¶
- โฌ๏ธ Upgrade and relax dependencies for extras "all". PR #5634 by @tiangolo.
- โจ Re-export Starlette's
WebSocketException
and add it to docs. PR #5629 by @tiangolo. - ๐ Update references to Requests for tests to HTTPX, and add HTTPX to extras. PR #5628 by @tiangolo.
- โฌ Upgrade Starlette to
0.21.0
, including the newTestClient
based on HTTPX. PR #5471 by @pawelrubin.
Docs¶
- โ๏ธ Tweak Help FastAPI from PR review after merging. PR #5633 by @tiangolo.
- โ๏ธ Clarify docs on CORS. PR #5627 by @paxcodes.
- ๐ Update Help FastAPI: Help Maintain FastAPI. PR #5632 by @tiangolo.
Translations¶
- ๐ Fix highlight lines for Japanese translation for
docs/tutorial/query-params.md
. PR #2969 by @ftnext. - ๐ Add French translation for
docs/fr/docs/advanced/additional-status-code.md
. PR #5477 by @axel584. - ๐ Add Portuguese translation for
docs/pt/docs/tutorial/request-forms-and-files.md
. PR #5579 by @batlopes. - ๐ Add Japanese translation for
docs/ja/docs/advanced/websockets.md
. PR #4983 by @xryuseix.
Internal¶
- โจ Use Ruff for linting. PR #5630 by @tiangolo.
- ๐ Add Arabic issue number to Notify Translations GitHub Action. PR #5610 by @tiangolo.
- โฌ Bump dawidd6/action-download-artifact from 2.24.1 to 2.24.2. PR #5609 by @dependabot[bot].
- โฌ Bump dawidd6/action-download-artifact from 2.24.0 to 2.24.1. PR #5603 by @dependabot[bot].
- ๐ Update coverage badge to use Samuel Colvin's Smokeshow. PR #5585 by @tiangolo.
0.86.0¶
Features¶
- โฌ Add Python 3.11 to the officially supported versions. PR #5587 by @tiangolo.
- โ Enable tests for Python 3.11. PR #4881 by @tiangolo.
Fixes¶
Docs¶
- โ Fix typo in
docs/en/docs/tutorial/security/oauth2-jwt.md
. PR #5584 by @vivekashok1221.
Translations¶
- ๐ Update wording in Chinese translation for
docs/zh/docs/python-types.md
. PR #5416 by @supercaizehua. - ๐ Add Russian translation for
docs/ru/docs/deployment/index.md
. PR #5336 by @Xewus. - ๐ Update Chinese translation for
docs/tutorial/security/oauth2-jwt.md
. PR #3846 by @jaystone776.
Internal¶
- ๐ท Update FastAPI People to exclude bots: pre-commit-ci, dependabot. PR #5586 by @tiangolo.
- ๐จ Format OpenAPI JSON in
test_starlette_exception.py
. PR #5379 by @iudeen. - ๐ท Switch from Codecov to Smokeshow plus pytest-cov to pure coverage for internal tests. PR #5583 by @tiangolo.
- ๐ฅ Update FastAPI People. PR #5571 by @github-actions[bot].
0.85.2¶
Docs¶
- โ Fix grammar and add helpful links to dependencies in
docs/en/docs/async.md
. PR #5432 by @pamelafox. - โ Fix broken link in
alternatives.md
. PR #5455 by @su-shubham. - โ Fix typo in docs about contributing, for compatibility with
pip
in Zsh. PR #5523 by @zhangbo2012. - ๐ Fix typo in docs with examples for Python 3.10 instead of 3.9. PR #5545 by @feliciss.
Translations¶
- ๐ Add Portuguese translation for
docs/pt/docs/tutorial/request-forms.md
. PR #4934 by @batlopes. - ๐ Add Chinese translation for
docs/zh/docs/tutorial/dependencies/classes-as-dependencies.md
. PR #4971 by @Zssaer. - ๐ Add French translation for
deployment/deta.md
. PR #3692 by @rjNemo. - ๐ Update Chinese translation for
docs/zh/docs/tutorial/query-params-str-validations.md
. PR #5255 by @hjlarry. - ๐ Add Chinese translation for
docs/zh/docs/tutorial/sql-databases.md
. PR #4999 by @Zssaer. - ๐ Add Chinese translation for
docs/zh/docs/advanced/wsgi.md
. PR #4505 by @ASpathfinder. - ๐ Add Portuguese translation for
docs/pt/docs/tutorial/body-multiple-params.md
. PR #4111 by @lbmendes. - ๐ Add Portuguese translation for
docs/pt/docs/tutorial/path-params-numeric-validations.md
. PR #4099 by @lbmendes. - ๐ Add French translation for
deployment/versions.md
. PR #3690 by @rjNemo. - ๐ Add French translation for
docs/fr/docs/help-fastapi.md
. PR #2233 by @JulianMaurin. - ๐ Fix typo in Chinese translation for
docs/zh/docs/tutorial/security/first-steps.md
. PR #5530 by @yuki1sntSnow. - ๐ Add Portuguese translation for
docs/pt/docs/tutorial/response-status-code.md
. PR #4922 by @batlopes. - ๐ง Add config for Tamil translations. PR #5563 by @tiangolo.
Internal¶
- โฌ Bump internal dependency mypy from 0.971 to 0.982. PR #5541 by @dependabot[bot].
- โฌ Bump nwtgck/actions-netlify from 1.2.3 to 1.2.4. PR #5507 by @dependabot[bot].
- โฌ Bump internal dependency types-ujson from 5.4.0 to 5.5.0. PR #5537 by @dependabot[bot].
- โฌ Bump dawidd6/action-download-artifact from 2.23.0 to 2.24.0. PR #5508 by @dependabot[bot].
- โฌ Update internal dependency pytest-cov requirement from <4.0.0,>=2.12.0 to >=2.12.0,<5.0.0. PR #5539 by @dependabot[bot].
- โฌ [pre-commit.ci] pre-commit autoupdate. PR #5536 by @pre-commit-ci[bot].
- ๐ Fix internal Trio test warnings. PR #5547 by @samuelcolvin.
- โฌ [pre-commit.ci] pre-commit autoupdate. PR #5408 by @pre-commit-ci[bot].
- โฌ๏ธ Upgrade Typer to include Rich in scripts for docs. PR #5502 by @tiangolo.
- ๐ Fix calling
mkdocs
for languages as a subprocess to fix/enable MkDocs Material search plugin. PR #5501 by @tiangolo.
0.85.1¶
Fixes¶
- ๐ Fix support for strings in OpenAPI status codes:
default
,1XX
,2XX
,3XX
,4XX
,5XX
. PR #5187 by @JarroVGIT.
Docs¶
Internal¶
- ๐ฅ Update FastAPI People. PR #5447 by @github-actions[bot].
- ๐ง Disable Material for MkDocs search plugin. PR #5495 by @tiangolo.
- ๐ Ignore Trio warning in tests for CI. PR #5483 by @samuelcolvin.
0.85.0¶
Features¶
- โฌ Upgrade version required of Starlette from
0.19.1
to0.20.4
. Initial PR #4820 by @Kludex.- This includes several bug fixes in Starlette.
- โฌ๏ธ Upgrade Uvicorn max version in public extras: all. From
>=0.12.0,<0.18.0
to>=0.12.0,<0.19.0
. PR #5401 by @tiangolo.
Internal¶
- โฌ๏ธ Upgrade dependencies for doc and dev internal extras: Typer, Uvicorn. PR #5400 by @tiangolo.
- โฌ๏ธ Upgrade test dependencies: Black, HTTPX, databases, types-ujson. PR #5399 by @tiangolo.
- โฌ๏ธ Upgrade mypy and tweak internal type annotations. PR #5398 by @tiangolo.
- ๐ง Update test dependencies, upgrade Pytest, move dependencies from dev to test. PR #5396 by @tiangolo.
0.84.0¶
Breaking Changes¶
This version of FastAPI drops support for Python 3.6. ๐ฅ Please upgrade to a supported version of Python (3.7 or above), Python 3.6 reached the end-of-life a long time ago. ๐ โ
- ๐ง Update package metadata, drop support for Python 3.6, move build internals from Flit to Hatch. PR #5240 by @ofek.
0.83.0¶
๐จ This is probably the last release (or one of the last releases) to support Python 3.6. ๐ฅ
Python 3.6 reached the end-of-life and is no longer supported by Python since around a year ago.
You hopefully updated to a supported version of Python a while ago. If you haven't, you really should.
Features¶
- โจ Add support in
jsonable_encoder
for include and exclude with dataclasses. PR #4923 by @DCsunset.
Fixes¶
- ๐ Fix
RuntimeError
raised whenHTTPException
has a status code with no content. PR #5365 by @iudeen. - ๐ Fix empty reponse body when default
status_code
is empty but the aResponse
parameter withresponse.status_code
is set. PR #5360 by @tmeckel.
Docs¶
Internal¶
- โฌ [pre-commit.ci] pre-commit autoupdate. PR #5352 by @pre-commit-ci[bot].
0.82.0¶
๐จ This is probably the last release (or one of the last releases) to support Python 3.6. ๐ฅ
Python 3.6 reached the end-of-life and is no longer supported by Python since around a year ago.
You hopefully updated to a supported version of Python a while ago. If you haven't, you really should.
Features¶
- โจ Export
WebSocketState
infastapi.websockets
. PR #4376 by @matiuszka. - โจ Support Python internal description on Pydantic model's docstring. PR #3032 by @Kludex.
- โจ Update
ORJSONResponse
to support nonstr
keys and serializing Numpy arrays. PR #3892 by @baby5.
Fixes¶
- ๐ Allow exit code for dependencies with
yield
to always execute, by removing capacity limiter for them, to e.g. allow closing DB connections without deadlocks. PR #5122 by @adriangb. - ๐ Fix FastAPI People GitHub Action: set HTTPX timeout for GraphQL query request. PR #5222 by @iudeen.
- ๐ Make sure a parameter defined as required is kept required in OpenAPI even if defined as optional in another dependency. PR #4319 by @cd17822.
- ๐ Fix support for path parameters in WebSockets. PR #3879 by @davidbrochart.
Docs¶
- โ Update Hypercorn link, now pointing to GitHub. PR #5346 by @baconfield.
- โ Tweak wording in
docs/en/docs/advanced/dataclasses.md
. PR #3698 by @pfackeldey. - ๐ Add note about Python 3.10
X | Y
operator in explanation about Response Models. PR #5307 by @MendyLanda. - ๐ Add link to New Relic article: "How to monitor FastAPI application performance using Python agent". PR #5260 by @sjyothi54.
- ๐ Update docs for
ORJSONResponse
with details about improving performance. PR #2615 by @falkben. - ๐ Add docs for creating a custom Response class. PR #5331 by @tiangolo.
- ๐ Add tip about using alias for form data fields. PR #5329 by @tiangolo.
Translations¶
- ๐ Add Russian translation for
docs/ru/docs/features.md
. PR #5315 by @Xewus. - ๐ Update Chinese translation for
docs/zh/docs/tutorial/request-files.md
. PR #4529 by @ASpathfinder. - ๐ Add Chinese translation for
docs/zh/docs/tutorial/encoder.md
. PR #4969 by @Zssaer. - ๐ Fix MkDocs file line for Portuguese translation of
background-task.md
. PR #5242 by @ComicShrimp.
Internal¶
- ๐ฅ Update FastAPI People. PR #5347 by @github-actions[bot].
- โฌ Bump dawidd6/action-download-artifact from 2.22.0 to 2.23.0. PR #5321 by @dependabot[bot].
- โฌ [pre-commit.ci] pre-commit autoupdate. PR #5318 by @pre-commit-ci[bot].
- โ Fix a small code highlight line error. PR #5256 by @hjlarry.
- โป Internal small refactor, move
operation_id
parameter position in delete method for consistency with the code. PR #4474 by @hiel. - ๐ง Update sponsors, disable ImgWhale. PR #5338 by @tiangolo.
0.81.0¶
Features¶
- โจ Add ReDoc
<noscript>
warning when JS is disabled. PR #5074 by @evroon. - โจ Add support for
FrozenSet
in parameters (e.g. query). PR #2938 by @juntatalor. - โจ Allow custom middlewares to raise
HTTPException
s and propagate them. PR #2036 by @ghandic. - โจ Preserve
json.JSONDecodeError
information when handling invalid JSON in request body, to support custom exception handlers that use its information. PR #4057 by @UKnowWhoIm.
Fixes¶
- ๐ Fix
jsonable_encoder
for dataclasses with pydantic-compatible fields. PR #3607 by @himbeles. - ๐ Fix support for extending
openapi_extras
with parameter lists. PR #4267 by @orilevari.
Docs¶
- โ Fix a simple typo in
docs/en/docs/python-types.md
. PR #5193 by @GlitchingCore. - โ Fix typos in
tests/test_schema_extra_examples.py
. PR #5126 by @supraaxdd. - โ Fix typos in
docs/en/docs/tutorial/path-params-numeric-validations.md
. PR #5142 by @invisibleroads. - ๐ Add step about upgrading pip in the venv to avoid errors when installing dependencies
docs/en/docs/contributing.md
. PR #5181 by @edisnake. - โ Reword and clarify text in tutorial
docs/en/docs/tutorial/body-nested-models.md
. PR #5169 by @papb. - โ Fix minor typo in
docs/en/docs/features.md
. PR #5206 by @OtherBarry. - โ Fix minor typos in
docs/en/docs/async.md
. PR #5125 by @Ksenofanex. - ๐ Add external link to docs: "Fastapi, Docker(Docker compose) and Postgres". PR #5033 by @krishnardt.
- ๐ Simplify example for docs for Additional Responses, remove unnecessary
else
. PR #4693 by @adriangb. - ๐ Update docs, compare enums with identity instead of equality. PR #4905 by @MicaelJarniac.
- โ Fix typo in
docs/en/docs/python-types.md
. PR #4886 by @MicaelJarniac. - ๐จ Fix syntax highlighting in docs for OpenAPI Callbacks. PR #4368 by @xncbf.
- โ Reword confusing sentence in docs file
typo-fix-path-params-numeric-validations.md
. PR #3219 by @ccrenfroe. - ๐ Update docs for handling HTTP Basic Auth with
secrets.compare_digest()
to account for non-ASCII characters. PR #3536 by @lewoudar. - ๐ Update docs for testing, fix examples with relative imports. PR #5302 by @tiangolo.
Translations¶
- ๐ Add Russian translation for
docs/ru/docs/index.md
. PR #5289 by @impocode. - ๐ Add Russian translation for
docs/ru/docs/deployment/versions.md
. PR #4985 by @emp7yhead. - ๐ Add Portuguese translation for
docs/pt/docs/tutorial/header-params.md
. PR #4921 by @batlopes. - ๐ Update
ko/mkdocs.yml
for a missing link. PR #5020 by @dalinaum.
Internal¶
- โฌ Bump dawidd6/action-download-artifact from 2.21.1 to 2.22.0. PR #5258 by @dependabot[bot].
- โฌ [pre-commit.ci] pre-commit autoupdate. PR #5196 by @pre-commit-ci[bot].
- ๐ฅ Delete duplicated tests in
tests/test_tutorial/test_sql_databases/test_sql_databases.py
. PR #5040 by @raccoonyy. - โป Simplify internal RegEx in
fastapi/utils.py
. PR #5057 by @pylounge. - ๐ง Fix Type hint of
auto_error
which does not need to beOptional[bool]
. PR #4933 by @DavidKimDY. - ๐ง Update mypy config, use
strict = true
instead of manual configs. PR #4605 by @michaeloliverx. - โป Change a
dict()
for{}
infastapi/utils.py
. PR #3138 by @ShahriyarR. - โป Move internal variable for errors in
jsonable_encoder
to put related code closer. PR #4560 by @GuilleQP. - โป Simplify conditional assignment in
fastapi/dependencies/utils.py
. PR #4597 by @cikay. - โฌ Upgrade version pin accepted for Flake8, for internal code, to
flake8 >=3.8.3,<6.0.0
. PR #4097 by @jamescurtin. - ๐ฑ Update Jina banner, fix typo. PR #5301 by @tiangolo.
0.80.0¶
Breaking Changes - Fixes¶
If you are using response_model
with some type that doesn't include None
but the function is returning None
, it will now raise an internal server error, because you are returning invalid data that violates the contract in response_model
. Before this release it would allow breaking that contract returning None
.
For example, if you have an app like this:
from fastapi import FastAPI
from pydantic import BaseModel
class Item(BaseModel):
name: str
price: Optional[float] = None
owner_ids: Optional[List[int]] = None
app = FastAPI()
@app.get("/items/invalidnone", response_model=Item)
def get_invalid_none():
return None
...calling the path /items/invalidnone
will raise an error, because None
is not a valid type for the response_model
declared with Item
.
You could also be implicitly returning None
without realizing, for example:
from fastapi import FastAPI
from pydantic import BaseModel
class Item(BaseModel):
name: str
price: Optional[float] = None
owner_ids: Optional[List[int]] = None
app = FastAPI()
@app.get("/items/invalidnone", response_model=Item)
def get_invalid_none():
if flag:
return {"name": "foo"}
# if flag is False, at this point the function will implicitly return None
If you have path operations using response_model
that need to be allowed to return None
, make it explicit in response_model
using Union[Something, None]
:
from typing import Union
from fastapi import FastAPI
from pydantic import BaseModel
class Item(BaseModel):
name: str
price: Optional[float] = None
owner_ids: Optional[List[int]] = None
app = FastAPI()
@app.get("/items/invalidnone", response_model=Union[Item, None])
def get_invalid_none():
return None
This way the data will be correctly validated, you won't have an internal server error, and the documentation will also reflect that this path operation could return None
(or null
in JSON).
Fixes¶
- โฌ Upgrade Swagger UI copy of
oauth2-redirect.html
to include fixes for flavors of authorization code flows in Swagger UI. PR #3439 initial PR by @koonpeng. - โป Strip empty whitespace from description extracted from docstrings. PR #2821 by @and-semakin.
- ๐ Fix cached dependencies when using a dependency in
Security()
and other places (e.g.Depends()
) with different OAuth2 scopes. PR #2945 by @laggardkernel. - ๐จ Update type annotations for
response_model
, allow things likeUnion[str, None]
. PR #5294 by @tiangolo.
Translations¶
- ๐ Fix typos in German translation for
docs/de/docs/features.md
. PR #4533 by @0xflotus. - ๐ Add missing navigator for
encoder.md
in Korean translation. PR #5238 by @joonas-yoon. - (Empty PR merge by accident) #4913.
0.79.1¶
Fixes¶
- ๐ Fix
jsonable_encoder
usinginclude
andexclude
parameters for non-Pydantic objects. PR #2606 by @xaviml. - ๐ Fix edge case with repeated aliases names not shown in OpenAPI. PR #2351 by @klaa97.
- ๐ Add misc dependency installs to tutorial docs. PR #2126 by @TeoZosa.
Docs¶
- ๐ Add note giving credit for illustrations to Ketrina Thompson. PR #5284 by @tiangolo.
- โ Fix typo in
python-types.md
. PR #5116 by @Kludex. - โ Fix typo in
docs/en/docs/python-types.md
. PR #5007 by @atiabbz. - ๐ Remove unneeded Django/Flask references from async topic intro. PR #5280 by @carltongibson.
- โจ Add illustrations for Concurrent burgers and Parallel burgers. PR #5277 by @tiangolo. Updated docs at: Concurrency and Burgers.
Translations¶
- ๐ Add Portuguese translation for
docs/pt/docs/tutorial/query-params.md
. PR #4775 by @batlopes. - ๐ Add Portuguese translation for
docs/pt/docs/tutorial/security/first-steps.md
. PR #4954 by @FLAIR7. - ๐ Add translation for
docs/zh/docs/advanced/response-cookies.md
. PR #4638 by @zhangbo2012. - ๐ Add French translation for
docs/fr/docs/deployment/index.md
. PR #3689 by @rjNemo. - ๐ Add Portuguese translation for
tutorial/handling-errors.md
. PR #4769 by @frnsimoes. - ๐ Add French translation for
docs/fr/docs/history-design-future.md
. PR #3451 by @rjNemo. - ๐ Add Russian translation for
docs/ru/docs/tutorial/background-tasks.md
. PR #4854 by @AdmiralDesu. - ๐ Add Chinese translation for
docs/tutorial/security/first-steps.md
. PR #3841 by @jaystone776. - ๐ Add Japanese translation for
docs/ja/docs/advanced/nosql-databases.md
. PR #4205 by @sUeharaE4. - ๐ Add Indonesian translation for
docs/id/docs/tutorial/index.md
. PR #4705 by @bas-baskara. - ๐ Add Persian translation for
docs/fa/docs/index.md
and tweak right-to-left CSS. PR #2395 by @mohsen-mahmoodi.
Internal¶
- ๐ง Update Jina sponsorship. PR #5283 by @tiangolo.
- ๐ง Update Jina sponsorship. PR #5272 by @tiangolo.
- ๐ง Update sponsors, Striveworks badge. PR #5179 by @tiangolo.
0.79.0¶
Fixes - Breaking Changes¶
- ๐ Fix removing body from status codes that do not support it. PR #5145 by @tiangolo.
- Setting
status_code
to204
,304
, or any code below200
(1xx) will remove the body from the response. - This fixes an error in Uvicorn that otherwise would be thrown:
RuntimeError: Response content longer than Content-Length
. - This removes
fastapi.openapi.constants.STATUS_CODES_WITH_NO_BODY
, it is replaced by a function in utils.
- Setting
Translations¶
- ๐ Start of Hebrew translation. PR #5050 by @itay-raveh.
- ๐ง Add config for Swedish translations notification. PR #5147 by @tiangolo.
- ๐ Start of Swedish translation. PR #5062 by @MrRawbin.
- ๐ Add Japanese translation for
docs/ja/docs/advanced/index.md
. PR #5043 by @wakabame. - ๐๐ต๐ฑ Add Polish translation for
docs/pl/docs/tutorial/first-steps.md
. PR #5024 by @Valaraucoo.
Internal¶
- ๐ง Update translations notification for Hebrew. PR #5158 by @tiangolo.
- ๐ง Update Dependabot commit message. PR #5156 by @tiangolo.
- โฌ Bump actions/upload-artifact from 2 to 3. PR #5148 by @dependabot[bot].
- โฌ Bump actions/cache from 2 to 3. PR #5149 by @dependabot[bot].
- ๐ง Update sponsors badge configs. PR #5155 by @tiangolo.
- ๐ฅ Update FastAPI People. PR #5154 by @tiangolo.
- ๐ง Update Jina sponsor badges. PR #5151 by @tiangolo.
- โฌ Bump actions/checkout from 2 to 3. PR #5133 by @dependabot[bot].
- โฌ [pre-commit.ci] pre-commit autoupdate. PR #5030 by @pre-commit-ci[bot].
- โฌ Bump nwtgck/actions-netlify from 1.1.5 to 1.2.3. PR #5132 by @dependabot[bot].
- โฌ Bump codecov/codecov-action from 2 to 3. PR #5131 by @dependabot[bot].
- โฌ Bump dawidd6/action-download-artifact from 2.9.0 to 2.21.1. PR #5130 by @dependabot[bot].
- โฌ Bump actions/setup-python from 2 to 4. PR #5129 by @dependabot[bot].
- ๐ท Add Dependabot. PR #5128 by @tiangolo.
- โป๏ธ Move from
Optional[X]
toUnion[X, None]
for internal utils. PR #5124 by @tiangolo. - ๐ง Update sponsors, remove Dropbase, add Doist. PR #5096 by @tiangolo.
- ๐ง Update sponsors, remove Classiq, add ImgWhale. PR #5079 by @tiangolo.
0.78.0¶
Features¶
-
โจ Add support for omitting
...
as default value when declaring required parameters with: -
Path()
Query()
Header()
Cookie()
Body()
Form()
File()
New docs at Tutorial - Query Parameters and String Validations - Make it required. PR #4906 by @tiangolo.
Up to now, declaring a required parameter while adding additional validation or metadata needed using ...
(Ellipsis).
For example:
from fastapi import Cookie, FastAPI, Header, Path, Query
app = FastAPI()
@app.get("/items/{item_id}")
def main(
item_id: int = Path(default=..., gt=0),
query: str = Query(default=..., max_length=10),
session: str = Cookie(default=..., min_length=3),
x_trace: str = Header(default=..., title="Tracing header"),
):
return {"message": "Hello World"}
...all these parameters are required because the default value is ...
(Ellipsis).
But now it's possible and supported to just omit the default value, as would be done with Pydantic fields, and the parameters would still be required.
โจ For example, this is now supported:
from fastapi import Cookie, FastAPI, Header, Path, Query
app = FastAPI()
@app.get("/items/{item_id}")
def main(
item_id: int = Path(gt=0),
query: str = Query(max_length=10),
session: str = Cookie(min_length=3),
x_trace: str = Header(title="Tracing header"),
):
return {"message": "Hello World"}
To declare parameters as optional (not required), you can set a default value as always, for example using None
:
from typing import Union
from fastapi import Cookie, FastAPI, Header, Path, Query
app = FastAPI()
@app.get("/items/{item_id}")
def main(
item_id: int = Path(gt=0),
query: Union[str, None] = Query(default=None, max_length=10),
session: Union[str, None] = Cookie(default=None, min_length=3),
x_trace: Union[str, None] = Header(default=None, title="Tracing header"),
):
return {"message": "Hello World"}
Docs¶
- ๐ Add docs recommending
Union
overOptional
and migrate source examples. New docs at Python Types Intro - UsingUnion
orOptional
. PR #4908 by @tiangolo. - ๐จ Fix default value as set in tutorial for Path Operations Advanced Configurations. PR #4899 by @tiangolo.
- ๐ Add documentation for redefined path operations. PR #4864 by @madkinsz.
- ๐ Updates links for Celery documentation. PR #4736 by @sammyzord.
- โ Fix example code with sets in tutorial for body nested models. PR #3030 by @hitrust.
- โ Fix links to Pydantic docs. PR #4670 by @kinuax.
- ๐ Update docs about Swagger UI self-hosting with newer source links. PR #4813 by @Kastakin.
- ๐ Add link to external article: Building the Poll App From Django Tutorial With FastAPI And React. PR #4778 by @jbrocher.
- ๐ Add OpenAPI warning to "Body - Fields" docs with extra schema extensions. PR #4846 by @ml-evs.
Translations¶
- ๐ Fix code examples in Japanese translation for
docs/ja/docs/tutorial/testing.md
. PR #4623 by @hirotoKirimaru.
Internal¶
- โป Refactor dict value extraction to minimize key lookups
fastapi/utils.py
. PR #3139 by @ShahriyarR. - โ Add tests for required nonable parameters and body fields. PR #4907 by @tiangolo.
- ๐ท Fix installing Material for MkDocs Insiders in CI. PR #4897 by @tiangolo.
- ๐ท Add pre-commit CI instead of custom GitHub Action. PR #4896 by @tiangolo.
- ๐ท Add pre-commit GitHub Action workflow. PR #4895 by @tiangolo.
- ๐ Add dark mode auto switch to docs based on OS preference. PR #4869 by @ComicShrimp.
- ๐ฅ Remove un-used old pending tests, already covered in other places. PR #4891 by @tiangolo.
- ๐ง Add Python formatting hooks to pre-commit. PR #4890 by @tiangolo.
- ๐ง Add pre-commit with first config and first formatting pass. PR #4888 by @tiangolo.
- ๐ท Disable CI installing Material for MkDocs in forks. PR #4410 by @dolfinus.
0.77.1¶
Upgrades¶
Docs¶
- ๐ Add link to german article: REST-API Programmieren mittels Python und dem FastAPI Modul. PR #4624 by @fschuermeyer.
- ๐ Add external link: PyCharm Guide to FastAPI. PR #4512 by @mukulmantosh.
- ๐ Add external link to article: Building an API with FastAPI and Supabase and Deploying on Deta. PR #4440 by @aUnicornDev.
- โ Fix small typo in
docs/en/docs/tutorial/security/first-steps.md
. PR #4515 by @KikoIlievski.
Translations¶
- ๐ Add Polish translation for
docs/pl/docs/tutorial/index.md
. PR #4516 by @MKaczkow. - โ Fix typo in deployment. PR #4629 by @raisulislam541.
- ๐ Add Portuguese translation for
docs/pt/docs/help-fastapi.md
. PR #4583 by @mateusjs.
Internal¶
0.77.0¶
Upgrades¶
- โฌ Upgrade Starlette from 0.18.0 to 0.19.0. PR #4488 by @Kludex.
- When creating an explicit
JSONResponse
thecontent
argument is now required.
- When creating an explicit
Docs¶
- ๐ Add external link to article: Seamless FastAPI Configuration with ConfZ. PR #4414 by @silvanmelchior.
- ๐ Add external link to article: 5 Advanced Features of FastAPI You Should Try. PR #4436 by @kaustubhgupta.
- โ Reword to improve legibility of docs about
TestClient
. PR #4389 by @rgilton. - ๐ Add external link to blog post about Kafka, FastAPI, and Ably. PR #4044 by @Ugbot.
- โ Fix typo in
docs/en/docs/tutorial/sql-databases.md
. PR #4875 by @wpyoga. - โ Fix typo in
docs/en/docs/async.md
. PR #4726 by @Prezu.
Translations¶
- ๐ Update source example highlights for
docs/zh/docs/tutorial/query-params-str-validations.md
. PR #4237 by @caimaoy. - ๐ Remove translation docs references to aiofiles as it's no longer needed since AnyIO. PR #3594 by @alonme.
- โ ๐ Fix typo in Portuguese translation for
docs/pt/docs/tutorial/path-params.md
. PR #4722 by @CleoMenezesJr. - ๐ Fix live docs server for translations for some languages. PR #4729 by @wakabame.
- ๐ Add Portuguese translation for
docs/pt/docs/tutorial/cookie-params.md
. PR #4112 by @lbmendes. - ๐ Fix French translation for
docs/tutorial/body.md
. PR #4332 by @Smlep. - ๐ Add Japanese translation for
docs/ja/docs/advanced/conditional-openapi.md
. PR #2631 by @sh0nk. - ๐ Fix Japanese translation of
docs/ja/docs/tutorial/body.md
. PR #3062 by @a-takahashi223. - ๐ Add Portuguese translation for
docs/pt/docs/tutorial/background-tasks.md
. PR #2170 by @izaguerreiro. - ๐ Add Portuguese translation for
docs/deployment/deta.md
. PR #4442 by @lsglucas. - ๐ Add Russian translation for
docs/async.md
. PR #4036 by @Winand. - ๐ Add Portuguese translation for
docs/tutorial/body.md
. PR #3960 by @leandrodesouzadev. - ๐ Add Portuguese translation of
tutorial/extra-data-types.md
. PR #4077 by @luccasmmg. - ๐ Update German translation for
docs/features.md
. PR #3905 by @jomue.
0.76.0¶
Upgrades¶
Internal¶
- ๐ฅ Update FastAPI People. PR #4847 by @github-actions[bot].
- ๐ง Add Budget Insight sponsor. PR #4824 by @tiangolo.
- ๐ฑ Update sponsor, ExoFlare badge. PR #4822 by @tiangolo.
- ๐ง Update sponsors, enable Dropbase again, update TalkPython link. PR #4821 by @tiangolo.
0.75.2¶
This release includes upgrades to third-party packages that handle security issues. Although there's a chance these issues don't affect you in particular, please upgrade as soon as possible.
Fixes¶
- โ
Fix new/recent tests with new fixed
ValidationError
JSON Schema. PR #4806 by @tiangolo. - ๐ Fix JSON Schema for
ValidationError
at fieldloc
. PR #3810 by @dconathan. - ๐ Fix support for prefix on APIRouter WebSockets. PR #2640 by @Kludex.
Upgrades¶
- โฌ๏ธ Update ujson ranges for CVE-2021-45958. PR #4804 by @tiangolo.
- โฌ๏ธ Upgrade dependencies upper range for extras "all". PR #4803 by @tiangolo.
- โฌ Upgrade Swagger UI - swagger-ui-dist@4. This handles a security issue in Swagger UI itself where it could be possible to inject HTML into Swagger UI. Please upgrade as soon as you can, in particular if you expose your Swagger UI (
/docs
) publicly to non-expert users. PR #4347 by @RAlanWright.
Internal¶
- ๐ง Update sponsors, add: ExoFlare, Ines Course; remove: Dropbase, Vim.so, Calmcode; update: Striveworks, TalkPython and TestDriven.io. PR #4805 by @tiangolo.
- โฌ๏ธ Upgrade Codecov GitHub Action. PR #4801 by @tiangolo.
0.75.1¶
Translations¶
- ๐ Start Dutch translations. PR #4703 by @tiangolo.
- ๐ Start Persian/Farsi translations. PR #4243 by @aminalaee.
- โ Reword sentence about handling errors. PR #1993 by @khuhroproeza.
Internal¶
- ๐ฅ Update FastAPI People. PR #4752 by @github-actions[bot].
- โ Temporarily remove typer-cli from dependencies and upgrade Black to unblock Pydantic CI. PR #4754 by @tiangolo.
- ๐ง Add configuration to notify Dutch translations. PR #4702 by @tiangolo.
- ๐ฅ Update FastAPI People. PR #4699 by @github-actions[bot].
- ๐ Fix FastAPI People generation to include missing file in commit. PR #4695 by @tiangolo.
- ๐ง Update Classiq sponsor links. PR #4688 by @tiangolo.
- ๐ง Add Classiq sponsor. PR #4671 by @tiangolo.
- ๐ Add Jina's QA Bot to the docs to help people that want to ask quick questions. PR #4655 by @tiangolo based on original PR #4626 by @hanxiao.
0.75.0¶
Features¶
- โจ Add support for custom
generate_unique_id_function
and docs for generating clients. New docs: Advanced - Generate Clients. PR #4650 by @tiangolo.
0.74.1¶
Features¶
- โจ Include route in scope to allow middleware and other tools to extract its information. PR #4603 by @tiangolo.
0.74.0¶
Breaking Changes¶
- โจ Update internal
AsyncExitStack
to fix context for dependencies withyield
. PR #4575 by @tiangolo.
Dependencies with yield
can now catch HTTPException
and custom exceptions. For example:
async def get_database():
with Session() as session:
try:
yield session
except HTTPException:
session.rollback()
raise
finally:
session.close()
After the dependency with yield
handles the exception (or not) the exception is raised again. So that any exception handlers can catch it, or ultimately the default internal ServerErrorMiddleware
.
If you depended on exceptions not being received by dependencies with yield
, and receiving an exception breaks the code after yield
, you can use a block with try
and finally
:
async def do_something():
try:
yield something
finally:
some_cleanup()
...that way the finally
block is run regardless of any exception that might happen.
Features¶
- The same PR #4575 from above also fixes the
contextvars
context for the code before and afteryield
. This was the main objective of that PR.
This means that now, if you set a value in a context variable before yield
, the value would still be available after yield
(as you would intuitively expect). And it also means that you can reset the context variable with a token afterwards.
For example, this works correctly now:
from contextvars import ContextVar
from typing import Any, Dict, Optional
legacy_request_state_context_var: ContextVar[Optional[Dict[str, Any]]] = ContextVar(
"legacy_request_state_context_var", default=None
)
async def set_up_request_state_dependency():
request_state = {"user": "deadpond"}
contextvar_token = legacy_request_state_context_var.set(request_state)
yield request_state
legacy_request_state_context_var.reset(contextvar_token)
...before this change it would raise an error when resetting the context variable, because the contextvars
context was different, because of the way it was implemented.
Note: You probably don't need contextvars
, and you should probably avoid using them. But they are powerful and useful in some advanced scenarios, for example, migrating from code that used Flask's g
semi-global variable.
Technical Details: If you want to know more of the technical details you can check out the PR description #4575.
Internal¶
- ๐ง Add Striveworks sponsor. PR #4596 by @tiangolo.
- ๐ Only build docs on push when on master to avoid duplicate runs from PRs. PR #4564 by @tiangolo.
- ๐ฅ Update FastAPI People. PR #4502 by @github-actions[bot].
0.73.0¶
Features¶
- โจ Add support for declaring
UploadFile
parameters without explicitFile()
. PR #4469 by @tiangolo. New docs: Request Files - File Parameters with UploadFile. - โจ Add support for tags with Enums. PR #4468 by @tiangolo. New docs: Path Operation Configuration - Tags with Enums.
- โจ Allow hiding from OpenAPI (and Swagger UI)
Query
,Cookie
,Header
, andPath
parameters. PR #3144 by @astraldawn. New docs: Query Parameters and String Validations - Exclude from OpenAPI.
Docs¶
Fixes¶
- ๐ Fix bug preventing to use OpenAPI when using tuples. PR #3874 by @victorbenichoux.
- ๐ Prefer custom encoder over defaults if specified in
jsonable_encoder
. PR #2061 by @viveksunder.
Internal¶
- ๐ Fix docs dependencies cache, to get the latest Material for MkDocs. PR #4466 by @tiangolo.
- ๐ง Add sponsor Dropbase. PR #4465 by @tiangolo.
0.72.0¶
Features¶
- โจ Enable configuring Swagger UI parameters. Original PR #2568 by @jmriebold. Here are the new docs: Configuring Swagger UI.
Docs¶
Translations¶
- ๐ Update Chinese translation for
docs/help-fastapi.md
. PR #3847 by @jaystone776. - ๐ Fix Korean translation for
docs/ko/docs/index.md
. PR #4195 by @kty4119. - ๐ Add Polish translation for
docs/pl/docs/index.md
. PR #4245 by @MicroPanda123. - ๐ Add Chinese translation for
docs\tutorial\path-operation-configuration.md
. PR #3312 by @jaystone776.
Internal¶
0.71.0¶
Features¶
- โจ Add docs and tests for Python 3.9 and Python 3.10. PR #3712 by @tiangolo.
- You can start with Python Types Intro, it explains what changes between different Python versions, in Python 3.9 and in Python 3.10.
- All the FastAPI docs are updated. Each code example in the docs that could use different syntax in Python 3.9 or Python 3.10 now has all the alternatives in tabs.
- โฌ๏ธ Upgrade Starlette to 0.17.1. PR #4145 by @simondale00.
Internal¶
- ๐ฅ Update FastAPI People. PR #4354 by @github-actions[bot].
- ๐ง Add FastAPI Trove Classifier for PyPI as now there's one ๐คท๐. PR #4386 by @tiangolo.
- โฌ Upgrade MkDocs Material and configs. PR #4385 by @tiangolo.
0.70.1¶
There's nothing interesting in this particular FastAPI release. It is mainly to enable/unblock the release of the next version of Pydantic that comes packed with features and improvements. ๐คฉ
Fixes¶
- ๐ Fix JSON Schema for dataclasses, supporting the fixes in Pydantic 1.9. PR #4272 by @PrettyWood.
Translations¶
- ๐ Add Korean translation for
docs/tutorial/request-forms-and-files.md
. PR #3744 by @NinaHwang. - ๐ Add Korean translation for
docs/tutorial/request-files.md
. PR #3743 by @NinaHwang. - ๐ Add portuguese translation for
docs/tutorial/query-params-str-validations.md
. PR #3965 by @leandrodesouzadev. - ๐ Add Korean translation for
docs/tutorial/response-status-code.md
. PR #3742 by @NinaHwang. - ๐ Add Korean translation for Tutorial - JSON Compatible Encoder. PR #3152 by @NEONKID.
- ๐ Add Korean translation for Tutorial - Path Parameters and Numeric Validations. PR #2432 by @hard-coders.
- ๐ Add Korean translation for
docs/ko/docs/deployment/versions.md
. PR #4121 by @DevDae. - ๐ Fix Korean translation for
docs/ko/docs/tutorial/index.md
. PR #4193 by @kimjaeyoonn. - ๐ง Add CryptAPI sponsor. PR #4264 by @tiangolo.
- ๐ Update
docs/tutorial/dependencies/classes-as-dependencies
: Add type of query parameters in a description ofClasses as dependencies
. PR #4015 by @0417taehyun. - ๐ Add French translation for Tutorial - First steps. PR #3455 by @Smlep.
- ๐ Add French translation for
docs/tutorial/path-params.md
. PR #3548 by @Smlep. - ๐ Add French translation for
docs/tutorial/query-params.md
. PR #3556 by @Smlep. - ๐ Add Turkish translation for
docs/python-types.md
. PR #3926 by @BilalAlpaslan.
Internal¶
- ๐ฅ Update FastAPI People. PR #4274 by @github-actions[bot].
0.70.0¶
This release just upgrades Starlette to the latest version, 0.16.0
, which includes several bug fixes and some small breaking changes.
These last three consecutive releases are independent so that you can migrate gradually:
- First to FastAPI
0.68.2
, with no breaking changes, but upgrading all the sub-dependencies. - Next to FastAPI
0.69.0
, which upgrades Starlette to0.15.0
, with AnyIO support, and a higher chance of having breaking changes in your code. - Finally to FastAPI
0.70.0
, just upgrading Starlette to the latest version0.16.0
with additional bug fixes.
This way, in case there was a breaking change for your code in one of the releases, you can still benefit from the previous upgrades. โจ
Breaking Changes - Upgrade¶
Also upgrades the ranges of optional dependencies:
"jinja2 >=2.11.2,<4.0.0"
"itsdangerous >=1.1.0,<3.0.0"
0.69.0¶
Breaking Changes - Upgrade¶
This release adds support for Trio. โจ
It upgrades the version of Starlette to 0.15.0
, now based on AnyIO, and the internal async components in FastAPI are now based on AnyIO as well, making it compatible with both asyncio and Trio.
You can read the docs about running FastAPI with Trio using Hypercorn.
This release also removes graphene
as an optional dependency for GraphQL. If you need to work with GraphQL, the recommended library now is Strawberry. You can read the new FastAPI with GraphQL docs.
Features¶
- โจ Add support for Trio via AnyIO, upgrading Starlette to
0.15.0
. PR #3372 by @graingert. - โ Remove
graphene
as an optional dependency. PR #4007 by @tiangolo.
Docs¶
- ๐ Add docs for using Trio with Hypercorn. PR #4014 by @tiangolo.
- โ Fix typos in Deployment Guide. PR #3975 by @ghandic.
- ๐ Update docs with pip install calls when using extras with brackets, use quotes for compatibility with Zsh. PR #3131 by @tomwei7.
- ๐ Add external link to article: Deploying ML Models as API Using FastAPI and Heroku. PR #3904 by @kaustubhgupta.
- โ Fix typo in file paths in
docs/en/docs/contributing.md
. PR #3752 by @NinaHwang. - โ Fix a typo in
docs/en/docs/advanced/path-operation-advanced-configuration.md
anddocs/en/docs/release-notes.md
. PR #3750 by @saintmalik. - โ๏ธ Add a missing comma in the security tutorial. PR #3564 by @jalvaradosegura.
- โ Fix typo in
docs/en/docs/help-fastapi.md
. PR #3760 by @jaystone776. - โ Fix typo about file path in
docs/en/docs/tutorial/bigger-applications.md
. PR #3285 by @HolyDorus. - โ Re-word to clarify test client in
docs/en/docs/tutorial/testing.md
. PR #3382 by @Bharat123rox. - ๐ Fix incorrect highlighted code. PR #3325 by @paxcodes.
- ๐ Add external link to article: How-to deploy FastAPI app to Heroku. PR #3241 by @Jarmos-san.
- โ Fix typo (mistranslation) in
docs/en/docs/advanced/templates.md
. PR #3211 by @oerpli. - ๐ Remove note about (now supported) feature from Swagger UI in
docs/en/docs/tutorial/request-files.md
. PR #2803 by @gsganden. - โ Fix typo re-word in
docs/tutorial/handling-errors.md
. PR #2700 by @graue70.
Translations¶
- ๐ Initialize Azerbaijani translations. PR #3941 by @madatbay.
- ๐ Add Turkish translation for
docs/fastapi-people.md
. PR #3848 by @BilalAlpaslan.
Internal¶
- ๐ Add supported Python versions badge. PR #2794 by @hramezani.
- โ Fix link in Japanese docs for
docs/ja/docs/deployment/docker.md
. PR #3245 by @utamori. - ๐ง Correct DeprecationWarning config and comment in pytest settings. PR #4008 by @graingert.
- ๐ง Swap light/dark theme button icon. PR #3246 by @eddsalkield.
- ๐ง Lint only in Python 3.7 and above. PR #4006 by @tiangolo.
- ๐ง Add GitHub Action notify-translations config for Azerbaijani. PR #3995 by @tiangolo.
0.68.2¶
This release has no breaking changes. ๐
It upgrades the version ranges of sub-dependencies to allow applications using FastAPI to easily upgrade them.
Soon there will be a new FastAPI release upgrading Starlette to take advantage of recent improvements, but as that has a higher chance of having breaking changes, it will be in a separate release.
Features¶
- โฌIncrease supported version of aiofiles to suppress warnings. PR #2899 by @SnkSynthesis.
- โ Do not require backports in Python >= 3.7. PR #1880 by @FFY00.
- โฌ Upgrade required Python version to >= 3.6.1, needed by typing.Deque, used by Pydantic. PR #2733 by @hukkin.
- โฌ๏ธ Bump Uvicorn max range to 0.15.0. PR #3345 by @Kludex.
Docs¶
- ๐ Update GraphQL docs, recommend Strawberry. PR #3981 by @tiangolo.
- ๐ Re-write and extend Deployment guide: Concepts, Uvicorn, Gunicorn, Docker, Containers, Kubernetes. PR #3974 by @tiangolo.
- ๐ Upgrade HTTPS guide with more explanations and diagrams. PR #3950 by @tiangolo.
Translations¶
- ๐ Add Turkish translation for
docs/features.md
. PR #1950 by @ycd. - ๐ Add Turkish translation for
docs/benchmarks.md
. PR #2729 by @Telomeraz. - ๐ Add Turkish translation for
docs/index.md
. PR #1908 by @ycd. - ๐ Add French translation for
docs/tutorial/body.md
. PR #3671 by @Smlep. - ๐ Add French translation for
deployment/docker.md
. PR #3694 by @rjNemo. - ๐ Add Portuguese translation for
docs/tutorial/path-params.md
. PR #3664 by @FelipeSilva93. - ๐ Add Portuguese translation for
docs/deployment/https.md
. PR #3754 by @lsglucas. - ๐ Add German translation for
docs/features.md
. PR #3699 by @mawassk.
Internal¶
- โจ Update GitHub Action: notify-translations, to avoid a race conditions. PR #3989 by @tiangolo.
- โฌ๏ธ Upgrade development
autoflake
, supporting multi-line imports. PR #3988 by @tiangolo. - โฌ๏ธ Increase dependency ranges for tests and docs: pytest-cov, pytest-asyncio, black, httpx, sqlalchemy, databases, mkdocs-markdownextradata-plugin. PR #3987 by @tiangolo.
- ๐ฅ Update FastAPI People. PR #3986 by @github-actions[bot].
- ๐ Fix badges in README and main page. PR #3979 by @ghandic.
- โฌ Upgrade internal testing dependencies: mypy to version 0.910, add newly needed type packages. PR #3350 by @ArcLightSlavik.
- โจ Add Deepset Sponsorship. PR #3976 by @tiangolo.
- ๐จ Tweak CSS styles for shell animations. PR #3888 by @tiangolo.
- ๐ง Add new Sponsor Calmcode.io. PR #3777 by @tiangolo.
0.68.1¶
- โจ Add support for
read_with_orm_mode
, to support SQLModel relationship attributes. PR #3757 by @tiangolo.
Translations¶
- ๐ Add Portuguese translation of
docs/fastapi-people.md
. PR #3461 by @ComicShrimp. - ๐ Add Chinese translation for
docs/tutorial/dependencies/dependencies-in-path-operation-decorators.md
. PR #3492 by @jaystone776. - ๐ง Add new Translation tracking issues for German and Indonesian. PR #3718 by @tiangolo.
- ๐ Add Chinese translation for
docs/tutorial/dependencies/sub-dependencies.md
. PR #3491 by @jaystone776. - ๐ Add Portuguese translation for
docs/advanced/index.md
. PR #3460 by @ComicShrimp. - ๐ Portuguese translation of
docs/async.md
. PR #1330 by @Serrones. - ๐ Add French translation for
docs/async.md
. PR #3416 by @Smlep.
Internal¶
- โจ Add GitHub Action: Notify Translations. PR #3715 by @tiangolo.
- โจ Update computation of FastAPI People and sponsors. PR #3714 by @tiangolo.
- โจ Enable recent Material for MkDocs Insiders features. PR #3710 by @tiangolo.
- ๐ฅ Remove/clean extra imports from examples in docs for features. PR #3709 by @tiangolo.
- โ Update docs library to include sources in Markdown. PR #3648 by @tiangolo.
- โฌ Enable tests for Python 3.9. PR #2298 by @Kludex.
- ๐ฅ Update FastAPI People. PR #3642 by @github-actions[bot].
0.68.0¶
Features¶
- โจ Add support for extensions and updates to the OpenAPI schema in each path operation. New docs: FastAPI Path Operation Advanced Configuration - OpenAPI Extra. Initial PR #1922 by @edouardlp.
- โจ Add additional OpenAPI metadata parameters to
FastAPI
class, shown on the automatic API docs UI. New docs: Metadata and Docs URLs. Initial PR #1812 by @dkreeft. - โจ Add
description
parameter to all the security scheme classes, e.g.APIKeyQuery(name="key", description="A very cool API key")
. PR #1757 by @hylkepostma. - โจ Update OpenAPI models, supporting recursive models and extensions. PR #3628 by @tiangolo.
- โจ Import and re-export data structures from Starlette, used by Request properties, on
fastapi.datastructures
. Initial PR #1872 by @jamescurtin.
Docs¶
- ๐ Update docs about async and response-model with more gender neutral language. PR #1869 by @Edward-Knight.
Translations¶
- ๐ Add Russian translation for
docs/python-types.md
. PR #3039 by @dukkee. - ๐ Add Chinese translation for
docs/tutorial/dependencies/index.md
. PR #3489 by @jaystone776. - ๐ Add Russian translation for
docs/external-links.md
. PR #3036 by @dukkee. - ๐ Add Chinese translation for
docs/tutorial/dependencies/global-dependencies.md
. PR #3493 by @jaystone776. - ๐ Add Portuguese translation for
docs/deployment/versions.md
. PR #3618 by @lsglucas. - ๐ Add Japanese translation for
docs/tutorial/security/oauth2-jwt.md
. PR #3526 by @sattosan.
Internal¶
- โ
Add the
docs_src
directory to test coverage and update tests. Initial PR #1904 by @Kludex. - ๐ง Add new GitHub templates with forms for new issues. PR #3612 by @tiangolo.
- ๐ Add official FastAPI Twitter to docs: @fastapi. PR #3578 by @tiangolo.
0.67.0¶
Features¶
- โจ Add support for
dataclasses
in request bodies andresponse_model
. New documentation: Advanced User Guide - Using Dataclasses. PR #3577 by @tiangolo. - โจ Support
dataclasses
in responses. PR #3576 by @tiangolo, continuation from initial PR #2722 by @amitlissack.
Docs¶
- ๐ Add external link: How to Create A Fake Certificate Authority And Generate TLS Certs for FastAPI. PR #2839 by @aitoehigie.
- โ Fix code highlighted line in:
body-nested-models.md
. PR #3463 by @jaystone776. - โ Fix typo in
body-nested-models.md
. PR #3462 by @jaystone776. - โ Fix typo "might me" -> "might be" in
docs/en/docs/tutorial/schema-extra-example.md
. PR #3362 by @dbrakman. - ๐ Add external link: Building simple E-Commerce with NuxtJS and FastAPI. PR #3271 by @ShahriyarR.
- ๐ Add external link: Serve a machine learning model using Sklearn, FastAPI and Docker. PR #2974 by @rodrigo-arenas.
- โ๏ธ Fix typo on docstring in datastructures file. PR #2887 by @Kludex.
- ๐ Add External Link: Deploy FastAPI on Ubuntu and Serve using Caddy 2 Web Server. PR #3572 by @tiangolo.
- ๐ Add External Link, replaces #1898. PR #3571 by @tiangolo.
Internal¶
- ๐จ Improve style for sponsors, add radius border. PR #2388 by @Kludex.
- ๐ท Update GitHub Action latest-changes. PR #3574 by @tiangolo.
- ๐ท Update GitHub Action latest-changes. PR #3573 by @tiangolo.
- ๐ท Rename and clarify CI workflow job names. PR #3570 by @tiangolo.
- ๐ท Update GitHub Action latest-changes, strike 2 โพ. PR #3575 by @tiangolo.
- ๐ง Sort external links in docs to have the most recent at the top. PR #3568 by @tiangolo.
0.66.1¶
Translations¶
- ๐ Add basic setup for German translations. PR #3522 by @0x4Dark.
- ๐ Add Portuguese translation for
docs/tutorial/security/index.md
. PR #3507 by @oandersonmagalhaes. - ๐ Add Portuguese translation for
docs/deployment/index.md
. PR #3337 by @lsglucas.
Internal¶
- ๐ง Configure strict pytest options and update/refactor tests. Upgrade pytest to
>=6.2.4,<7.0.0
and pytest-cov to>=2.12.0,<3.0.0
. Initial PR #2790 by @graingert. - โฌ๏ธ Upgrade python-jose dependency to
>=3.3.0,<4.0.0
for tests. PR #3468 by @tiangolo.
0.66.0¶
Features¶
- โจ Allow setting the
response_class
toRedirectResponse
orFileResponse
and returning the URL from the function. New and updated docs are in the tutorial section Custom Response - HTML, Stream, File, others, in RedirectResponse and in FileResponse. PR #3457 by @tiangolo.
Fixes¶
- ๐ Fix include/exclude for dicts in
jsonable_encoder
. PR #2016 by @Rubikoid. - ๐ Support custom OpenAPI / JSON Schema fields in the generated output OpenAPI. PR #1429 by @jmagnusson.
Translations¶
- ๐ Add Spanish translation for
tutorial/query-params.md
. PR #2243 by @mariacamilagl. - ๐ Add Spanish translation for
advanced/response-directly.md
. PR #1253 by @jfunez. - ๐ Add Spanish translation for
advanced/additional-status-codes.md
. PR #1252 by @jfunez. - ๐ Add Spanish translation for
advanced/path-operation-advanced-configuration.md
. PR #1251 by @jfunez.
0.65.3¶
Fixes¶
- โป Assume request bodies contain JSON when no Content-Type header is provided. This fixes a breaking change introduced by 0.65.2 with PR #2118. It should allow upgrading FastAPI applications with clients that send JSON data without a
Content-Type
header. And there's still protection against CSRFs. PR #3456 by @tiangolo.
Translations¶
- ๐ Initialize Indonesian translations. PR #3014 by @pace-noge.
- ๐ Add Spanish translation of Tutorial - Path Parameters. PR #2219 by @mariacamilagl.
- ๐ Add Spanish translation of Tutorial - First Steps. PR #2208 by @mariacamilagl.
- ๐ Portuguese translation of Tutorial - Body - Fields. PR #3420 by @ComicShrimp.
- ๐ Add Chinese translation for Tutorial - Request - Forms - and - Files. PR #3249 by @jaystone776.
- ๐ Add Chinese translation for Tutorial - Handling - Errors. PR #3299 by @jaystone776.
- ๐ Add Chinese translation for Tutorial - Form - Data. PR #3248 by @jaystone776.
- ๐ Add Chinese translation for Tutorial - Body - Updates. PR #3237 by @jaystone776.
- ๐ Add Chinese translation for FastAPI People. PR #3112 by @hareru.
- ๐ Add French translation for Project Generation. PR #3197 by @Smlep.
- ๐ Add French translation for Python Types Intro. PR #3185 by @Smlep.
- ๐ Add French translation for External Links. PR #3103 by @Smlep.
- ๐ Add French translation for Alternatives, Inspiration and Comparisons. PR #3020 by @rjNemo.
- ๐ Fix Chinese translation code snippet mismatch in Tutorial - Python Types Intro. PR #2573 by @BoYanZh.
- ๐ Add Portuguese translation for Development Contributing. PR #1364 by @Serrones.
- ๐ Add Chinese translation for Tutorial - Request - Files. PR #3244 by @jaystone776.
Internal¶
- ๐ฅ Update FastAPI People. PR #3450 by @github-actions[bot].
- ๐ฅ Update FastAPI People. PR #3319 by @github-actions[bot].
- โฌ Upgrade docs development dependency on
typer-cli
to >=0.0.12 to fix conflicts. PR #3429 by @tiangolo.
0.65.2¶
Security fixes¶
- ๐ Check Content-Type request header before assuming JSON. Initial PR #2118 by @patrickkwang.
This change fixes a CSRF security vulnerability when using cookies for authentication in path operations with JSON payloads sent by browsers.
In versions lower than 0.65.2
, FastAPI would try to read the request payload as JSON even if the content-type
header sent was not set to application/json
or a compatible JSON media type (e.g. application/geo+json
).
So, a request with a content type of text/plain
containing JSON data would be accepted and the JSON data would be extracted.
But requests with content type text/plain
are exempt from CORS preflights, for being considered Simple requests. So, the browser would execute them right away including cookies, and the text content could be a JSON string that would be parsed and accepted by the FastAPI application.
See CVE-2021-32677 for more details.
Thanks to Dima Boger for the security report! ๐๐
Internal¶
- ๐ง Update sponsors badge, course bundle. PR #3340 by @tiangolo.
- ๐ง Add new gold sponsor Jina ๐. PR #3291 by @tiangolo.
- ๐ง Add new banner sponsor badge for FastAPI courses bundle. PR #3288 by @tiangolo.
- ๐ท Upgrade Issue Manager GitHub Action. PR #3236 by @tiangolo.
0.65.1¶
Security fixes¶
- ๐ Upgrade pydantic pin, to handle security vulnerability CVE-2021-29510. PR #3213 by @tiangolo.
0.65.0¶
Breaking Changes - Upgrade¶
- โฌ๏ธ Upgrade Starlette to
0.14.2
, including internalUJSONResponse
migrated from Starlette. This includes several bug fixes and features from Starlette. PR #2335 by @hanneskuettner.
Translations¶
- ๐ Initialize new language Polish for translations. PR #3170 by @neternefer.
Internal¶
- ๐ท Add GitHub Action cache to speed up CI installs. PR #3204 by @tiangolo.
- โฌ๏ธ Upgrade setup-python GitHub Action to v2. PR #3203 by @tiangolo.
- ๐ Fix docs script to generate a new translation language with
overrides
boilerplate. PR #3202 by @tiangolo. - โจ Add new Deta banner badge with new sponsorship tier ๐. PR #3194 by @tiangolo.
- ๐ฅ Update FastAPI People. PR #3189 by @github-actions[bot].
- ๐ Update FastAPI People to allow better debugging. PR #3188 by @tiangolo.
0.64.0¶
Features¶
- โจ Add support for adding multiple
examples
in request bodies and path, query, cookie, and header params. New docs: Declare Request Example Data. Initial PR #1267 by @austinorr.
Fixes¶
- ๐ Pin SQLAlchemy range for tests, as it doesn't use SemVer. PR #3001 by @tiangolo.
- ๐จ Add newly required type annotations for mypy. PR #2882 by @tiangolo.
- ๐จ Remove internal "type: ignore", now unnecessary. PR #2424 by @AsakuraMizu.
Docs¶
- ๐ Add link to article in Russian "FastAPI: ะทะฝะฐะบะพะผะธะผัั ั ััะตะนะผะฒะพัะบะพะผ". PR #2564 by @trkohler.
- ๐ Add external link to blog post "Authenticate Your FastAPI App with Auth0". PR #2172 by @dompatmore.
- ๐ Fix broken link to article: Machine learning model serving in Python using FastAPI and Streamlit. PR #2557 by @davidefiocco.
- ๐ Add FastAPI Medium Article: Deploy a dockerized FastAPI application to AWS. PR #2515 by @vjanz.
- โ Fix typo in Tutorial - Handling Errors. PR #2486 by @johnthagen.
- โ Fix typo in Security OAuth2 scopes. PR #2407 by @jugmac00.
- โ Fix typo/clarify docs for SQL (Relational) Databases. PR #2393 by @kangni.
- ๐ Add external link to "FastAPI for Flask Users". PR #2280 by @amitness.
Translations¶
- ๐ Fix Chinese translation of Tutorial - Query Parameters, remove obsolete content. PR #3051 by @louis70109.
- ๐ Add French translation for Tutorial - Background Tasks. PR #3098 by @Smlep.
- ๐ Fix Korean translation for docs/ko/docs/index.md. PR #3159 by @SueNaEunYang.
- ๐ Add Korean translation for Tutorial - Query Parameters. PR #2390 by @hard-coders.
- ๐ Add French translation for FastAPI People. PR #2232 by @JulianMaurin.
- ๐ Add Korean translation for Tutorial - Path Parameters. PR #2355 by @hard-coders.
- ๐ Add French translation for Features. PR #2157 by @Jefidev.
- ๐ฅ Update FastAPI People. PR #3031 by @github-actions[bot].
- ๐ Add Chinese translation for Tutorial - Debugging. PR #2737 by @blt232018.
- ๐ Add Chinese translation for Tutorial - Security - OAuth2 with Password (and hashing), Bearer with JWT tokens. PR #2642 by @waynerv.
- ๐ Add Korean translation for Tutorial - Header Parameters. PR #2589 by @mode9.
- ๐ Add Chinese translation for Tutorial - Metadata and Docs URLs. PR #2559 by @blt232018.
- ๐ Add Korean translation for Tutorial - First Steps. PR #2323 by @hard-coders.
- ๐ Add Chinese translation for Tutorial - CORS (Cross-Origin Resource Sharing). PR #2540 by @blt232018.
- ๐ Add Chinese translation for Tutorial - Middleware. PR #2334 by @lpdswing.
- ๐ Add Korean translation for Tutorial - Intro. PR #2317 by @hard-coders.
- ๐ Add Chinese translation for Tutorial - Bigger Applications - Multiple Files. PR #2453 by @waynerv.
- ๐ Add Chinese translation for Tutorial - Security - Security Intro. PR #2443 by @waynerv.
- ๐ Add Chinese translation for Tutorial - Header Parameters. PR #2412 by @maoyibo.
- ๐ Add Chinese translation for Tutorial - Extra Data Types. PR #2410 by @maoyibo.
- ๐ Add Japanese translation for Deployment - Docker. PR #2312 by @tokusumi.
- ๐ Add Japanese translation for Deployment - Versions. PR #2310 by @tokusumi.
- ๐ Add Chinese translation for Tutorial - Cookie Parameters. PR #2261 by @alicrazy1947.
- ๐ Add Japanese translation for Tutorial - Static files. PR #2260 by @tokusumi.
- ๐ Add Japanese translation for Tutorial - Testing. PR #2259 by @tokusumi.
- ๐ Add Japanese translation for Tutorial - Debugging. PR #2256 by @tokusumi.
- ๐ Add Japanese translation for Tutorial - Middleware. PR #2255 by @tokusumi.
- ๐ Add Japanese translation for Concurrency and async / await. PR #2058 by @tokusumi.
- ๐ Add Chinese translation for Tutorial - Security - Simple OAuth2 with Password and Bearer. PR #2514 by @waynerv.
- ๐ Add Japanese translation for Deployment - Deta. PR #2314 by @tokusumi.
- ๐ Add Chinese translation for Tutorial - Security - Get Current User. PR #2474 by @waynerv.
- ๐ Add Japanese translation for Deployment - Manually. PR #2313 by @tokusumi.
- ๐ Add Japanese translation for Deployment - Intro. PR #2309 by @tokusumi.
- ๐ Add Japanese translation for FastAPI People. PR #2254 by @tokusumi.
- ๐ Add Japanese translation for Advanced - Path Operation Advanced Configuration. PR #2124 by @Attsun1031.
- ๐ Add Japanese translation for External Links. PR #2070 by @tokusumi.
- ๐ Add Japanese translation for Tutorial - Body - Updates. PR #1956 by @SwftAlpc.
- ๐ Add Japanese translation for Tutorial - Form Data. PR #1943 by @SwftAlpc.
- ๐ Add Japanese translation for Tutorial - Cookie Parameters. PR #1933 by @SwftAlpc.
Internal¶
- ๐ง Update top banner, point to newsletter. PR #3003 by @tiangolo.
- ๐ง Disable sponsor WeTransfer. PR #3002 by @tiangolo.
- ๐ฅ Update FastAPI People. PR #2880 by @github-actions[bot].
- ๐ฅ Update FastAPI People. PR #2739 by @github-actions[bot].
- ๐ง Add new Gold Sponsor Talk Python ๐. PR #2673 by @tiangolo.
- ๐ง Add new Gold Sponsor vim.so ๐. PR #2669 by @tiangolo.
- ๐ง Add FastAPI user survey banner. PR #2623 by @tiangolo.
- ๐ง Add new Bronze Sponsor(s) ๐ฅ๐. PR #2622 by @tiangolo.
- ๐ Update social links: add Discord, fix GitHub. PR #2621 by @tiangolo.
- ๐ง Update FastAPI People GitHub Sponsors order. PR #2620 by @tiangolo.
- ๐ง Update InvestSuite sponsor data. PR #2608 by @tiangolo.
- ๐ฅ Update FastAPI People. PR #2590 by @github-actions[bot].
0.63.0¶
Features¶
- โจ Improve type annotations, add support for mypy --strict, internally and for external packages. PR #2547 by @tiangolo.
Breaking changes¶
- โฌ๏ธ Upgrade Uvicorn when installing
fastapi[all]
to the latest version includinguvloop
, the new range isuvicorn[standard] >=0.12.0,<0.14.0
. PR #2548 by @tiangolo.
Fixes¶
- ๐ PR #2547 (read above) also fixes some false-positive mypy errors with
callbacks
parameters and when using theOAuth2
class.
Docs¶
- ๐ Update Uvicorn installation instructions to use uvicorn[standard] (includes uvloop). PR #2543 by @tiangolo.
- ๐ Update title for Deta tutorial. PR #2466 by @tiangolo.
- ๐ฅ Update FastAPI People. PR #2454 by @github-actions[bot].
Translations¶
- ๐ Add docs lang selector widget. PR #2542 by @tiangolo.
- ๐ Add Chinese translation for Tutorial - Response Status Code. PR #2442 by @waynerv.
- ๐ Start translation of the documentation for the Albanian language. PR #2516 by @vjanz.
- ๐ Add Chinese translation for Tutorial - Extra Models. PR #2416 by @waynerv.
- ๐ Add Chinese translation for Tutorial - Response Model. PR #2414 by @waynerv.
- ๐ Add Chinese translation for Tutorial - Schema Extra Example. PR #2411 by @maoyibo.
- ๐ Add Korean translation for Index. PR #2192 by @hard-coders.
- ๐ Add Japanese translation for Advanced User Guide - Additional Status Codes. PR #2145 by @Attsun1031.
Internal¶
- ๐ Fix docs overrides directory for translations. PR #2541 by @tiangolo.
- โ Remove Typer as a docs building dependency (covered by typer-cli) to fix pip resolver conflicts. PR #2539 by @tiangolo.
- โจ Add newsletter: FastAPI and friends. PR #2509 by @tiangolo.
- โจ Add new Gold Sponsor: InvestSuite ๐. PR #2508 by @tiangolo.
- ๐ง Add issue template configs. PR #2476 by @tiangolo.
0.62.0¶
Features¶
Up to now, for several options, the only way to apply them to a group of path operations was in include_router
. That works well, but the call to app.include_router()
or router.include_router()
is normally done in another file.
That means that, for example, to apply authentication to all the path operations in a router it would end up being done in a different file, instead of keeping related logic together.
Setting options in include_router
still makes sense in some cases, for example, to override or increase configurations from a third party router included in an app. But in a router that is part of a bigger application, it would probably make more sense to add those settings when creating the APIRouter
.
In FastAPI
This allows setting the (mostly new) parameters (additionally to the already existing parameters):
default_response_class
: updated to handle defaults inAPIRouter
andinclude_router
.dependencies
: to include โจ top-level dependencies โจ that apply to the whole application. E.g. to add global authentication.callbacks
: OpenAPI callbacks that apply to all the path operations.deprecated
: to mark all the path operations as deprecated. ๐คทinclude_in_schema
: to allow excluding all the path operations from the OpenAPI schema.responses
: OpenAPI responses that apply to all the path operations.
For example:
from fastapi import FastAPI, Depends
async def some_dependency():
return
app = FastAPI(dependencies=[Depends(some_dependency)])
In APIRouter
This allows setting the (mostly new) parameters (additionally to the already existing parameters):
default_response_class
: updated to handle defaults inAPIRouter
andinclude_router
. For example, it's not needed to set it explicitly when creating callbacks.dependencies
: to include โจ router-level dependencies โจ that apply to all the path operations in a router. Up to now, this was only possible withinclude_router
.callbacks
: OpenAPI callbacks that apply to all the path operations in this router.deprecated
: to mark all the path operations in a router as deprecated.include_in_schema
: to allow excluding all the path operations in a router from the OpenAPI schema.responses
: OpenAPI responses that apply to all the path operations in a router.prefix
: to set the path prefix for a router. Up to now, this was only possible when callinginclude_router
.tags
: OpenAPI tags to apply to all the path operations in this router.
For example:
from fastapi import APIRouter, Depends
async def some_dependency():
return
router = APIRouter(prefix="/users", dependencies=[Depends(some_dependency)])
In include_router
Most of these settings are now supported in APIRouter
, which normally lives closer to the related code, so it is recommended to use APIRouter
when possible.
But include_router
is still useful to, for example, adding options (like dependencies
, prefix
, and tags
) when including a third party router, or a generic router that is shared between several projects.
This PR allows setting the (mostly new) parameters (additionally to the already existing parameters):
default_response_class
: updated to handle defaults inAPIRouter
andFastAPI
.deprecated
: to mark all the path operations in a router as deprecated in OpenAPI.include_in_schema
: to allow disabling all the path operations from showing in the OpenAPI schema.callbacks
: OpenAPI callbacks that apply to all the path operations in this router.
Note: all the previous parameters are still there, so it's still possible to declare dependencies
in include_router
.
Breaking Changes¶
- PR #2434 includes several improvements that shouldn't affect normal use cases, but could affect in advanced scenarios:
- If you are testing the generated OpenAPI (you shouldn't, FastAPI already tests it extensively for you): the order for
tags
ininclude_router
and path operations was updated for consistency, but it's a simple order change. - If you have advanced custom logic to access each route's
route.response_class
, or therouter.default_response_class
, or theapp.default_response_class
: the default value forresponse_class
inAPIRoute
and fordefault_response_class
inAPIRouter
andFastAPI
is now aDefaultPlaceholder
used internally to handle and solve default values and overrides. The actual response class inside theDefaultPlaceholder
is available atroute.response_class.value
.
- If you are testing the generated OpenAPI (you shouldn't, FastAPI already tests it extensively for you): the order for
Docs¶
-
PR #2434 (above) includes new or updated docs:
-
๐ Add FastAPI monitoring blog post to External Links. PR #2324 by @louisguitton.
- โ๏ธ Fix typo in Deta tutorial. PR #2320 by @tiangolo.
- โจ Add Discord chat. PR #2322 by @tiangolo.
- ๐ Fix image links for sponsors. PR #2304 by @tiangolo.
Translations¶
- ๐ Add Japanese translation for Advanced - Custom Response. PR #2193 by @Attsun1031.
- ๐ Add Chinese translation for Benchmarks. PR #2119 by @spaceack.
- ๐ Add Chinese translation for Tutorial - Body - Nested Models. PR #1609 by @waynerv.
- ๐ Add Chinese translation for Advanced - Custom Response. PR #1459 by @RunningIkkyu.
- ๐ Add Chinese translation for Advanced - Return a Response Directly. PR #1452 by @RunningIkkyu.
- ๐ Add Chinese translation for Advanced - Additional Status Codes. PR #1451 by @RunningIkkyu.
- ๐ Add Chinese translation for Advanced - Path Operation Advanced Configuration. PR #1447 by @RunningIkkyu.
- ๐ Add Chinese translation for Advanced User Guide - Intro. PR #1445 by @RunningIkkyu.
Internal¶
- ๐ง Update TestDriven link to course in sponsors section. PR #2435 by @tiangolo.
- ๐ฑ Update sponsor logos. PR #2418 by @tiangolo.
- ๐ Fix disabling install of Material for MkDocs Insiders in forks, strike 1 โพ. PR #2340 by @tiangolo.
- ๐ Fix disabling Material for MkDocs Insiders install in forks. PR #2339 by @tiangolo.
- โจ Add silver sponsor WeTransfer. PR #2338 by @tiangolo.
- โจ Set up and enable Material for MkDocs Insiders for the docs. PR #2325 by @tiangolo.
0.61.2¶
Fixes¶
- ๐ Relax Swagger UI version pin. PR #2089 by @jmriebold.
- ๐ Fix bug overriding custom HTTPException and RequestValidationError from exception_handlers. PR #1924 by @uriyyo.
- โ๏ธ Fix typo on dependencies utils and cleanup unused variable. PR #1912 by @Kludex.
Docs¶
- โ๏ธ Fix typo in Tutorial - Path Parameters. PR #2231 by @mariacamilagl.
- โ Fix a stylistic error in docs. PR #2206 by @ddobrinskiy.
- โ Fix capitalizaiton typo in docs. PR #2204 by @imba-tjd.
- โ Fix typo in docs. PR #2179 by @ammarasmro.
- ๐ Update/fix links in docs to use HTTPS. PR #2165 by @imba-tjd.
- โ Fix typos and add rewording in docs. PR #2159 by @nukopy.
- ๐ Fix code consistency in examples for Tutorial - User Guide - Path Parameters. PR #2158 by @nukopy.
- ๐ Fix renamed parameter
content_type
typo. PR #2135 by @TeoZosa. - โ Fix minor typos in docs. PR #2122 by @TeoZosa.
- โ Fix typos in docs and source examples. PR #2102 by @AdrianDeAnda.
- โ Fix incorrect Celery URLs in docs. PR #2100 by @CircleOnCircles.
- ๐ Simplify intro to Python Types, all currently supported Python versions include type hints ๐. PR #2085 by @ninjaaron.
- ๐ Fix example code with sets in Tutorial - Body - Nested Models 3. PR #2054 by @hitrust.
- ๐ Fix example code with sets in Tutorial - Body - Nested Models 2. PR #2053 by @hitrust.
- ๐ Fix example code with sets in Tutorial - Body - Nested Models. PR #2052 by @hitrust.
- โ Fix typo in Benchmarks. PR #1995 by @AlejoAsd.
- ๐ Add note in CORS tutorial about allow_origins with ["*"] and allow_credentials. PR #1895 by @dsmurrell.
- ๐ Add deployment to Deta, the first gold sponsor ๐. PR #2303 by @tiangolo.
- ๐ฅ Update FastAPI People. PR #2282 by @github-actions[bot].
- โ๏ธ Fix uppercase in Tutorial - Query parameters. PR #2245 by @mariacamilagl.
- ๐ Add articles to External Links. PR #2247 by @tiangolo.
- โ Fix typo in Spanish tutorial index. PR #2020 by @aviloncho.
Translations¶
- ๐ Add Japanese translation for Advanced Tutorial - Response Directly. PR #2191 by @Attsun1031.
- ๐ Add Japanese translation for Tutorial - Security - First Steps. PR #2153 by @komtaki.
- ๐ Add Japanese translation for Tutorial - Query Parameters and String Validations. PR #1901 by @SwftAlpc.
- ๐ Add Portuguese translation for External Links. PR #1443 by @Serrones.
- ๐ Add Japanese translation for Tutorial - CORS. PR #2125 by @tokusumi.
- ๐ Add Japanese translation for Contributing. PR #2067 by @komtaki.
- ๐ Add Japanese translation for Project Generation. PR #2050 by @tokusumi.
- ๐ Add Japanese translation for Alternatives. PR #2043 by @Attsun1031.
- ๐ Add Japanese translation for History Design and Future. PR #2002 by @komtaki.
- ๐ Add Japanese translation for Benchmarks. PR #1992 by @komtaki.
- ๐ Add Japanese translation for Tutorial - Header Parameters. PR #1935 by @SwftAlpc.
- ๐ Add Portuguese translation for Tutorial - First Steps. PR #1861 by @jessicapaz.
- ๐ Add Portuguese translation for Python Types. PR #1796 by @izaguerreiro.
- ๐ Add Japanese translation for Help FastAPI. PR #1692 by @tokusumi.
- ๐ Add Japanese translation for Tutorial - Body. PR #1683 by @tokusumi.
- ๐ Add Japanese translation for Tutorial - Query Params. PR #1674 by @tokusumi.
- ๐ Add Japanese translation for tutorial/path-params.md. PR #1671 by @tokusumi.
- ๐ Add Japanese translation for tutorial/first-steps.md. PR #1658 by @tokusumi.
- ๐ Add Japanese translation for tutorial/index.md. PR #1656 by @tokusumi.
- ๐ Add translation to Portuguese for Project Generation. PR #1602 by @Serrones.
- ๐ Add Japanese translation for Features. PR #1625 by @tokusumi.
- ๐ Initialize new language Korean for translations. PR #2018 by @hard-coders.
- ๐ Add Portuguese translation of Deployment. PR #1374 by @Serrones.
Internal¶
- ๐ฅ Cleanup after upgrade for Docs Previews GitHub Action. PR #2248 by @tiangolo.
- ๐ Fix CI docs preview, unzip docs. PR #2246 by @tiangolo.
- โจ Add instant docs deploy previews for PRs from forks. PR #2244 by @tiangolo.
- โก๏ธ Build docs for languages in parallel in subprocesses to speed up CI. PR #2242 by @tiangolo.
- ๐ Fix docs order generation for partial translations. PR #2238 by @tiangolo.
- ๐ฅ Update FastAPI People. PR #2202 by @github-actions[bot].
- โป๏ธ Update FastAPI People GitHub Action to send the PR as github-actions. PR #2201 by @tiangolo.
- ๐ง Update FastAPI People GitHub Action config, run monthly. PR #2199 by @tiangolo.
- ๐ Fix FastAPI People GitHub Action Docker dependency, strike 1 โพ. PR #2198 by @tiangolo.
- ๐ Fix FastAPI People GitHub Action Docker dependencies. PR #2197 by @tiangolo.
- ๐ Fix FastAPI People GitHub Action when there's nothing to change. PR #2196 by @tiangolo.
- ๐ฅ Add new section FastAPI People. PR #2195 by @tiangolo.
- โฌ๏ธ Upgrade GitHub Action Latest Changes. PR #2190 by @tiangolo.
- โฌ๏ธ Upgrade GitHub Action Label Approved. PR #2189 by @tiangolo.
- ๐ง Update GitHub Action Label Approved, run at 12:00. PR #2185 by @tiangolo.
- ๐ท Upgrade GitHub Action Latest Changes. PR #2184 by @tiangolo.
- ๐ท Set GitHub Action Label Approved to run daily, not every minute. PR #2163 by @tiangolo.
- ๐ฅ Remove pr-approvals GitHub Action as it's not compatible with forks. Use the new one. PR #2162 by @tiangolo.
- ๐ท Add GitHub Action Latest Changes. PR #2160.
- ๐ท Add GitHub Action Label Approved. PR #2161.
0.61.1¶
Fixes¶
- Fix issues using
jsonable_encoder
with SQLAlchemy models directly. PR #1987.
Docs¶
- Fix typo in NoSQL docs. PR #1980 by @facundojmaero.
Translations¶
- Add translation for main page to Japanese PR #1571 by @ryuckel.
- Initialize French translations. PR #1975 by @JulianMaurin-BM.
- Initialize Turkish translations. PR #1905 by @ycd.
Internal¶
0.61.0¶
Features¶
- Add support for injecting
HTTPConnection
(asRequest
andWebSocket
). Useful for sharing app state in dependencies. PR #1827 by @nsidnev. - Export
WebSocketDisconnect
and add example handling WebSocket disconnections to docs. PR #1822 by @rkbeatss.
Breaking Changes¶
- Require Pydantic >
1.0.0
.- Remove support for deprecated Pydantic
0.32.2
. This improves maintainability and allows new features. - In
FastAPI
andAPIRouter
:- Remove path operation decorators related/deprecated parameter
response_model_skip_defaults
(useresponse_model_exclude_unset
instead). - Change path operation decorators parameter default for
response_model_exclude
fromset()
toNone
(as is in Pydantic).
- Remove path operation decorators related/deprecated parameter
- In
encoders.jsonable_encoder
:- Remove deprecated
skip_defaults
, use insteadexclude_unset
. - Set default of
exclude
fromset()
toNone
(as is in Pydantic).
- Remove deprecated
- PR #1862.
- Remove support for deprecated Pydantic
- In
encoders.jsonable_encoder
remove parametersqlalchemy_safe
.- It was an early hack to allow returning SQLAlchemy models, but it was never documented, and the recommended way is using Pydantic's
orm_mode
as described in the tutorial: SQL (Relational) Databases. - PR #1864.
- It was an early hack to allow returning SQLAlchemy models, but it was never documented, and the recommended way is using Pydantic's
Docs¶
- Add link to the course by TestDriven.io: Test-Driven Development with FastAPI and Docker. PR #1860.
- Fix empty log message in docs example about handling errors. PR #1815 by @manlix.
- Reword text to reduce ambiguity while not being gender-specific. PR #1824 by @Mause.
Internal¶
- Add Flake8 linting. Original PR #1774 by @MashhadiNima.
- Disable Gitter bot, as it's currently broken, and Gitter's response doesn't show the problem. PR #1853.
0.60.2¶
- Fix typo in docs for query parameters. PR #1832 by @ycd.
- Add docs about Async Tests. PR #1619 by @empicano.
- Raise an exception when using form data (
Form
,File
) without havingpython-multipart
installed.- Up to now the application would run, and raise an exception only when receiving a request with form data, the new behavior, raising early, will prevent from deploying applications with broken dependencies.
- It also detects if the correct package
python-multipart
is installed instead of the incorrectmultipart
(both importable asmultipart
). - PR #1851 based on original PR #1627 by @chrisngyn, @YKo20010, @kx-chen.
- Re-enable Gitter releases bot. PR #1831.
- Add link to async SQL databases tutorial from main SQL tutorial. PR #1813 by @short2strings.
- Fix typo in tutorial about behind a proxy. PR #1807 by @toidi.
- Fix typo in Portuguese docs. PR #1795 by @izaguerreiro.
- Add translations setup for Ukrainian. PR #1830.
- Add external link Build And Host Fast Data Science Applications Using FastAPI. PR #1786 by @Kludex.
- Fix encoding of Pydantic models that inherit from others models with custom
json_encoders
. PR #1769 by @henrybetts. - Simplify and improve
jsonable_encoder
. PR #1754 by @MashhadiNima. - Simplify internal code syntax in several points. PR #1753 by @uriyyo.
- Improve internal typing, declare
Optional
parameters. PR #1731 by @MashhadiNima. - Add external link Deploy FastAPI on Azure App Service to docs. PR #1726 by @windson.
- Add link to Starlette docs about WebSocket testing. PR #1717 by @hellocoldworld.
- Refactor generating dependant, merge for loops. PR #1714 by @Bloodielie.
- Update example for templates with Jinja to include HTML media type. PR #1690 by @frafra.
- Fix typos in docs for security. PR #1678 by @nilslindemann.
- Fix typos in docs for dependencies. PR #1675 by @nilslindemann.
- Fix type annotation for
**extra
parameters inFastAPI
. PR #1659 by @bharel. - Bump MkDocs Material to fix docs in browsers with dark mode. PR #1789 by @adriencaccia.
- Remove docs preview comment from each commit. PR #1826.
- Update GitHub context extraction for Gitter notification bot. PR #1766.
0.60.1¶
- Add debugging logs for GitHub actions to introspect GitHub hidden context. PR #1764.
- Use OS preference theme for online docs. PR #1760 by @adriencaccia.
- Upgrade Starlette to version
0.13.6
to handle a vulnerability when using static files in Windows. PR #1759 by @jamesag26. - Pin Swagger UI temporarily, waiting for a fix for swagger-api/swagger-ui#6249. PR #1763.
- Update GitHub Actions, use commit from PR for docs preview, not commit from pre-merge. PR #1761.
- Update GitHub Actions, refactor Gitter bot. PR #1746.
0.60.0¶
- Add GitHub Action to watch for missing preview docs and trigger a preview deploy. PR #1740.
- Add custom GitHub Action to get artifact with docs preview. PR #1739.
- Add new GitHub Actions to preview docs from PRs. PR #1738.
- Add XML test coverage to support GitHub Actions. PR #1737.
- Update badges and remove Travis now that GitHub Actions is the main CI. PR #1736.
- Add GitHub Actions for CI, move from Travis. PR #1735.
- Add support for adding OpenAPI schema for GET requests with a body. PR #1626 by @victorphoenix3.
0.59.0¶
- Fix typo in docstring for OAuth2 utils. PR #1621 by @tomarv2.
- Update JWT docs to use Python-jose instead of PyJWT. Initial PR #1610 by @asheux.
- Fix/re-enable search bar in docs. PR #1703.
- Auto-generate a "server" in OpenAPI
servers
when there's aroot_path
instead of prefixing all thepaths
:- Add a new parameter for
FastAPI
classes:root_path_in_servers
to disable the auto-generation ofservers
. - New docs about
root_path
andservers
in Additional Servers. - Update OAuth2 examples to use a relative URL for
tokenUrl="token"
to make sure those examples keep working as-is even when behind a reverse proxy. - Initial PR #1596 by @rkbeatss.
- Add a new parameter for
- Fix typo/link in External Links. PR #1702.
- Update handling of External Links to use a data file and allow translating the headers without becoming obsolete quickly when new links are added. PR #https://github.com/tiangolo/fastapi/pull/1701.
- Add external link Machine learning model serving in Python using FastAPI and Streamlit to docs. PR #1669 by @davidefiocco.
- Add note in docs on order in Pydantic Unions. PR #1591 by @kbanc.
- Improve support for tests in editor. PR #1699.
- Pin dependencies. PR #1697.
- Update isort to version 5.x.x. PR #1670 by @asheux.
0.58.1¶
- Add link in docs to Pydantic data types. PR #1612 by @tayoogunbiyi.
- Fix link in warning logs for
openapi_prefix
. PR #1611 by @bavaria95. - Fix bad link in docs. PR #1603 by @molto0504.
- Add Vim temporary files to
.gitignore
for contributors using Vim. PR #1590 by @asheux. - Fix typo in docs for sub-applications. PR #1578 by @schlpbch.
- Use
Optional
in all the examples in the docs. Original PR #1574 by @chrisngyn, @kx-chen, @YKo20010. Updated and merged PR #1644. - Update tests and handling of
response_model_by_alias
. PR #1642. - Add translation to Chinese for Body - Fields - ่ฏทๆฑไฝ - ๅญๆฎต. PR #1569 by @waynerv.
- Update Chinese translation of main page. PR #1564 by @waynerv.
- Add translation to Chinese for Body - Multiple Parameters - ่ฏทๆฑไฝ - ๅคไธชๅๆฐ. PR #1532 by @waynerv.
- Add translation to Chinese for Path Parameters and Numeric Validations - ่ทฏๅพๅๆฐๅๆฐๅผๆ ก้ช. PR #1506 by @waynerv.
- Add GitHub action to auto-label approved PRs (mainly for translations). PR #1638.
0.58.0¶
- Deep merge OpenAPI responses to preserve all the additional metadata. PR #1577.
- Mention in docs that only main app events are run (not sub-apps). PR #1554 by @amacfie.
- Fix body validation error response, do not include body variable when it is not embedded. PR #1553 by @amacfie.
- Fix testing OAuth2 security scopes when using dependency overrides. PR #1549 by @amacfie.
- Fix Model for JSON Schema keyword
not
as a JSON Schema instead of a list. PR #1548 by @v-do. - Add support for OpenAPI
servers
. PR #1547 by @mikaello.
0.57.0¶
- Remove broken link from "External Links". PR #1565 by @victorphoenix3.
- Update/fix docs for WebSockets with dependencies. Original PR #1540 by @ChihSeanHsu.
- Add support for Python's
http.HTTPStatus
instatus_code
parameters. PR #1534 by @retnikt. - When using Pydantic models with
__root__
, use the internal value injsonable_encoder
. PR #1524 by @patrickkwang. - Update docs for path parameters. PR #1521 by @yankeexe.
- Update docs for first steps, links and rewording. PR #1518 by @yankeexe.
- Enable
showCommonExtensions
in Swagger UI to show additional validations likemaxLength
, etc. PR #1466 by @TiewKH. - Make
OAuth2PasswordRequestFormStrict
importable directly fromfastapi.security
. PR #1462 by @RichardHoekstra. - Add docs about Default response class. PR #1455 by @TezRomacH.
- Add note in docs about additional parameters
response_model_exclude_defaults
andresponse_model_exclude_none
in Response Model. PR #1427 by @wshayes. - Add note about PyCharm Pydantic plugin to docs. PR #1420 by @koxudaxi.
- Update and clarify testing function name. PR #1395 by @chenl.
- Fix duplicated headers created by indirect dependencies that use the request directly. PR #1386 by @obataku from tests by @scottsmith2gmail.
- Upgrade Starlette version to
0.13.4
. PR #1361 by @rushton. - Improve error handling and feedback for requests with invalid JSON. PR #1354 by @aviramha.
- Add support for declaring metadata for tags in OpenAPI. New docs at Tutorial - Metadata and Docs URLs - Metadata for tags. PR #1348 by @thomas-maschler.
- Add basic setup for Russian translations. PR #1566.
- Remove obsolete Chinese articles after adding official community translations. PR #1510 by @waynerv.
- Add
__repr__
for path operation function parameter helpers (likeQuery
,Depends
, etc) to simplify debugging. PR #1560 by @rkbeatss and @victorphoenix3.
0.56.1¶
- Add link to advanced docs from tutorial. PR #1512 by @kx-chen.
- Remove internal unnecessary f-strings. PR #1526 by @kotamatsuoka.
- Add translation to Chinese for Query Parameters and String Validations - ๆฅ่ฏขๅๆฐๅๅญ็ฌฆไธฒๆ ก้ช. PR #1500 by @waynerv.
- Add translation to Chinese for Request Body - ่ฏทๆฑไฝ. PR #1492 by @waynerv.
- Add translation to Chinese for Help FastAPI - Get Help - ๅธฎๅฉ FastAPI - ่ทๅๅธฎๅฉ. PR #1465 by @waynerv.
- Add translation to Chinese for Query Parameters - ๆฅ่ฏขๅๆฐ. PR #1454 by @waynerv.
- Add translation to Chinese for Contributing - ๅผๅ - ่ดก็ฎ. PR #1460 by @waynerv.
- Add translation to Chinese for Path Parameters - ่ทฏๅพๅๆฐ. PR #1453 by @waynerv.
- Add official Microsoft project generator for serving spaCy with FastAPI and Azure Cognitive Skills to Project Generators. PR #1390 by @kabirkhan.
- Update docs in Python Types Intro to include info about
Optional
. Original PR #1377 by @yaegassy. - Fix support for callable class dependencies with
yield
. PR #1365 by @mrosales. - Fix/remove incorrect error logging when a client sends invalid payloads. PR #1351 by @dbanty.
- Add translation to Chinese for First Steps - ็ฌฌไธๆญฅ. PR #1323 by @waynerv.
- Fix generating OpenAPI for apps using callbacks with routers including Pydantic models. PR #1322 by @nsidnev.
- Optimize internal regex performance in
get_path_param_names()
. PR #1243 by @heckad. - Remove
*,
from functions in docs where it's not needed. PR #1239 by @pankaj-giri. - Start translations for Italian. PR #1557 by @csr.
0.56.0¶
- Add support for ASGI
root_path
:- Use
root_path
internally for mounted applications, so that OpenAPI and the docs UI works automatically without extra configurations and parameters. - Add new
root_path
parameter forFastAPI
applications to provide it in cases where it can be set with the command line (e.g. for Uvicorn and Hypercorn, with the parameter--root-path
). - Deprecate
openapi_prefix
parameter in favor of the newroot_path
parameter. - Add new/updated docs for Sub Applications - Mounts, without
openapi_prefix
(as it is now handled automatically). - Add new/updated docs for Behind a Proxy, including how to setup a local testing proxy with Traefik and using
root_path
. - Update docs for Extending OpenAPI with the new
openapi_prefix
parameter passed (internally generated fromroot_path
). - Original PR #1199 by @iksteen.
- Use
- Update new issue templates and docs: Help FastAPI - Get Help. PR #1531.
- Update GitHub action issue-manager. PR #1520.
- Add new links:
- English articles:
- Real-time Notifications with Python and Postgres by Guillermo Cruz.
- Microservice in Python using FastAPI by Paurakh Sharma Humagain.
- Build simple API service with Python FastAPI โ Part 1 by cuongld2.
- FastAPI + Zeit.co = ๐ by Paul Sec.
- Build a web API from scratch with FastAPI - the workshop by Sebastiรกn Ramรญrez (tiangolo).
- Build a Secure Twilio Webhook with Python and FastAPI by Twilio.
- Using FastAPI with Django by Stavros Korokithakis.
- Introducing Dispatch by Netflix.
- Podcasts:
- Talks:
- PR #1467.
- English articles:
- Add translation to Chinese for Python Types Intro - Python ็ฑปๅๆ็คบ็ฎไป. PR #1197 by @waynerv.
0.55.1¶
- Fix handling of enums with their own schema in path parameters. To support pydantic/pydantic#1432 in FastAPI. PR #1463.
0.55.0¶
- Allow enums to allow them to have their own schemas in OpenAPI. To support pydantic/pydantic#1432 in FastAPI. PR #1461.
- Add links for funding through GitHub sponsors. PR #1425.
- Update issue template for for questions. PR #1344 by @retnikt.
- Update warning about storing passwords in docs. PR #1336 by @skorokithakis.
- Fix typo. PR #1326 by @chenl.
- Add translation to Portuguese for Alternatives, Inspiration and Comparisons - Alternativas, Inspiraรงรฃo e Comparaรงรตes. PR #1325 by @Serrones.
- Fix 2 typos in docs. PR #1324 by @waynerv.
- Update CORS docs, fix correct default of
max_age=600
. PR #1301 by @derekbekoe. - Add translation of main page to Portuguese. PR #1300 by @Serrones.
- Re-word and clarify docs for extra info in fields. PR #1299 by @chris-allnutt.
- Make sure the
*
in short features in the docs is consistent (after.
) in all languages. PR #1424. - Update order of execution for
get_db
in SQLAlchemy tutorial. PR #1293 by @bcb. - Fix typos in Async docs. PR #1423.
0.54.2¶
- Add translation to Spanish for Concurrency and async / await - Concurrencia y async / await. PR #1290 by @alvaropernas.
- Remove obsolete vote link. PR #1289 by @donhui.
- Allow disabling docs UIs by just disabling OpenAPI with
openapi_url=None
. New example in docs: Advanced: Conditional OpenAPI. PR #1421. - Add translation to Portuguese for Benchmarks - Comparaรงรตes. PR #1274 by @Serrones.
- Add translation to Portuguese for Tutorial - User Guide - Intro - Tutorial - Guia de Usuรกrio - Introduรงรฃo. PR #1259 by @marcosmmb.
- Allow using Unicode in MkDocs for translations. PR #1419.
- Add translation to Spanish for Advanced User Guide - Intro - Guรญa de Usuario Avanzada - Introducciรณn. PR #1250 by @jfunez.
- Add translation to Portuguese for History, Design and Future - Histรณria, Design e Futuro. PR #1249 by @marcosmmb.
- Add translation to Portuguese for Features - Recursos. PR #1248 by @marcosmmb.
- Add translation to Spanish for Tutorial - User Guide - Intro - Tutorial - Guรญa de Usuario - Introducciรณn. PR #1244 by @MartinEliasQ.
- Add translation to Chinese for Deployment - ้จ็ฝฒ. PR #1203 by @RunningIkkyu.
- Add translation to Chinese for Tutorial - User Guide - Intro - ๆ็จ - ็จๆทๆๅ - ็ฎไป. PR #1202 by @waynerv.
- Add translation to Chinese for Features - ็นๆง. PR #1192 by @Dustyposa.
- Add translation for main page to Chinese PR #1191 by @waynerv.
- Update docs for project generation. PR #1287.
- Add Spanish translation for Introducciรณn a los Tipos de Python (Python Types Intro). PR #1237 by @mariacamilagl.
- Add Spanish translation for Caracterรญsticas (Features). PR #1220 by @mariacamilagl.
0.54.1¶
- Update database test setup. PR #1226.
- Improve test debugging by showing response text in failing tests. PR #1222 by @samuelcolvin.
0.54.0¶
- Fix grammatical mistakes in async docs. PR #1188 by @mickeypash.
- Add support for
response_model_exclude_defaults
andresponse_model_exclude_none
: - Add example about Testing a Database. Initial PR #1144 by @duganchen.
- Update docs for Development - Contributing: Translations including note about reviewing translation PRs. #1215.
- Update log style in README.md for GitHub Markdown compatibility. PR #1200 by #geekgao.
- Add Python venv
env
to.gitignore
. PR #1212 by @cassiobotaro. - Start Portuguese translations. PR #1210 by @cassiobotaro.
- Update docs for Pydantic's
Settings
using a dependency with@lru_cache()
. PR #1214. - Add first translation to Spanish FastAPI. PR #1201 by @mariacamilagl.
- Add docs about Settings and Environment Variables. Initial PR 1118 by @alexmitelman.
0.53.2¶
- Fix automatic embedding of body fields for dependencies and sub-dependencies. Original PR #1079 by @Toad2186.
- Fix dependency overrides in WebSocket testing. PR #1122 by @amitlissack.
- Fix docs script to ensure languages are always sorted. PR #1189.
- Start translations for Chinese. PR #1187 by @RunningIkkyu.
- Add docs for Schema Extra - Example. PR #1185.
0.53.1¶
- Fix included example after translations refactor. PR #1182.
- Add docs example for
example
inField
. Docs at Body - Fields: JSON Schema extras. PR #1106 by @JohnPaton. - Fix using recursive models in
response_model
. PR #1164 by @voegtlel. - Add docs for Pycharm Debugging. PR #1096 by @youngquan.
- Fix typo in docs. PR #1148 by @PLNech.
- Update Windows development environment instructions. PR #1179.
0.53.0¶
- Update test coverage badge. PR #1175.
- Add
orjson
topip install fastapi[all]
. PR #1161 by @michael0liver. - Fix included example for
GZipMiddleware
. PR #1138 by @arimbr. - Fix class name in docstring for
OAuth2PasswordRequestFormStrict
. PR #1126 by @adg-mh. - Clarify function name in example in docs. PR #1121 by @tmsick.
- Add external link Apache Kafka producer and consumer with FastAPI and aiokafka to docs. PR #1112 by @iwpnd.
- Fix serialization when using
by_alias
orexclude_unset
and returning data with Pydantic models. PR #1074 by @juhovh-aiven. - Add Gitter chat to docs. PR #1061 by @aakashnand.
- Update and simplify translations docs. PR #1171.
- Update development of FastAPI docs, set address to
127.0.0.1
to improve Windows support. PR #1169 by @mariacamilagl. - Add support for docs translations. New docs: Development - Contributing: Docs: Translations. PR #1168.
- Update terminal styles in docs and add note about Typer, the FastAPI of CLIs. PR #1139.
0.52.0¶
- Add new high-performance JSON response class using
orjson
. New docs: Custom Response - HTML, Stream, File, others:ORJSONResponse
. PR #1065.
0.51.0¶
- Re-export utils from Starlette:
- This allows using things like
from fastapi.responses import JSONResponse
instead offrom starlette.responses import JSONResponse
. - It's mainly syntax sugar, a convenience for developer experience.
- Now
Request
,Response
,WebSocket
,status
can be imported directly fromfastapi
as infrom fastapi import Response
. This is because those are frequently used, to use the request directly, to set headers and cookies, to get status codes, etc. - Documentation changes in many places, but new docs and noticeable improvements:
- PR #1064.
- This allows using things like
0.50.0¶
- Add link to Release Notes from docs about pinning versions for deployment. PR #1058.
- Upgrade code to use the latest version of Starlette, including:
- Several bug fixes.
- Optional redirects of slashes, with or without ending in
/
. - Events for routers,
"startup"
, and"shutdown"
. - PR #1057.
- Add docs about pinning FastAPI versions for deployment: Deployment: FastAPI versions. PR #1056.
0.49.2¶
- Fix links in release notes. PR #1052 by @sattosan.
- Fix typo in release notes. PR #1051 by @sattosan.
- Refactor/clarify
serialize_response
parameter name to avoid confusion. PR #1031 by @patrickmckenna. - Refactor calling each a path operation's handler function in an isolated function, to simplify profiling. PR #1027 by @sm-Fifteen.
- Add missing dependencies for testing. PR #1026 by @sm-Fifteen.
- Fix accepting valid types for response models, including Python types like
List[int]
. PR #1017 by @patrickmckenna. - Fix format in SQL tutorial. PR #1015 by @vegarsti.
0.49.1¶
- Fix path operation duplicated parameters when used in dependencies and the path operation function. PR #994 by @merowinger92.
- Update Netlify previews deployment GitHub action as the fix is already merged and there's a new release. PR #1047.
- Move mypy configurations to config file. PR #987 by @hukkinj1.
- Temporary fix to Netlify previews not deployable from PRs from forks. PR #1046 by @mariacamilagl.
0.49.0¶
- Fix encoding of
pathlib
paths injsonable_encoder
. PR #978 by @patrickmckenna. - Add articles to External Links: PythonใฎWeb frameworkใฎใใใฉใผใใณในๆฏ่ผ (Django, Flask, responder, FastAPI, japronto) and [FastAPI] Python่ฃฝใฎASGI Web ใใฌใผใ ใฏใผใฏ FastAPIใซๅ ฅ้ใใ. PR #974 by @tokusumi.
- Fix broken links in docs. PR #949 by @tsotnikov.
- Fix small typos. PR #941 by @NikitaKolesov.
- Update and clarify docs for dependencies with
yield
. PR #986. - Add Mermaid JS support for diagrams in docs. Add first diagrams to Dependencies: First Steps and Dependencies with
yield
andHTTPException
. PR #985. - Update CI to run docs deployment in GitHub actions. PR #983.
- Allow
callable
s in path operation functions, like functions modified withfunctools.partial
. PR #977.
0.48.0¶
- Run linters first in tests to error out faster. PR #948.
- Log warning about
email-validator
only when used. PR #946. - Simplify Peewee docs with double dependency with
yield
. PR #947. - Add article External Links: Create and Deploy FastAPI app to Heroku. PR #942 by @windson.
- Update description of Sanic, as it is now ASGI too. PR #932 by @raphaelauv.
- Fix typo in main page. PR #920 by @mMarzeta.
- Fix parsing of possibly invalid bodies. PR #918 by @dmontagu.
- Fix typo #916 by @adursun.
- Allow
Any
type for enums in OpenAPI. PR #906 by @songzhi. - Add article to External Links: How to continuously deploy a FastAPI to AWS Lambda with AWS SAM. PR #901 by @iwpnd.
- Add note about using Body parameters without Pydantic. PR #900 by @pawamoy.
- Fix Pydantic field clone logic. PR #899 by @deuce2367.
- Fix link in middleware docs. PR #893 by @linchiwei123.
- Rename default API title from "Fast API" to "FastAPI" for consistency. PR #890.
0.47.1¶
- Fix model filtering in
response_model
, cloning sub-models. PR #889. - Fix FastAPI serialization of Pydantic models using ORM mode blocking the event loop. PR #888.
0.47.0¶
- Refactor documentation to make a simpler and shorter Tutorial - User Guide and an additional Advanced User Guide with all the additional docs. PR #887.
- Tweak external links, Markdown format, typos. PR #881.
- Fix bug in tutorial handling HTTP Basic Auth
username
andpassword
. PR #865 by @isaevpd. - Fix handling form path operation parameters declared with pure classes like
list
,tuple
, etc. PR #856 by @nsidnev. - Add request
body
toRequestValidationError
, new docs: Use theRequestValidationError
body. Initial PR #853 by @aviramha. - Update External Links with new links and dynamic GitHub projects with
fastapi
topic. PR #850. - Fix Peewee
contextvars
handling in docs: SQL (Relational) Databases with Peewee. PR #879. - Setup development environment with Python's Venv and Flit, instead of requiring the extra Pipenv duplicating dependencies. Updated docs: Development - Contributing. PR #877.
- Update docs for HTTP Basic Auth to improve security against timing attacks. Initial PR #807 by @zwass.
0.46.0¶
- Fix typos and tweak configs. PR #837.
- Add link to Chinese article in External Links. PR 810 by @wxq0309.
- Implement
OAuth2AuthorizationCodeBearer
class. PR #797 by @kuwv. - Update example upgrade in docs main page. PR #795 by @cdeil.
- Fix callback handling for sub-routers. PR #792 by @jekirl.
- Fix typos. PR #784 by @kkinder.
- Add 4 Japanese articles to External Links. PR #783 by @HymanZHAN.
- Add support for subtypes of main types in
jsonable_encoder
, e.g. asyncpg's UUIDs. PR #756 by @RmStorm. - Fix usage of Pydantic's
HttpUrl
in docs. PR #832 by @Dustyposa. - Fix Twitter links in docs. PR #813 by @justindujardin.
- Add docs for correctly using FastAPI with Peewee ORM. Including how to overwrite parts of Peewee to correctly handle async threads. PR #789.
0.45.0¶
- Add support for OpenAPI Callbacks:
- New docs: OpenAPI Callbacks.
- Refactor generation of
operationId
s to be valid Python names (also valid variables in most languages). - Add
default_response_class
parameter toAPIRouter
. - Original PR #722 by @booooh.
- Refactor logging to use the same logger everywhere, update log strings and levels. PR #781.
- Add article to External Links: ะะพัะตะผั ะั ะดะพะปะถะฝั ะฟะพะฟัะพะฑะพะฒะฐัั FastAPI?. PR #766 by @prostomarkeloff.
- Remove gender bias in docs for handling errors. PR #780. Original idea in PR #761 by @classywhetten.
- Rename docs and references to
body-schema
tobody-fields
to keep in line with Pydantic. PR #746 by @prostomarkeloff.
0.44.1¶
- Add GitHub social preview images to git. PR #752.
- Update PyPI "trove classifiers". PR #751.
- Add full support for Python 3.8. Enable Python 3.8 in full in Travis. PR 749.
- Update "new issue" templates. PR #749.
- Fix serialization of errors for exotic Pydantic types. PR #748 by @dmontagu.
0.44.0¶
- Add GitHub action Issue Manager. PR #742.
- Fix typos in docs. PR 734 by @bundabrg.
- Fix usage of
custom_encoder
injsonable_encoder
. PR #715 by @matrixise. - Fix invalid XML example. PR 710 by @OcasoProtal.
- Fix typos and update wording in deployment docs. PR #700 by @marier-nico.
- Add note about dependencies in
APIRouter
docs. PR #698 by @marier-nico. - Add support for async class methods as dependencies #681 by @frankie567.
- Add FastAPI with Swagger UI cheatsheet to external links. PR #671 by @euri10.
- Fix typo in HTTP protocol in CORS example. PR #647 by @forestmonster.
- Add support for Pydantic versions
1.0.0
and above, with temporary (deprecated) backwards compatibility for Pydantic0.32.2
. PR #646 by @dmontagu.
0.43.0¶
- Update docs to reduce gender bias. PR #645 by @ticosax.
- Add docs about overriding the
operationId
for all the path operations based on their function name. PR #642 by @SKalt. - Fix validators in models generating an incorrect key order. PR #637 by @jaddison.
- Generate correct OpenAPI docs for responses with no content. PR #621 by @brotskydotcom.
- Remove
$
from Bash code blocks in docs for consistency. PR #613 by @nstapelbroek. - Add docs for self-serving docs' (Swagger UI) static assets, e.g. to use the docs offline, or without Internet. Initial PR #557 by @svalouch.
- Fix
black
linting after upgrade. PR #682 by @frankie567.
0.42.0¶
- Add dependencies with
yield
, a.k.a. exit steps, context managers, cleanup, teardown, ...- This allows adding extra code after a dependency is done. It can be used, for example, to close database connections.
- Dependencies with
yield
can be normal orasync
, FastAPI will run normal dependencies in a threadpool. - They can be combined with normal dependencies.
- It's possible to have arbitrary trees/levels of dependencies with
yield
and exit steps are handled in the correct order automatically. - It works by default in Python 3.7 or above. For Python 3.6, it requires the extra backport dependencies:
async-exit-stack
async-generator
- New docs at Dependencies with
yield
. - Updated database docs SQL (Relational) Databases: Main FastAPI app.
- PR #595.
- Fix
sitemap.xml
in website. PR #598 by @samuelcolvin.
0.41.0¶
- Upgrade required Starlette to
0.12.9
, the new range is>=0.12.9,<=0.12.9
.- Add
State
to FastAPI apps atapp.state
. - PR #593.
- Add
- Improve handling of custom classes for
Request
s andAPIRoute
s.- This helps to more easily solve use cases like:
- Reading a body before and/or after a request (equivalent to a middleware).
- Run middleware-like code only for a subset of path operations.
- Process a request before passing it to a path operation function. E.g. decompressing, deserializing, etc.
- Processing a response after being generated by path operation functions but before returning it. E.g. adding custom headers, logging, adding extra metadata.
- New docs section: Custom Request and APIRoute class.
- PR #589 by @dmontagu.
- This helps to more easily solve use cases like:
- Fix preserving custom route class in routers when including other sub-routers. PR #538 by @dmontagu.
0.40.0¶
- Add notes to docs about installing
python-multipart
when using forms. PR #574 by @sliptonic. - Generate OpenAPI schemas in alphabetical order. PR #554 by @dmontagu.
- Add support for truncating docstrings from path operation functions.
- New docs at Advanced description from docstring.
- PR #556 by @svalouch.
- Fix
DOCTYPE
in HTML files generated for Swagger UI and ReDoc. PR #537 by @Trim21. - Fix handling
4XX
responses overriding default422
validation error responses. PR #517 by @tsouvarev. - Fix typo in documentation for Simple HTTP Basic Auth. PR #514 by @prostomarkeloff.
- Fix incorrect documentation example in first steps. PR #511 by @IgnatovFedor.
- Add support for Swagger UI initOauth settings with the parameter
swagger_ui_init_oauth
. PR #499 by @zamiramir.
0.39.0¶
- Allow path parameters to have default values (e.g.
None
) and discard them instead of raising an error.- This allows declaring a parameter like
user_id: str = None
that can be taken from a query parameter, but the same path operation can be included in a router with a path/users/{user_id}
, in which case will be taken from the path and will be required. - PR #464 by @jonathanunderwood.
- This allows declaring a parameter like
- Add support for setting a
default_response_class
in theFastAPI
instance or ininclude_router
. Initial PR #467 by @toppk. - Add support for type annotations using strings and
from __future__ import annotations
. PR #451 by @dmontagu.
0.38.1¶
- Fix incorrect
Request
class import. PR #493 by @kamalgill.
0.38.0¶
- Add recent articles to External Links and recent opinions. PR #490.
- Upgrade support range for Starlette to include
0.12.8
. The new range is>=0.11.1,<=0.12.8"
. PR #477 by @dmontagu. - Upgrade support to Pydantic version 0.32.2 and update internal code to use it (breaking change). PR #463 by @dmontagu.
0.37.0¶
- Add support for custom route classes for advanced use cases. PR #468 by @dmontagu.
- Allow disabling Google fonts in ReDoc. PR #481 by @b1-luettje.
- Fix security issue: when returning a sub-class of a response model and using
skip_defaults
it could leak information. PR #485 by @dmontagu. - Enable tests for Python 3.8-dev. PR #465 by @Jamim.
- Add support and tests for Pydantic dataclasses in
response_model
. PR #454 by @dconathan. - Fix typo in OAuth2 JWT tutorial. PR #447 by @pablogamboa.
- Use the
media_type
parameter inBody()
params to set the media type in OpenAPI forrequestBody
. PR #439 by @divums. - Add article Deploying a scikit-learn model with ONNX and FastAPI by https://www.linkedin.com/in/nico-axtmann. PR #438 by @naxty.
- Allow setting custom
422
(validation error) response/schema in OpenAPI. - Fix using
"default"
extra response with status codes at the same time. PR #489. - Allow additional responses to use status code ranges (like
5XX
and4XX
) and"default"
. PR #435 by @divums.
0.36.0¶
- Fix implementation for
skip_defaults
when returning a Pydantic model. PR #422 by @dmontagu. - Fix OpenAPI generation when using the same dependency in multiple places for the same path operation. PR #417 by @dmontagu.
- Allow having empty paths in path operations used with
include_router
and aprefix
. - Fix mypy error after merging PR #415. PR #462.
0.35.0¶
- Fix typo in routing
assert
. PR #419 by @pablogamboa. - Fix typo in docs. PR #411 by @bronsen.
- Fix parsing a body type declared with
Union
. PR #400 by @koxudaxi.
0.34.0¶
-
Upgrade Starlette supported range to include the latest
0.12.7
. The new range is0.11.1,<=0.12.7
. PR #367 by @dedsm. -
Add test for OpenAPI schema with duplicate models from PR #333 by @dmontagu. PR #385.
0.33.0¶
0.32.0¶
-
Fix typo in docs for features. PR #380 by @MartinoMensio.
-
Fix source code
limit
for example in Query Parameters. PR #366 by @Smashman. -
Update wording in docs about OAuth2 scopes. PR #371 by @cjw296.
-
Update docs for
Enum
s to inherit fromstr
and improve Swagger UI rendering. PR #351. -
Fix regression, add Swagger UI deep linking again. PR #350.
-
Add test for having path templates in
prefix
of.include_router
. PR #349. -
Add note to docs: Include the same router multiple times with different
prefix
. PR #348. -
Fix OpenAPI/JSON Schema generation for two functions with the same name (in different modules) with the same composite bodies.
- Composite bodies' IDs are now based on path, not only on route name, as the auto-generated name uses the function names, that can be duplicated in different modules.
- The same new ID generation applies to response models.
- This also changes the generated title for those models.
- Only composite bodies and response models are affected because those are generated dynamically, they don't have a module (a Python file).
- This also adds the possibility of using
.include_router()
with the sameAPIRouter
multiple times, with different prefixes, e.g./api/v2
and/api/latest
, and it will now work correctly. - PR #347.
0.31.0¶
- Upgrade Pydantic supported version to
0.29.0
.- New supported version range is
"pydantic >=0.28,<=0.29.0"
. - This adds support for Pydantic Generic Models, kudos to @dmontagu.
- PR #344.
- New supported version range is
0.30.1¶
-
Add section in docs about External Links and Articles. PR #341.
-
Remove
Pipfile.lock
from the repository as it is only used by FastAPI contributors (developers of FastAPI itself). See the PR for more details. PR #340. -
Update section about Help FastAPI - Get Help. PR #339.
-
Refine internal type declarations to improve/remove Mypy errors in users' code. PR #338.
-
Update and clarify SQL tutorial with SQLAlchemy. PR #331 by @mariacamilagl.
-
Add SQLite online viewers to the docs. PR #330 by @cyrilbois.
0.30.0¶
-
Add support for Pydantic's ORM mode:
- Updated documentation about SQL with SQLAlchemy, using Pydantic models with ORM mode, SQLAlchemy models with relations, separation of files, simplification of code and other changes. New docs: SQL (Relational) Databases.
- The new support for ORM mode fixes issues/adds features related to ORMs with lazy-loading, hybrid properties, dynamic/getters (using
@property
decorators) and several other use cases. - This applies to ORMs like SQLAlchemy, Peewee, Tortoise ORM, GINO ORM and virtually any other.
- If your path operations return an arbitrary object with attributes (e.g.
my_item.name
instead ofmy_item["name"]
) AND you use aresponse_model
, make sure to update the Pydantic models withorm_mode = True
as described in the docs (link above). - New documentation about receiving plain
dict
s as request bodies: Bodies of arbitrarydict
s. - New documentation about returning arbitrary
dict
s in responses: Response with arbitrarydict
. - Technical Details:
- When declaring a
response_model
it is used directly to generate the response content, from whatever was returned from the path operation function. - Before this, the return content was first passed through
jsonable_encoder
to ensure it was a "jsonable" object, like adict
, instead of an arbitrary object with attributes (like an ORM model). That's why you should make sure to update your Pydantic models for objects with attributes to useorm_mode = True
. - If you don't have a
response_model
, the return object will still be passed throughjsonable_encoder
first. - When a
response_model
is declared, the sameresponse_model
type declaration won't be used as is, it will be "cloned" to create an new one (a cloned PydanticField
with all the submodels cloned as well). - This avoids/fixes a potential security issue: as the returned object is passed directly to Pydantic, if the returned object was a subclass of the
response_model
(e.g. you return aUserInDB
that inherits fromUser
but contains extra fields, likehashed_password
, andUser
is used in theresponse_model
), it would still pass the validation (becauseUserInDB
is a subclass ofUser
) and the object would be returned as-is, including thehashed_password
. To fix this, the declaredresponse_model
is cloned, if it is a Pydantic model class (or contains Pydantic model classes in it, e.g. in aList[Item]
), the Pydantic model class(es) will be a different one (the "cloned" one). So, an object that is a subclass won't simply pass the validation and returned as-is, because it is no longer a sub-class of the clonedresponse_model
. Instead, a new Pydantic model object will be created with the contents of the returned object. So, it will be a new object (made with the data from the returned one), and will be filtered by the clonedresponse_model
, containing only the declared fields as normally.
- When declaring a
- PR #322.
-
Remove/clean unused RegEx code in routing. PR #314 by @dmontagu.
-
Use default response status code descriptions for additional responses. PR #313 by @duxiaoyao.
0.29.1¶
-
Fix handling an empty-body request with a required body param. PR #311.
-
Fix broken link in docs: Return a Response directly. PR #306 by @dmontagu.
-
Fix docs discrepancy in docs for Response Model. PR #288 by @awiddersheim.
0.29.0¶
- Add support for declaring a
Response
parameter:- This allows declaring:
- Response Cookies.
- Response Headers.
- An HTTP Status Code different than the default: Response - Change Status Code.
- All of this while still being able to return arbitrary objects (
dict
, DB model, etc). - Update attribution to Hug, for inspiring the
response
parameter pattern. - PR #294.
- This allows declaring:
0.28.0¶
-
Implement dependency cache per request.
- This avoids calling each dependency multiple times for the same request.
- This is useful while calling external services, performing costly computation, etc.
- This also means that if a dependency was declared as a path operation decorator dependency, possibly at the router level (with
.include_router()
) and then it is declared again in a specific path operation, the dependency will be called only once. - The cache can be disabled per dependency declaration, using
use_cache=False
as inDepends(your_dependency, use_cache=False)
. - Updated docs at: Using the same dependency multiple times.
- PR #292.
-
Implement dependency overrides for testing.
- This allows using overrides/mocks of dependencies during tests.
- New docs: Testing Dependencies with Overrides.
- PR #291.
0.27.2¶
- Fix path and query parameters receiving
dict
as a valid type. It should be mapped to a body payload. PR #287. Updated docs at: Query parameter list / multiple values with defaults: Usinglist
.
0.27.1¶
-
Fix
auto_error=False
handling inHTTPBearer
security scheme. Do notraise
when there's an incorrectAuthorization
header ifauto_error=False
. PR #282. -
Fix type declaration of
HTTPException
. PR #279.
0.27.0¶
-
Fix broken link in docs about OAuth 2.0 with scopes. PR #275 by @dmontagu.
-
Refactor param extraction using Pydantic
Field
:- Large refactor, improvement, and simplification of param extraction from path operations.
- Fix/add support for list query parameters with list defaults. New documentation: Query parameter list / multiple values with defaults.
- Add support for enumerations in path operation parameters. New documentation: Path Parameters: Predefined values.
- Add support for type annotations using
Optional
as inparam: Optional[str] = None
. New documentation: Optional type declarations. - PR #278.
0.26.0¶
-
Separate error handling for validation errors.
- This will allow developers to customize the exception handlers.
- Document better how to handle exceptions and use error handlers.
- Include
RequestValidationError
andWebSocketRequestValidationError
(this last one will be useful once encode/starlette#527 or equivalent is merged). - New documentation about exceptions handlers:
- PR #273.
-
Fix support for paths in path parameters without needing explicit
Path(...)
.- PR #256.
- Documented in PR #272 by @wshayes.
- New documentation at: Path Parameters containing paths.
-
Update docs for testing FastAPI. Include using
POST
, sending JSON, testing headers, etc. New documentation: Testing. PR #271. -
Fix type declaration of
response_model
to allow generic Python types asList[Model]
. Mainly to fixmypy
for users. PR #266.
0.25.0¶
-
Add support for Pydantic's
include
,exclude
,by_alias
.- Update documentation: Response Model.
- Add docs for: Body - updates, using Pydantic's
skip_defaults
. - Add method consistency tests.
- PR #264.
-
Add
CONTRIBUTING.md
file to GitHub, to help new contributors. PR #255 by @wshayes. -
Add support for Pydantic's
skip_defaults
:- There's a new path operation decorator parameter
response_model_skip_defaults
.- The name of the parameter will most probably change in a future version to
response_skip_defaults
,model_skip_defaults
or something similar.
- The name of the parameter will most probably change in a future version to
- New documentation section about using
response_model_skip_defaults
. - PR #248 by @wshayes.
- There's a new path operation decorator parameter
0.24.0¶
-
Add support for WebSockets with dependencies and parameters.
- Support included for:
Depends
Security
Cookie
Header
Path
Query
- ...as these are compatible with the WebSockets protocol (e.g.
Body
is not).
- Updated documentation for WebSockets.
- PR #178 by @jekirl.
- Support included for:
-
Upgrade the compatible version of Pydantic to
0.26.0
.
0.23.0¶
-
Upgrade the compatible version of Starlette to
0.12.0
.- This includes support for ASGI 3 (the latest version of the standard).
- It's now possible to use Starlette's
StreamingResponse
with iterators, like file-like objects (as those returned byopen()
). - It's now possible to use the low level utility
iterate_in_threadpool
fromstarlette.concurrency
(for advanced scenarios). - PR #243.
-
Add OAuth2 redirect page for Swagger UI. This allows having delegated authentication in the Swagger UI docs. For this to work, you need to add
{your_origin}/docs/oauth2-redirect
to the allowed callbacks in your OAuth2 provider (in Auth0, Facebook, Google, etc).- For example, during development, it could be
http://localhost:8000/docs/oauth2-redirect
. - Have in mind that this callback URL is independent of whichever one is used by your frontend. You might also have another callback at
https://yourdomain.com/login/callback
. - This is only to allow delegated authentication in the API docs with Swagger UI.
- PR #198 by @steinitzu.
- For example, during development, it could be
-
Make Swagger UI and ReDoc route handlers (path operations) be
async
functions instead of lambdas to improve performance. PR #241 by @Trim21. -
Make Swagger UI and ReDoc URLs parameterizable, allowing to host and serve local versions of them and have offline docs. PR #112 by @euri10.
0.22.0¶
-
Add support for
dependencies
parameter:- A parameter in path operation decorators, for dependencies that should be executed but the return value is not important or not used in the path operation function.
- A parameter in the
.include_router()
method of FastAPI applications and routers, to include dependencies that should be executed in each path operation in a router.- This is useful, for example, to require authentication or permissions in specific group of path operations.
- Different
dependencies
can be applied to different routers.
- These
dependencies
are run before the normal parameter dependencies. And normal dependencies are run too. They can be combined. - Dependencies declared in a router are executed first, then the ones defined in path operation decorators, and then the ones declared in normal parameters. They are all combined and executed.
- All this also supports using
Security
withscopes
in thosedependencies
parameters, for more advanced OAuth 2.0 security scenarios with scopes. - New documentation about dependencies in path operation decorators.
- New documentation about dependencies in the
include_router()
method. - PR #235.
-
Fix OpenAPI documentation of Starlette URL convertors. Specially useful when using
path
convertors, to take a whole path as a parameter, like/some/url/{p:path}
. PR #234 by @euri10. -
Make default parameter utilities exported from
fastapi
be functions instead of classes (the new functions return instances of those classes). To be able to override the return types and fixmypy
errors in FastAPI's users' code. Applies toPath
,Query
,Header
,Cookie
,Body
,Form
,File
,Depends
, andSecurity
. PR #226 and PR #231. -
Separate development scripts
test.sh
,lint.sh
, andformat.sh
. PR #232. -
Re-enable
black
formatting checks for Python 3.7. PR #229 by @zamiramir.
0.21.0¶
-
On body parsing errors, raise
from
previous exception, to allow better introspection in logging code. PR #192 by @ricardomomm. -
Use Python logger named "
fastapi
" instead of root logger. PR #222 by @euri10. -
Fix typo in routing. PR #221 by @djlambert.
0.20.1¶
-
Add typing information to package including file
py.typed
. PR #209 by @meadsteve. -
Add FastAPI bot for Gitter. To automatically announce new releases. PR #189.
0.20.0¶
-
Upgrade OAuth2:
- Upgrade Password flow using Bearer tokens to use the correct HTTP status code 401
UNAUTHORIZED
, withWWW-Authenticate
headers. - Update, simplify, and improve all the security docs.
- Add new
scope_str
toSecurityScopes
and update docs: OAuth2 scopes. - Update docs, images, tests.
- PR #188.
- Upgrade Password flow using Bearer tokens to use the correct HTTP status code 401
-
Include Hypercorn as an alternative ASGI server in the docs. PR #187.
-
Add docs for Static Files and Templates. PR #186.
-
Add docs for handling Response Cookies and Response Headers. PR #185.
0.19.0¶
-
Rename path operation decorator parameter
content_type
toresponse_class
. PR #183. -
Add docs:
- How to use the
jsonable_encoder
in JSON compatible encoder. - How to Return a Response directly.
- Update how to use a Custom Response Class.
- PR #184.
- How to use the
0.18.0¶
-
Add docs for HTTP Basic Auth. PR #177.
-
Upgrade HTTP Basic Auth handling with automatic headers (automatic browser login prompt). PR #175.
-
Update dependencies for security. PR #174.
-
Add docs for Middleware. PR #173.
0.17.0¶
-
Make Flit publish from CI. PR #170.
-
Add documentation about handling CORS (Cross-Origin Resource Sharing). PR #169.
-
By default, encode by alias. This allows using Pydantic
alias
parameters working by default. PR #168.
0.16.0¶
-
Upgrade path operation
docstring
parsing to support proper Markdown descriptions. New documentation at Path Operation Configuration. PR #163. -
Refactor internal usage of Pydantic to use correct data types. PR #164.
-
Fix typo in Tutorial about Extra Models. PR #159 by @danielmichaels.
-
Fix Query Parameters URL examples in docs. PR #157 by @hayata-yamamoto.
0.15.0¶
-
Add support for multiple file uploads (as a single form field). New docs at: Multiple file uploads. PR #158.
-
Add docs for: Additional Status Codes. PR #156.
0.14.0¶
-
Improve automatically generated names of path operations in OpenAPI (in API docs). A function
read_items
instead of having a generated name "Read Items Get" will have "Read Items". PR #155. -
Add docs for: Testing FastAPI. PR #151.
-
Update
/docs
Swagger UI to enable deep linking. This allows sharing the URL pointing directly to the path operation documentation in the docs. PR #148 by @wshayes. -
Update development dependencies,
Pipfile.lock
. PR #150. -
Include Falcon and Hug in: Alternatives, Inspiration and Comparisons.
0.13.0¶
- Improve/upgrade OAuth2 scopes support with
SecurityScopes
:SecurityScopes
can be declared as a parameter likeRequest
, to get the scopes of all super-dependencies/dependants.- Improve
Security
handling, merging scopes when declaringSecurityScopes
. - Allow using
SecurityBase
(likeOAuth2
) classes withDepends
and still document them.Security
now is needed only to declarescopes
. - Updated docs about: OAuth2 with Password (and hashing), Bearer with JWT tokens.
- New docs about: OAuth2 scopes.
- PR #141.
0.12.1¶
-
Fix bug: handling additional
responses
inAPIRouter.include_router()
. PR #140. -
Fix typo in SQL tutorial. PR #138 by @mostaphaRoudsari.
-
Fix typos in section about nested models and OAuth2 with JWT. PR #127 by @mmcloud.
0.12.0¶
- Add additional
responses
parameter to path operation decorators to extend responses in OpenAPI (and API docs).- It also allows extending existing responses generated from
response_model
, declare other media types (like images), etc. - The new documentation is here: Additional Responses.
responses
can also be added to.include_router()
, the updated docs are here: Bigger Applications.- PR #97 originally initiated by @barsi.
- It also allows extending existing responses generated from
- Update
scripts/test-cov-html.sh
to allow passing extra parameters like-vv
, for development.
0.11.0¶
-
Add
auto_error
parameter to security utility functions. Allowing them to be optional. Also allowing to have multiple alternative security schemes that are then checked in a single dependency instead of each one verifying and returning the error to the client automatically when not satisfied. PR #134. -
Update SQL Tutorial to close database sessions even when there are exceptions. PR #89 by @alexiri.
-
Fix duplicate dependency in
pyproject.toml
. PR #128 by @zxalif.
0.10.3¶
-
Add Gitter chat, badge, links, etc. https://gitter.im/tiangolo/fastapi . PR #117.
-
Add docs about Extending OpenAPI. PR #126.
-
Make Travis run Ubuntu Xenial (newer version) and Python 3.7 instead of Python 3.7-dev. PR #92 by @blueyed.
-
Fix duplicated param variable creation. PR #123 by @yihuang.
-
Add note in Response Model docs about why using a function parameter instead of a function return type annotation. PR #109 by @JHSaunders.
-
Fix event docs (startup/shutdown) function name. PR #105 by @stratosgear.
0.10.2¶
-
Fix OpenAPI (JSON Schema) for declarations of Python
Union
(JSON SchemaadditionalProperties
). PR #121. -
Update Background Tasks with a note on Celery.
-
Document response models using unions and lists, updated at: Extra Models. PR #108.
0.10.1¶
- Add docs and tests for encode/databases. New docs at: Async SQL (Relational) Databases. PR #107.
0.10.0¶
-
Add support for Background Tasks in path operation functions and dependencies. New documentation about Background Tasks is here. PR #103.
-
Add support for
.websocket_route()
inAPIRouter
. PR #100 by @euri10. -
New docs section about Events: startup - shutdown. PR #99.
0.9.1¶
- Document receiving Multiple values with the same query parameter and Duplicate headers. PR #95.
0.9.0¶
-
Upgrade compatible Pydantic version to
0.21.0
. PR #90. -
Add documentation for: Application Configuration.
-
Fix typo in docs. PR #76 by @matthewhegarty.
-
Fix link in "Deployment" to "Bigger Applications".
0.8.0¶
-
Add support for adding
tags
inapp.include_router()
. PR #55 by @euri10. Documentation updated in the section: Bigger Applications. -
Update docs related to Uvicorn to use new
--reload
option from version0.5.x
. PR #74. -
Update
isort
imports and scripts to be compatible with newer versions. PR #75.
0.7.1¶
-
Update technical details about
async def
handling with respect to previous frameworks. PR #64 by @haizaar. -
Add deployment documentation for Docker in Raspberry Pi and other architectures.
-
Trigger Docker images build on Travis CI automatically. PR #65.
0.7.0¶
- Add support for
UploadFile
inFile
parameter annotations.- This includes a file-like interface.
- Here's the updated documentation for declaring
File
parameters withUploadFile
. - And here's the updated documentation for using
Form
parameters mixed withFile
parameters, supportingbytes
andUploadFile
at the same time. - PR #63.
0.6.4¶
-
Add technical details about
async def
handling to docs. PR #61. -
Add docs for Debugging FastAPI applications in editors.
-
Fix typos in docs.
-
Add section about History, Design and Future.
-
Add docs for using WebSockets with FastAPI. PR #62.
0.6.3¶
- Add Favicons to docs. PR #53.
0.6.2¶
-
Introduce new project generator based on FastAPI and PostgreSQL: https://github.com/tiangolo/full-stack-fastapi-postgresql. PR #52.
-
Update SQL tutorial with SQLAlchemy, using
Depends
to improve editor support and reduce code repetition. PR #52. -
Improve middleware naming in tutorial for SQL with SQLAlchemy https://fastapi.tiangolo.com/tutorial/sql-databases/.
0.6.1¶
- Add docs for GraphQL: https://fastapi.tiangolo.com/advanced/graphql/. PR #48.
0.6.0¶
-
Update SQL with SQLAlchemy tutorial at https://fastapi.tiangolo.com/tutorial/sql-databases/ using the new official
request.state
. PR #45. -
Upgrade Starlette to version
0.11.1
and add required compatibility changes. PR #44.
0.5.1¶
-
Add section about helping and getting help with FastAPI.
-
Add note about path operations order in docs.
-
Update section about error handling with more information and make relation with Starlette error handling utilities more explicit. PR #41.
0.5.0¶
-
Add new
HTTPException
with support for custom headers. With new documentation for handling errors at: https://fastapi.tiangolo.com/tutorial/handling-errors/. PR #35. -
Add documentation to use Starlette
Request
object directly. Check #25 by @euri10. -
Add issue templates to simplify reporting bugs, getting help, etc: #34.
-
Update example for the SQLAlchemy tutorial at https://fastapi.tiangolo.com/tutorial/sql-databases/ using middleware and database session attached to request.
0.4.0¶
-
Add
openapi_prefix
, support for reverse proxy and mounting sub-applications. See the docs at https://fastapi.tiangolo.com/advanced/sub-applications-proxy/: #26 by @kabirkhan. -
Update docs/tutorial for SQLAlchemy including note about DB Browser for SQLite.
0.3.0¶
- Fix/add SQLAlchemy support, including ORM, and update docs for SQLAlchemy: #30.
0.2.1¶
- Fix
jsonable_encoder
for Pydantic models withConfig
but withoutjson_encoders
: #29.