fastapi v0.62.0 Release Notes

Release Date: 2020-11-29 // 11 months 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 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 in APIRouter and include_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 in APIRouter and include_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 with include_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 calling include_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 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 in APIRouter and FastAPI.
    • 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 in include_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 the router.default_response_class, or the app.default_response_class: the default value for response_class in APIRoute and for default_response_class in APIRouter and FastAPI is now a DefaultPlaceholder used internally to handle and solve default values and overrides. The actual response class inside the DefaultPlaceholder is available at route.response_class.value.

    ๐Ÿ“„ Docs

    โšก๏ธ PR #2434 (above) includes new or updated docs:

    - 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.