Skip to content

Releases: tiangolo/fastapi

0.83.0

11 Sep 16:27
Compare
Choose a tag to compare

🚨 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 when HTTPException has a status code with no content. PR #5365 by @iudeen.
  • 🐛 Fix empty reponse body when default status_code is empty but the a Response parameter with response.status_code is set. PR #5360 by @tmeckel.

Docs

Internal

0.82.0

04 Sep 19:35
Compare
Choose a tag to compare

🚨 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 in fastapi.websockets. PR #4376 by @matiuszka.
  • ✨ Support Python internal description on Pydantic model's docstring. PR #3032 by @Kludex.
  • ✨ Update ORJSONResponse to support non str 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

0.81.0

26 Aug 15:21
Compare
Choose a tag to compare

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 HTTPExceptions 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 be Optional[bool]. PR #4933 by @DavidKimDY.
  • 🔧 Update mypy config, use strict = true instead of manual configs. PR #4605 by @michaeloliverx.
  • ♻ Change a dict() for {} in fastapi/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

23 Aug 14:17
Compare
Choose a tag to compare

Breaking Changes - Fixes

  • 🐛 Fix response_model not invalidating None. PR #2725 by @hukkin.

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 like Union[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

18 Aug 21:16
Compare
Choose a tag to compare

Fixes

  • 🐛 Fix jsonable_encoder using include and exclude 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

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

0.79.0

14 Jul 17:38
Compare
Choose a tag to compare

Fixes - Breaking Changes

  • 🐛 Fix removing body from status codes that do not support it. PR #5145 by @tiangolo.
    • Setting status_code to 204, 304, or any code below 200 (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.

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

0.78.0

14 May 20:01
Compare
Choose a tag to compare

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 over Optional and migrate source examples. New docs at Python Types Intro - Using Union or Optional. 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

10 May 04:22
Compare
Choose a tag to compare

Upgrades

  • ⬆ Upgrade Starlette from 0.19.0 to 0.19.1. PR #4819 by @Kludex.

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

Internal

  • 🔧 Add notifications in issue for Uzbek translations. PR #4884 by @tiangolo.

0.77.0

10 May 01:42
Compare
Choose a tag to compare

Upgrades

  • ⬆ Upgrade Starlette from 0.18.0 to 0.19.0. PR #4488 by @Kludex.
    • When creating an explicit JSONResponse the content argument is now required.

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

05 May 22:28
Compare
Choose a tag to compare

Upgrades

  • ⬆ Upgrade Starlette from 0.17.1 to 0.18.0. PR #4483 by @Kludex.

Internal