fastapi v0.62.0 Release Notes
Release Date: 2020-11-29 // over 4 years ago-
๐ Features
- ๐ฑ โจ Add support for shared/top-level parameters (dependencies, tags, etc). PR #2434 by @tiangolo.
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 toapp.include_router()
orrouter.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 theAPIRouter
.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, Dependsasync def some\_dependency(): returnapp = 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, Dependsasync def some\_dependency(): returnrouter = 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 useAPIRouter
when possible.But
include_router
is still useful to, for example, adding options (likedependencies
,prefix
, andtags
) 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
ininclude_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:
- Advanced User Guide - OpenAPI Callbacks.
- Tutorial - Bigger Applications.
- Tutorial - Dependencies - Dependencies in path operation decorators.
- Tutorial - Dependencies - Global Dependencies.
๐ฑ ๐ 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.
Previous changes from v0.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.