chore(deps): update dependency fastapi to v0.100.0
This MR contains the following updates:
Package | Change | Age | Adoption | Passing | Confidence |
---|---|---|---|---|---|
fastapi |
==0.71.0 -> ==0.100.0
|
Release Notes
tiangolo/fastapi (fastapi)
v0.100.0
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, ti 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.
-
MR #9816 by @tiangolo, included all the work done (in multiple MRs) on the beta branch (
main-pv2
).
v0.99.1
Fixes
-
🐛 Fix JSON Schema accepting bools as valid JSON Schemas, e.g.additionalProperties: false
. MR #9781 by @tiangolo.
Docs
-
📝 Update source examples to use new JSON Schema examples field. MR #9776 by @tiangolo.
v0.99.0
Note: this is the last release before supporting Pydantic v2. You can try out the beta with support for Pydantic v2 now, a new beta supporting Pydantic v2 with these same changes from this release will be available in the next hours/days. And the final version (0.100.0) with support for Pydantic v2 will be released in the next days (next week).
Now, back to this release (this one doesn't include the beta support for Pydantic v2).
This release has
Features
-
✨ Add support for OpenAPI 3.1.0. MR #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 fordeque
objects and children injsonable_encoder
. MR #9433 by @cranium.
Docs
-
📝 Fix form for the FastAPI and friends newsletter. MR #9749 by @tiangolo.
Translations
-
🌐 Add Persian translation fordocs/fa/docs/advanced/sub-applications.md
. MR #9692 by @mojtabapaso. -
🌐 Add Russian translation fordocs/ru/docs/tutorial/response-model.md
. MR #9675 by @glsglsgls.
Internal
-
🔨 Enable linenums in MkDocs Material during local live development to simplify highlighting code. MR #9769 by @tiangolo. -
⬆ Update httpx requirement from <0.24.0,>=0.23.0 to >=0.23.0,<0.25.0. MR #9724 by @dependabot[bot]. -
⬆ Bump mkdocs-material from 9.1.16 to 9.1.17. MR #9746 by @dependabot[bot]. -
🔥 Remove missing translation dummy pages, no longer necessary. MR #9751 by @tiangolo. -
⬆ [pre-commit.ci] pre-commit autoupdate. MR #9259 by @pre-commit-ci[bot]. -
✨ Add Material for MkDocs Insiders features and cards. MR #9748 by @tiangolo. -
🔥 Remove languages without translations. MR #9743 by @tiangolo. -
✨ Refactor docs for building scripts, use MkDocs hooks, simplify (remove) configs for languages. MR #9742 by @tiangolo. -
🔨 Add MkDocs hook that renames sections based on the first index file. MR #9737 by @tiangolo. -
👷 Make cron jobs run only on main repo, not on forks, to avoid error notifications from missing tokens. MR #9735 by @tiangolo. -
🔧 Update MkDocs for other languages. MR #9734 by @tiangolo. -
👷 Refactor Docs CI, run in multiple workers with a dynamic matrix to optimize speed. MR #9732 by @tiangolo. -
🔥 Remove old internal GitHub Action watch-previews that is no longer needed. MR #9730 by @tiangolo. -
⬆ ️ Upgrade MkDocs and MkDocs Material. MR #9729 by @tiangolo. -
👷 Build and deploy docs only on docs changes. MR #9728 by @tiangolo.
v0.98.0
Note: please also help me try out the beta with support for Pydantic v2: https://github.com/tiangolo/fastapi/releases/tag/0.100.0-beta1
Now, back to this release (this one doesn't include the beta support for Pydantic v2).
Features
-
✨ Allow disablingredirect_slashes
at the FastAPI app level. MR #3432 by @cyberlis.
Docs
-
📝 Update docs on Pydantic using ujson internally. MR #5804 by @mvasilkov. -
✏ Rewording indocs/en/docs/tutorial/debugging.md
. MR #9581 by @ivan-abc. -
📝 Add german blog post (Domain-driven Design mit Python und FastAPI). MR #9261 by @msander. -
✏ ️ Tweak wording indocs/en/docs/tutorial/security/index.md
. MR #9561 by @jyothish-mohan. -
📝 UpdateAnnotated
notes indocs/en/docs/tutorial/schema-extra-example.md
. MR #9620 by @Alexandrhub. -
✏ ️ Fix typoAnnotation
->Annotated
indocs/en/docs/tutorial/query-params-str-validations.md
. MR #9625 by @mccricardo. -
📝 Use in memory database for testing SQL in docs. MR #1223 by @HarshaLaxman.
Translations
-
🌐 Add Russian translation fordocs/ru/docs/tutorial/metadata.md
. MR #9681 by @TabarakoAkula. -
🌐 Fix typo in Spanish translation fordocs/es/docs/tutorial/first-steps.md
. MR #9571 by @lilidl-nft. -
🌐 Add Russian translation fordocs/tutorial/path-operation-configuration.md
. MR #9696 by @TabarakoAkula. -
🌐 Add Chinese translation fordocs/zh/docs/advanced/security/index.md
. MR #9666 by @lordqyxz. -
🌐 Add Chinese translations fordocs/zh/docs/advanced/settings.md
. MR #9652 by @ChoyeonChern. -
🌐 Add Chinese translations fordocs/zh/docs/advanced/websockets.md
. MR #9651 by @ChoyeonChern. -
🌐 Add Chinese translation fordocs/zh/docs/tutorial/testing.md
. MR #9641 by @wdh99. -
🌐 Add Russian translation fordocs/tutorial/extra-models.md
. MR #9619 by @ivan-abc. -
🌐 Add Russian translation fordocs/tutorial/cors.md
. MR #9608 by @ivan-abc. -
🌐 Add Polish translation fordocs/pl/docs/features.md
. MR #5348 by @mbroton. -
🌐 Add Russian translation fordocs/ru/docs/tutorial/body-nested-models.md
. MR #9605 by @Alexandrhub.
Internal
-
⬆ Bump ruff from 0.0.272 to 0.0.275. MR #9721 by @dependabot[bot]. -
⬆ Update uvicorn[standard] requirement from <0.21.0,>=0.12.0 to >=0.12.0,<0.23.0. MR #9463 by @dependabot[bot]. -
⬆ Bump mypy from 1.3.0 to 1.4.0. MR #9719 by @dependabot[bot]. -
⬆ Update pre-commit requirement from <3.0.0,>=2.17.0 to >=2.17.0,<4.0.0. MR #9251 by @dependabot[bot]. -
⬆ Bump pypa/gh-action-pypi-publish from 1.8.5 to 1.8.6. MR #9482 by @dependabot[bot]. -
✏ ️ Fix tooltips for light/dark theme toggler in docs. MR #9588 by @pankaj1707k. -
🔧 Set minimal hatchling version needed to build the package. MR #9240 by @mgorny. -
📝 Add repo link to PyPI. MR #9559 by @JacobCoffee. -
✏ ️ Fix typos in data for tests. MR #4958 by @ryanrussell. -
🔧 Update sponsors, add Flint. MR #9699 by @tiangolo. -
👷 Lint in CI only once, only with one version of Python, run tests with all of them. MR #9686 by @tiangolo.
v0.97.0
Features
-
✨ Add support fordependencies
in WebSocket routes. MR #4534 by @paulo-raca. -
✨ Add exception handler forWebSocketRequestValidationError
(which also allows to override it). MR #6030 by @kristjanvalur.
Refactors
-
⬆ ️ Upgrade and fully migrate to Ruff, remove isort, includes a couple of tweaks suggested by the new version of Ruff. MR #9660 by @tiangolo. -
♻ ️ Update internal type annotations and upgrade mypy. MR #9658 by @tiangolo. -
♻ ️ SimplifyAsyncExitStackMiddleware
as without Python 3.6AsyncExitStack
is always available. MR #9657 by @tiangolo.
Upgrades
-
⬆ ️ Upgrade Black. MR #9661 by @tiangolo.
Internal
-
💚 Update CI cache to fix installs when dependencies change. MR #9659 by @tiangolo. -
⬇ ️ Separate requirements for development into their own requirements.txt files, they shouldn't be extras. MR #9655 by @tiangolo.
v0.96.1
Fixes
-
🐛 FixHTTPException
header type annotations. MR #9648 by @tiangolo. -
🐛 Fix OpenAPI model fields int validations,gte
toge
. MR #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. MR #9567 by @Kludex.
Refactors
-
♻ Removemedia_type
fromORJSONResponse
as it's inherited from the parent class. MR #5805 by @Kludex. -
♻ InstantiateHTTPException
only when needed, optimization refactor. MR #5356 by @pawamoy.
Docs
Translations
-
🌐 Fix spelling in Indonesian translation ofdocs/id/docs/tutorial/index.md
. MR #5635 by @purwowd. -
🌐 Add Russian translation fordocs/ru/docs/tutorial/index.md
. MR #5896 by @Wilidon. -
🌐 Add Chinese translations fordocs/zh/docs/advanced/response-change-status-code.md
anddocs/zh/docs/advanced/response-headers.md
. MR #9544 by @ChoyeonChern. -
🌐 Add Russian translation fordocs/ru/docs/tutorial/schema-extra-example.md
. MR #9621 by @Alexandrhub.
Internal
-
🔧 Add sponsor Platform.sh. MR #9650 by @tiangolo. -
👷 Add custom token to Smokeshow and Preview Docs for download-artifact, to prevent API rate limits. MR #9646 by @tiangolo. -
👷 Add custom tokens for GitHub Actions to avoid rate limits. MR #9647 by @tiangolo.
v0.96.0
Features
-
⚡ Updatecreate_cloned_field
to use a global cache and improve startup performance. MR #4645 by @madkinsz and previous original MR by @huonw.
Docs
-
📝 Update Deta deployment tutorial for compatibility with Deta Space. MR #6004 by @mikBighne98. -
✏ ️ Fix typo in Deta deployment tutorial. MR #9501 by @lemonyte.
Translations
-
🌐 Add Russian translation fordocs/tutorial/body.md
. MR #3885 by @solomein-sv. -
🌐 Add Russian translation fordocs/ru/docs/tutorial/static-files.md
. MR #9580 by @Alexandrhub. -
🌐 Add Russian translation fordocs/ru/docs/tutorial/query-params.md
. MR #9584 by @Alexandrhub. -
🌐 Add Russian translation fordocs/ru/docs/tutorial/first-steps.md
. MR #9471 by @AGolicyn. -
🌐 Add Russian translation fordocs/ru/docs/tutorial/debugging.md
. MR #9579 by @Alexandrhub. -
🌐 Add Russian translation fordocs/ru/docs/tutorial/path-params.md
. MR #9519 by @AGolicyn. -
🌐 Add Chinese translation fordocs/zh/docs/tutorial/static-files.md
. MR #9436 by @wdh99. -
🌐 Update Spanish translation including new illustrations indocs/es/docs/async.md
. MR #9483 by @andresbermeoq. -
🌐 Add Russian translation fordocs/ru/docs/tutorial/path-params-numeric-validations.md
. MR #9563 by @ivan-abc. -
🌐 Add Russian translation fordocs/ru/docs/deployment/concepts.md
. MR #9577 by @Xewus. -
🌐 Add Russian translation fordocs/ru/docs/tutorial/body-multiple-params.md
. MR #9586 by @Alexandrhub.
Internal
-
👥 Update FastAPI People. MR #9602 by @github-actions[bot]. -
🔧 Update sponsors, remove InvestSuite. MR #9612 by @tiangolo.
v0.95.2
-
⬆ ️ Upgrade Starlette version to>=0.27.0
for a security release. MR #9541 by @tiangolo. Details on Starlette's security advisory.
Translations
-
🌐 Add Portuguese translation fordocs/pt/docs/advanced/events.md
. MR #9326 by @oandersonmagalhaes. -
🌐 Add Russian translation fordocs/ru/docs/deployment/manually.md
. MR #9417 by @Xewus. -
🌐 Add setup for translations to Lao. MR #9396 by @TheBrown. -
🌐 Add Russian translation fordocs/ru/docs/tutorial/testing.md
. MR #9403 by @Xewus. -
🌐 Add Russian translation fordocs/ru/docs/deployment/https.md
. MR #9428 by @Xewus. -
✏ Fix command to install requirements in Windows. MR #9445 by @MariiaRomanuik. -
🌐 Add French translation fordocs/fr/docs/advanced/response-directly.md
. MR #9415 by @axel584. -
🌐 Initiate Czech translation setup. MR #9288 by @3p1463k. -
✏ Fix typo in Portuguese docs fordocs/pt/docs/index.md
. MR #9337 by @lucasbalieiro. -
🌐 Add Russian translation fordocs/ru/docs/tutorial/response-status-code.md
. MR #9370 by @nadia3373.
Internal
-
🐛 Fixflask.escape
warning for internal tests. MR #9468 by @samuelcolvin. -
✅ Refactor 2 tests, for consistency and simplification. MR #9504 by @tiangolo. -
✅ Refactor OpenAPI tests, prepare for Pydantic v2. MR #9503 by @tiangolo. -
⬆ Bump dawidd6/action-download-artifact from 2.26.0 to 2.27.0. MR #9394 by @dependabot[bot]. -
💚 Disable setup-python pip cache in CI. MR #9438 by @tiangolo. -
⬆ Bump pypa/gh-action-pypi-publish from 1.6.4 to 1.8.5. MR #9346 by @dependabot[bot].
v0.95.1
Fixes
-
🐛 Fix usingAnnotated
in routers or path operations decorated multiple times. MR #9315 by @sharonyogev.
Docs
-
🌐 🔠 📄 🐢 Translate docs to Emoji 🥳🎉 💥 🤯 🤯. MR #5385 by @LeeeeT. -
📝 Add notification message warning about old versions of FastAPI not supportingAnnotated
. MR #9298 by @grdworkin. -
📝 Fix typo indocs/en/docs/advanced/behind-a-proxy.md
. MR #5681 by @Leommjr. -
✏ Fix wrong import from typing module in Persian translations fordocs/fa/docs/index.md
. MR #6083 by @Kimiaattaei. -
✏ ️ Fix format, remove unnecessary asterisks indocs/en/docs/help-fastapi.md
. MR #9249 by @armgabrielyan. -
✏ Fix typo indocs/en/docs/tutorial/query-params-str-validations.md
. MR #9272 by @nicornk. -
✏ Fix typo/bug in inline code example indocs/en/docs/tutorial/query-params-str-validations.md
. MR #9273 by @tim-habitat. -
✏ Fix typo indocs/en/docs/tutorial/path-params-numeric-validations.md
. MR #9282 by @aadarsh977. -
✏ Fix typo: 'wll' to 'will' indocs/en/docs/tutorial/query-params-str-validations.md
. MR #9380 by @dasstyxx.
Translations
-
🌐 Add French translation fordocs/fr/docs/advanced/index.md
. MR #5673 by @axel584. -
🌐 Add Portuguese translation fordocs/pt/docs/tutorial/body-nested-models.md
. MR #4053 by @luccasmmg. -
🌐 Add Russian translation fordocs/ru/docs/alternatives.md
. MR #5994 by @Xewus. -
🌐 Add Portuguese translation fordocs/pt/docs/tutorial/extra-models.md
. MR #5912 by @LorhanSohaky. -
🌐 Add Portuguese translation fordocs/pt/docs/tutorial/path-operation-configuration.md
. MR #5936 by @LorhanSohaky. -
🌐 Add Russian translation fordocs/ru/docs/contributing.md
. MR #6002 by @stigsanek. -
🌐 Add Korean translation fordocs/tutorial/dependencies/classes-as-dependencies.md
. MR #9176 by @sehwan505. -
🌐 Add Russian translation fordocs/ru/docs/project-generation.md
. MR #9243 by @Xewus. -
🌐 Add French translation fordocs/fr/docs/index.md
. MR #9265 by @frabc. -
🌐 Add Russian translation fordocs/ru/docs/tutorial/query-params-str-validations.md
. MR #9267 by @dedkot01. -
🌐 Add Russian translation fordocs/ru/docs/benchmarks.md
. MR #9271 by @Xewus.
Internal
-
🔧 Update sponsors: remove Jina. MR #9388 by @tiangolo. -
🔧 Update sponsors, add databento, remove Ines's course and StriveWorks. MR #9351 by @tiangolo.
v0.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 recommendingAnnotated
in docs. MR #9270 by @tiangolo. -
📝 Update order of examples, latest Python version first, and simplify version tab names. MR #9269 by @tiangolo. -
📝 Update all docs to useAnnotated
as the main recommendation, with new examples and tests. MR #9268 by @tiangolo.
v0.94.1
Fixes
-
🎨 Fix types for lifespan, upgrade Starlette to 0.26.1. MR #9245 by @tiangolo.
v0.94.0
Upgrades
-
⬆ Upgrade python-multipart to support 0.0.6. MR #9212 by @musicinmybrain. -
⬆ ️ Upgrade Starlette version, support newlifespan
with state. MR #9239 by @tiangolo.
Docs
-
📝 Update Sentry link in docs. MR #9218 by @smeubank.
Translations
Internal
-
➕ Addpydantic
to PyPI classifiers. MR #5914 by @yezz123. -
⬆ Bump black from 22.10.0 to 23.1.0. MR #5953 by @dependabot[bot]. -
⬆ Bump types-ujson from 5.6.0.0 to 5.7.0.1. MR #6027 by @dependabot[bot]. -
⬆ Bump dawidd6/action-download-artifact from 2.24.3 to 2.26.0. MR #6034 by @dependabot[bot]. -
⬆ [pre-commit.ci] pre-commit autoupdate. MR #5709 by @pre-commit-ci[bot].
v0.93.0
Features
-
✨ Add support forlifespan
async context managers (supersedingstartup
andshutdown
events). Initial MR #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. MR #5564 by @gusty1g. -
🌐 Add French translation fordocs/fr/docs/advanced/path-operation-advanced-configuration.md
. MR #9221 by @axel584. -
🌐 Add French translation fordocs/tutorial/debugging.md
. MR #9175 by @frabc. -
🌐 Initiate Armenian translation setup. MR #5844 by @har8. -
🌐 Add French translation fordeployment/manually.md
. MR #3693 by @rjNemo.
Internal
-
👷 Update translation bot messages. MR #9206 by @tiangolo. -
👷 Update translations bot to use Discussions, and notify when a MR is done. MR #9183 by @tiangolo. -
🔧 Update sponsors-badges. MR #9182 by @tiangolo. -
👥 Update FastAPI People. MR #9181 by @github-actions[bot]. -
🔊 Log GraphQL errors in FastAPI People, because it returns 200, with a payload with an error. MR #9171 by @tiangolo. -
💚 Fix/workaround GitHub Actions in Docker with git for FastAPI People. MR #9169 by @tiangolo. -
♻ ️ Refactor FastAPI Experts to use only discussions now that questions are migrated. MR #9165 by @tiangolo. -
⬆ ️ Upgrade analytics. MR #6025 by @tiangolo. -
⬆ ️ Upgrade and re-enable installing Typer-CLI. MR #6008 by @tiangolo.
v0.92.0
Upgrades
-
⬆ ️ Upgrade Starlette to 0.25.0. MR #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.
v0.91.0
Upgrades
-
⬆ ️ Upgrade Starlette version to0.24.0
and refactor internals for compatibility. MR #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 MR #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
v0.90.1
Upgrades
-
⬆ ️ Upgrade Starlette range to allow 0.23.1. MR #5980 by @tiangolo.
Docs
-
✏ Tweak wording to clarifydocs/en/docs/project-generation.md
. MR #5930 by @chandra-deb. -
✏ Update Pydantic GitHub URLs. MR #5952 by @yezz123. -
📝 Add opinion from Cisco. MR #5981 by @tiangolo.
Translations
Internal
-
✏ Updatezip-docs.sh
internal script, remove extra space. MR #5931 by @JuanPerdomo00.
v0.90.0
Upgrades
Docs
-
📝 Add article "Tortoise ORM / FastAPI 整合快速筆記" to External Links. MR #5496 by @Leon0824. -
👥 Update FastAPI People. MR #5954 by @github-actions[bot]. -
📝 Micro-tweak help docs. MR #5960 by @tiangolo. -
🔧 Update new issue chooser to direct to GitHub Discussions. MR #5948 by @tiangolo. -
📝 Recommend GitHub Discussions for questions. MR #5944 by @tiangolo.
Translations
-
🌐 Add Russian translation fordocs/ru/docs/tutorial/body-fields.md
. MR #5898 by @simatheone. -
🌐 Add Russian translation fordocs/ru/docs/help-fastapi.md
. MR #5970 by @tiangolo. -
🌐 Add Portuguese translation fordocs/pt/docs/tutorial/static-files.md
. MR #5858 by @batlopes. -
🌐 Add Portuguese translation fordocs/pt/docs/tutorial/encoder.md
. MR #5525 by @felipebpl. -
🌐 Add Russian translation fordocs/ru/docs/contributing.md
. MR #5870 by @Xewus.
Internal
-
⬆ ️ Upgrade Ubuntu version for docs workflow. MR #5971 by @tiangolo. -
🔧 Update sponsors badges. MR #5943 by @tiangolo. -
✨ Compute FastAPI Experts including GitHub Discussions. MR #5941 by @tiangolo. -
⬆ ️ Upgrade isort and update pre-commit. MR #5940 by @tiangolo. -
🔧 Add template for questions in Discussions. MR #5920 by @tiangolo. -
🔧 Update Sponsor Budget Insight to Powens. MR #5916 by @tiangolo. -
🔧 Update GitHub Sponsors badge data. MR #5915 by @tiangolo.
v0.89.1
Fixes
-
🐛 Ignore Response classes on return annotation. MR #5855 by @Kludex. See the new docs in the MR below.
Docs
-
📝 Update docs and examples for Response Model with Return Type Annotations, and update runtime error. MR #5873 by @tiangolo. New docs at Response Model - Return Type: Other Return Type Annotations. -
📝 Add External Link: FastAPI lambda container: serverless simplified. MR #5784 by @rafrasenberg.
Translations
-
🌐 Add Turkish translation fordocs/tr/docs/tutorial/first_steps.md
. MR #5691 by @Kadermiyanyedi.
v0.89.0
Features
-
✨ Add support for function return type annotations to declare theresponse_model
. Initial MR #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. MR #5712 by @Xhy-5000. -
✏ Fix typo indocs/en/docs/async.md
. MR #5785 by @Kingdageek. -
✏ Fix typo indocs/en/docs/deployment/concepts.md
. MR #5824 by @kelbyfaessler.
Translations
-
🌐 Add Russian translation fordocs/ru/docs/fastapi-people.md
. MR #5577 by @Xewus. -
🌐 Fix typo in Chinese translation fordocs/zh/docs/benchmarks.md
. MR #4269 by @15027668g. -
🌐 Add Korean translation fordocs/tutorial/cors.md
. MR #3764 by @NinaHwang.
Internal
-
⬆ Update coverage[toml] requirement from <7.0,>=6.5.0 to >=6.5.0,<8.0. MR #5801 by @dependabot[bot]. -
⬆ Update uvicorn[standard] requirement from <0.19.0,>=0.12.0 to >=0.12.0,<0.21.0 for development. MR #5795 by @dependabot[bot]. -
⬆ Bump dawidd6/action-download-artifact from 2.24.2 to 2.24.3. MR #5842 by @dependabot[bot]. -
👥 Update FastAPI People. MR #5825 by @github-actions[bot]. -
⬆ Bump types-ujson from 5.5.0 to 5.6.0.0. MR #5735 by @dependabot[bot]. -
⬆ Bump pypa/gh-action-pypi-publish from 1.5.2 to 1.6.4. MR #5750 by @dependabot[bot]. -
👷 Add GitHub Action gate/check. MR #5492 by @webknjaz. -
🔧 Update sponsors, add Svix. MR #5848 by @tiangolo. -
🔧 Remove Doist sponsor. MR #5847 by @tiangolo. -
⬆ Update sqlalchemy requirement from <=1.4.41,>=1.3.18 to >=1.3.18,<1.4.43. MR #5540 by @dependabot[bot]. -
⬆ Bump nwtgck/actions-netlify from 1.2.4 to 2.0.0. MR #5757 by @dependabot[bot]. -
👷 Refactor CI artifact upload/download for docs previews. MR #5793 by @tiangolo. -
⬆ Bump pypa/gh-action-pypi-publish from 1.5.1 to 1.5.2. MR #5714 by @dependabot[bot]. -
👥 Update FastAPI People. MR #5722 by @github-actions[bot]. -
🔧 Update sponsors, disable course bundle. MR #5713 by @tiangolo. -
⬆ Update typer[all] requirement from <0.7.0,>=0.6.1 to >=0.6.1,<0.8.0. MR #5639 by @dependabot[bot].
v0.88.0
Upgrades
-
⬆ Bump Starlette to version0.22.0
to fix bad encoding for query parameters in newTestClient
. MR #5659 by @azogue.
Docs
-
✏ ️ Fix typo in docs fordocs/en/docs/advanced/middleware.md
. MR #5376 by @rifatrakib.
Translations
Internal
-
👷 Tweak build-docs to improve CI performance. MR #5699 by @tiangolo. -
⬆ [pre-commit.ci] pre-commit autoupdate. MR #5566 by @pre-commit-ci[bot]. -
⬆ ️ Upgrade Ruff. MR #5698 by @tiangolo. -
👷 Remove pip cache for Smokeshow as it depends on a requirements.txt. MR #5700 by @tiangolo. -
💚 Fix pip cache for Smokeshow. MR #5697 by @tiangolo. -
👷 Fix and tweak CI cache handling. MR #5696 by @tiangolo. -
👷 Updatesetup-python
action in tests to use new caching feature. MR #5680 by @madkinsz. -
⬆ Bump black from 22.8.0 to 22.10.0. MR #5569 by @dependabot[bot].
v0.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". MR #5634 by @tiangolo. -
✨ Re-export Starlette'sWebSocketException
and add it to docs. MR #5629 by @tiangolo. -
📝 Update references to Requests for tests to HTTPX, and add HTTPX to extras. MR #5628 by @tiangolo. -
⬆ Upgrade Starlette to0.21.0
, including the newTestClient
based on HTTPX. MR #5471 by @pawelrubin.
Docs
-
✏ ️ Tweak Help FastAPI from MR review after merging. MR #5633 by @tiangolo. -
✏ ️ Clarify docs on CORS. MR #5627 by @paxcodes. -
📝 Update Help FastAPI: Help Maintain FastAPI. MR #5632 by @tiangolo.
Translations
-
🌐 Fix highlight lines for Japanese translation fordocs/tutorial/query-params.md
. MR #2969 by @ftnext. -
🌐 Add French translation fordocs/fr/docs/advanced/additional-status-code.md
. MR #5477 by @axel584. -
🌐 Add Portuguese translation fordocs/pt/docs/tutorial/request-forms-and-files.md
. MR #5579 by @batlopes. -
🌐 Add Japanese translation fordocs/ja/docs/advanced/websockets.md
. MR #4983 by @xryuseix.
Internal
-
✨ Use Ruff for linting. MR #5630 by @tiangolo. -
🛠 Add Arabic issue number to Notify Translations GitHub Action. MR #5610 by @tiangolo. -
⬆ Bump dawidd6/action-download-artifact from 2.24.1 to 2.24.2. MR #5609 by @dependabot[bot]. -
⬆ Bump dawidd6/action-download-artifact from 2.24.0 to 2.24.1. MR #5603 by @dependabot[bot]. -
📝 Update coverage badge to use Samuel Colvin's Smokeshow. MR #5585 by @tiangolo.
v0.86.0
Features
-
⬆ Add Python 3.11 to the officially supported versions. MR #5587 by @tiangolo. -
✅ Enable tests for Python 3.11. MR #4881 by @tiangolo.
Fixes
-
🐛 Close FormData (uploaded files) after the request is done. MR #5465 by @adriangb.
Docs
-
✏ Fix typo indocs/en/docs/tutorial/security/oauth2-jwt.md
. MR #5584 by @vivekashok1221.
Translations
-
🌐 Update wording in Chinese translation fordocs/zh/docs/python-types.md
. MR #5416 by @supercaizehua. -
🌐 Add Russian translation fordocs/ru/docs/deployment/index.md
. MR #5336 by @Xewus. -
🌐 Update Chinese translation fordocs/tutorial/security/oauth2-jwt.md
. MR #3846 by @jaystone776.
Internal
-
👷 Update FastAPI People to exclude bots: pre-commit-ci, dependabot. MR #5586 by @tiangolo. -
🎨 Format OpenAPI JSON intest_starlette_exception.py
. MR #5379 by @iudeen. -
👷 Switch from Codecov to Smokeshow plus pytest-cov to pure coverage for internal tests. MR #5583 by @tiangolo. -
👥 Update FastAPI People. MR #5571 by @github-actions[bot].
v0.85.2
Note: this release doesn't affect final users, it's mainly internal. It unlocks Pydanitc work with the integration that runs FastAPI's tests in Pydantic's CI.
Docs
-
✏ Fix grammar and add helpful links to dependencies indocs/en/docs/async.md
. MR #5432 by @pamelafox. -
✏ Fix broken link inalternatives.md
. MR #5455 by @su-shubham. -
✏ Fix typo in docs about contributing, for compatibility withpip
in Zsh. MR #5523 by @zhangbo2012. -
📝 Fix typo in docs with examples for Python 3.10 instead of 3.9. MR #5545 by @feliciss.
Translations
-
🌐 Add Portuguese translation fordocs/pt/docs/tutorial/request-forms.md
. MR #4934 by @batlopes. -
🌐 Add Chinese translation fordocs/zh/docs/tutorial/dependencies/classes-as-dependencies.md
. MR #4971 by @Zssaer. -
🌐 Add French translation fordeployment/deta.md
. MR #3692 by @rjNemo. -
🌐 Update Chinese translation fordocs/zh/docs/tutorial/query-params-str-validations.md
. MR #5255 by @hjlarry. -
🌐 Add Chinese translation fordocs/zh/docs/tutorial/sql-databases.md
. MR #4999 by @Zssaer. -
🌐 Add Chinese translation fordocs/zh/docs/advanced/wsgi.md
. MR #4505 by @ASpathfinder. -
🌐 Add Portuguese translation fordocs/pt/docs/tutorial/body-multiple-params.md
. MR #4111 by @lbmendes. -
🌐 Add Portuguese translation fordocs/pt/docs/tutorial/path-params-numeric-validations.md
. MR #4099 by @lbmendes. -
🌐 Add French translation fordeployment/versions.md
. MR #3690 by @rjNemo. -
🌐 Add French translation fordocs/fr/docs/help-fastapi.md
. MR #2233 by @JulianMaurin. -
🌐 Fix typo in Chinese translation fordocs/zh/docs/tutorial/security/first-steps.md
. MR #5530 by @yuki1sntSnow. -
🌐 Add Portuguese translation fordocs/pt/docs/tutorial/response-status-code.md
. MR #4922 by @batlopes. -
🔧 Add config for Tamil translations. MR #5563 by @tiangolo.
Internal
-
⬆ Bump internal dependency mypy from 0.971 to 0.982. MR #5541 by @dependabot[bot]. -
⬆ Bump nwtgck/actions-netlify from 1.2.3 to 1.2.4. MR #5507 by @dependabot[bot]. -
⬆ Bump internal dependency types-ujson from 5.4.0 to 5.5.0. MR #5537 by @dependabot[bot]. -
⬆ Bump dawidd6/action-download-artifact from 2.23.0 to 2.24.0. MR #5508 by @dependabot[bot]. -
⬆ Update internal dependency pytest-cov requirement from <4.0.0,>=2.12.0 to >=2.12.0,<5.0.0. MR #5539 by @dependabot[bot]. -
⬆ [pre-commit.ci] pre-commit autoupdate. MR #5536 by @pre-commit-ci[bot]. -
🐛 Fix internal Trio test warnings. MR #5547 by @samuelcolvin. -
⬆ [pre-commit.ci] pre-commit autoupdate. MR #5408 by @pre-commit-ci[bot]. -
⬆ ️ Upgrade Typer to include Rich in scripts for docs. MR #5502 by @tiangolo. -
🐛 Fix callingmkdocs
for languages as a subprocess to fix/enable MkDocs Material search plugin. MR #5501 by @tiangolo.
v0.85.1
Fixes
-
🐛 Fix support for strings in OpenAPI status codes:default
,1XX
,2XX
,3XX
,4XX
,5XX
. MR #5187 by @JarroVGIT.
Docs
Internal
-
👥 Update FastAPI People. MR #5447 by @github-actions[bot]. -
🔧 Disable Material for MkDocs search plugin. MR #5495 by @tiangolo. -
🔇 Ignore Trio warning in tests for CI. MR #5483 by @samuelcolvin.
v0.85.0
Features
-
⬆ Upgrade version required of Starlette from0.19.1
to0.20.4
. Initial MR #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
. MR #5401 by @tiangolo.
Internal
-
⬆ ️ Upgrade dependencies for doc and dev internal extras: Typer, Uvicorn. MR #5400 by @tiangolo. -
⬆ ️ Upgrade test dependencies: Black, HTTPX, databases, types-ujson. MR #5399 by @tiangolo. -
⬆ ️ Upgrade mypy and tweak internal type annotations. MR #5398 by @tiangolo. -
🔧 Update test dependencies, upgrade Pytest, move dependencies from dev to test. MR #5396 by @tiangolo.
v0.84.0
Breaking Changes
This version of FastAPI drops support for Python 3.6.
-
🔧 Update package metadata, drop support for Python 3.6, move build internals from Flit to Hatch. MR #5240 by @ofek.
v0.83.0
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 injsonable_encoder
for include and exclude with dataclasses. MR #4923 by @DCsunset.
Fixes
-
🐛 FixRuntimeError
raised whenHTTPException
has a status code with no content. MR #5365 by @iudeen. -
🐛 Fix empty reponse body when defaultstatus_code
is empty but the aResponse
parameter withresponse.status_code
is set. MR #5360 by @tmeckel.
Docs
Internal
-
⬆ [pre-commit.ci] pre-commit autoupdate. MR #5352 by @pre-commit-ci[bot].
v0.82.0
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
-
✨ ExportWebSocketState
infastapi.websockets
. MR #4376 by @matiuszka. -
✨ Support Python internal description on Pydantic model's docstring. MR #3032 by @Kludex. -
✨ UpdateORJSONResponse
to support nonstr
keys and serializing Numpy arrays. MR #3892 by @baby5.
Fixes
-
🐛 Allow exit code for dependencies withyield
to always execute, by removing capacity limiter for them, to e.g. allow closing DB connections without deadlocks. MR #5122 by @adriangb. -
🐛 Fix FastAPI People GitHub Action: set HTTPX timeout for GraphQL query request. MR #5222 by @iudeen. -
🐛 Make sure a parameter defined as required is kept required in OpenAPI even if defined as optional in another dependency. MR #4319 by @cd17822. -
🐛 Fix support for path parameters in WebSockets. MR #3879 by @davidbrochart.
Docs
-
✏ Update Hypercorn link, now pointing to GitHub. MR #5346 by @baconfield. -
✏ Tweak wording indocs/en/docs/advanced/dataclasses.md
. MR #3698 by @pfackeldey. -
📝 Add note about Python 3.10X | Y
operator in explanation about Response Models. MR #5307 by @MendyLanda. -
📝 Add link to New Relic article: "How to monitor FastAPI application performance using Python agent". MR #5260 by @sjyothi54. -
📝 Update docs forORJSONResponse
with details about improving performance. MR #2615 by @falkben. -
📝 Add docs for creating a custom Response class. MR #5331 by @tiangolo. -
📝 Add tip about using alias for form data fields. MR #5329 by @tiangolo.
Translations
-
🌐 Add Russian translation fordocs/ru/docs/features.md
. MR #5315 by @Xewus. -
🌐 Update Chinese translation fordocs/zh/docs/tutorial/request-files.md
. MR #4529 by @ASpathfinder. -
🌐 Add Chinese translation fordocs/zh/docs/tutorial/encoder.md
. MR #4969 by @Zssaer. -
🌐 Fix MkDocs file line for Portuguese translation ofbackground-task.md
. MR #5242 by @ComicShrimp.
Internal
-
👥 Update FastAPI People. MR #5347 by @github-actions[bot]. -
⬆ Bump dawidd6/action-download-artifact from 2.22.0 to 2.23.0. MR #5321 by @dependabot[bot]. -
⬆ [pre-commit.ci] pre-commit autoupdate. MR #5318 by @pre-commit-ci[bot]. -
✏ Fix a small code highlight line error. MR #5256 by @hjlarry. -
♻ Internal small refactor, moveoperation_id
parameter position in delete method for consistency with the code. MR #4474 by @hiel. -
🔧 Update sponsors, disable ImgWhale. MR #5338 by @tiangolo.
v0.81.0
Features
-
✨ Add ReDoc<noscript>
warning when JS is disabled. MR #5074 by @evroon. -
✨ Add support forFrozenSet
in parameters (e.g. query). MR #2938 by @juntatalor. -
✨ Allow custom middlewares to raiseHTTPException
s and propagate them. MR #2036 by @ghandic. -
✨ Preservejson.JSONDecodeError
information when handling invalid JSON in request body, to support custom exception handlers that use its information. MR #4057 by @UKnowWhoIm.
Fixes
-
🐛 Fixjsonable_encoder
for dataclasses with pydantic-compatible fields. MR #3607 by @himbeles. -
🐛 Fix support for extendingopenapi_extras
with parameter lists. MR #4267 by @orilevari.
Docs
-
✏ Fix a simple typo indocs/en/docs/python-types.md
. MR #5193 by @GlitchingCore. -
✏ Fix typos intests/test_schema_extra_examples.py
. MR #5126 by @supraaxdd. -
✏ Fix typos indocs/en/docs/tutorial/path-params-numeric-validations.md
. MR #5142 by @invisibleroads. -
📝 Add step about upgrading pip in the venv to avoid errors when installing dependenciesdocs/en/docs/contributing.md
. MR #5181 by @edisnake. -
✏ Reword and clarify text in tutorialdocs/en/docs/tutorial/body-nested-models.md
. MR #5169 by @papb. -
✏ Fix minor typo indocs/en/docs/features.md
. MR #5206 by @OtherBarry. -
✏ Fix minor typos indocs/en/docs/async.md
. MR #5125 by @Ksenofanex. -
📝 Add external link to docs: "Fastapi, Docker(Docker compose) and Postgres". MR #5033 by @krishnardt. -
📝 Simplify example for docs for Additional Responses, remove unnecessaryelse
. MR #4693 by @adriangb. -
📝 Update docs, compare enums with identity instead of equality. MR #4905 by @MicaelJarniac. -
✏ Fix typo indocs/en/docs/python-types.md
. MR #4886 by @MicaelJarniac. -
🎨 Fix syntax highlighting in docs for OpenAPI Callbacks. MR #4368 by @xncbf. -
✏ Reword confusing sentence in docs filetypo-fix-path-params-numeric-validations.md
. MR #3219 by @ccrenfroe. -
📝 Update docs for handling HTTP Basic Auth withsecrets.compare_digest()
to account for non-ASCII characters. MR #3536 by @lewoudar. -
📝 Update docs for testing, fix examples with relative imports. MR #5302 by @tiangolo.
Translations
-
🌐 Add Russian translation fordocs/ru/docs/index.md
. MR #5289 by @impocode. -
🌐 Add Russian translation fordocs/ru/docs/deployment/versions.md
. MR #4985 by @emp7yhead. -
🌐 Add Portuguese translation fordocs/pt/docs/tutorial/header-params.md
. MR #4921 by @batlopes. -
🌐 Updateko/mkdocs.yml
for a missing link. MR #5020 by @dalinaum.
Internal
-
⬆ Bump dawidd6/action-download-artifact from 2.21.1 to 2.22.0. MR #5258 by @dependabot[bot]. -
⬆ [pre-commit.ci] pre-commit autoupdate. MR #5196 by @pre-commit-ci[bot]. -
🔥 Delete duplicated tests intests/test_tutorial/test_sql_databases/test_sql_databases.py
. MR #5040 by @raccoonyy. -
♻ Simplify internal RegEx infastapi/utils.py
. MR #5057 by @pylounge. -
🔧 Fix Type hint ofauto_error
which does not need to beOptional[bool]
. MR #4933 by @DavidKimDY. -
🔧 Update mypy config, usestrict = true
instead of manual configs. MR #4605 by @michaeloliverx. -
♻ Change adict()
for{}
infastapi/utils.py
. MR #3138 by @ShahriyarR. -
♻ Move internal variable for errors injsonable_encoder
to put related code closer. MR #4560 by @GuilleQP. -
♻ Simplify conditional assignment infastapi/dependencies/utils.py
. MR #4597 by @cikay. -
⬆ Upgrade version pin accepted for Flake8, for internal code, toflake8 >=3.8.3,<6.0.0
. MR #4097 by @jamescurtin. -
🍱 Update Jina banner, fix typo. MR #5301 by @tiangolo.
v0.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 ofoauth2-redirect.html
to include fixes for flavors of authorization code flows in Swagger UI. MR #3439 initial MR by @koonpeng. -
♻ Strip empty whitespace from description extracted from docstrings. MR #2821 by @and-semakin. -
🐛 Fix cached dependencies when using a dependency inSecurity()
and other places (e.g.Depends()
) with different OAuth2 scopes. MR #2945 by @laggardkernel. -
🎨 Update type annotations forresponse_model
, allow things likeUnion[str, None]
. MR #5294 by @tiangolo.
Translations
-
🌐 Fix typos in German translation fordocs/de/docs/features.md
. MR #4533 by @0xflotus. -
🌐 Add missing navigator forencoder.md
in Korean translation. MR #5238 by @joonas-yoon. - (Empty MR merge by accident) #4913.
v0.79.1
Fixes
-
🐛 Fixjsonable_encoder
usinginclude
andexclude
parameters for non-Pydantic objects. MR #2606 by @xaviml. -
🐛 Fix edge case with repeated aliases names not shown in OpenAPI. MR #2351 by @klaa97. -
📝 Add misc dependency installs to tutorial docs. MR #2126 by @TeoZosa.
Docs
-
📝 Add note giving credit for illustrations to Ketrina Thompson. MR #5284 by @tiangolo. -
✏ Fix typo inpython-types.md
. MR #5116 by @Kludex. -
✏ Fix typo indocs/en/docs/python-types.md
. MR #5007 by @atiabbz. -
📝 Remove unneeded Django/Flask references from async topic intro. MR #5280 by @carltongibson. -
✨ Add illustrations for Concurrent burgers and Parallel burgers. MR #5277 by @tiangolo. Updated docs at: Concurrency and Burgers.
Translations
-
🌐 Add Portuguese translation fordocs/pt/docs/tutorial/query-params.md
. MR #4775 by @batlopes. -
🌐 Add Portuguese translation fordocs/pt/docs/tutorial/security/first-steps.md
. MR #4954 by @FLAIR7. -
🌐 Add translation fordocs/zh/docs/advanced/response-cookies.md
. MR #4638 by @zhangbo2012. -
🌐 Add French translation fordocs/fr/docs/deployment/index.md
. MR #3689 by @rjNemo. -
🌐 Add Portuguese translation fortutorial/handling-errors.md
. MR #4769 by @frnsimoes. -
🌐 Add French translation fordocs/fr/docs/history-design-future.md
. MR #3451 by @rjNemo. -
🌐 Add Russian translation fordocs/ru/docs/tutorial/background-tasks.md
. MR #4854 by @AdmiralDesu. -
🌐 Add Chinese translation fordocs/tutorial/security/first-steps.md
. MR #3841 by @jaystone776. -
🌐 Add Japanese translation fordocs/ja/docs/advanced/nosql-databases.md
. MR #4205 by @sUeharaE4. -
🌐 Add Indonesian translation fordocs/id/docs/tutorial/index.md
. MR #4705 by @bas-baskara. -
🌐 Add Persian translation fordocs/fa/docs/index.md
and tweak right-to-left CSS. MR #2395 by @mohsen-mahmoodi.
Internal
-
🔧 Update Jina sponsorship. MR #5283 by @tiangolo. -
🔧 Update Jina sponsorship. MR #5272 by @tiangolo. -
🔧 Update sponsors, Striveworks badge. MR #5179 by @tiangolo.
v0.79.0
Fixes - Breaking Changes
-
🐛 Fix removing body from status codes that do not support it. MR #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. MR #5050 by @itay-raveh. -
🔧 Add config for Swedish translations notification. MR #5147 by @tiangolo. -
🌐 Start of Swedish translation. MR #5062 by @MrRawbin. -
🌐 Add Japanese translation fordocs/ja/docs/advanced/index.md
. MR #5043 by @wakabame. -
🌐 🇵🇱 Add Polish translation fordocs/pl/docs/tutorial/first-steps.md
. MR #5024 by @Valaraucoo.
Internal
-
🔧 Update translations notification for Hebrew. MR #5158 by @tiangolo. -
🔧 Update Dependabot commit message. MR #5156 by @tiangolo. -
⬆ Bump actions/upload-artifact from 2 to 3. MR #5148 by @dependabot[bot]. -
⬆ Bump actions/cache from 2 to 3. MR #5149 by @dependabot[bot]. -
🔧 Update sponsors badge configs. MR #5155 by @tiangolo. -
👥 Update FastAPI People. MR #5154 by @tiangolo. -
🔧 Update Jina sponsor badges. MR #5151 by @tiangolo. -
⬆ Bump actions/checkout from 2 to 3. MR #5133 by @dependabot[bot]. -
⬆ [pre-commit.ci] pre-commit autoupdate. MR #5030 by @pre-commit-ci[bot]. -
⬆ Bump nwtgck/actions-netlify from 1.1.5 to 1.2.3. MR #5132 by @dependabot[bot]. -
⬆ Bump codecov/codecov-action from 2 to 3. MR #5131 by @dependabot[bot]. -
⬆ Bump dawidd6/action-download-artifact from 2.9.0 to 2.21.1. MR #5130 by @dependabot[bot]. -
⬆ Bump actions/setup-python from 2 to 4. MR #5129 by @dependabot[bot]. -
👷 Add Dependabot. MR #5128 by @tiangolo. -
♻ ️ Move fromOptional[X]
toUnion[X, None]
for internal utils. MR #5124 by @tiangolo. -
🔧 Update sponsors, remove Dropbase, add Doist. MR #5096 by @tiangolo. -
🔧 Update sponsors, remove Classiq, add ImgWhale. MR #5079 by @tiangolo.
v0.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. MR #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.
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 recommendingUnion
overOptional
and migrate source examples. New docs at Python Types Intro - UsingUnion
orOptional
. MR #4908 by @tiangolo. -
🎨 Fix default value as set in tutorial for Path Operations Advanced Configurations. MR #4899 by @tiangolo. -
📝 Add documentation for redefined path operations. MR #4864 by @madkinsz. -
📝 Updates links for Celery documentation. MR #4736 by @sammyzord. -
✏ Fix example code with sets in tutorial for body nested models. MR #3030 by @hitrust. -
✏ Fix links to Pydantic docs. MR #4670 by @kinuax. -
📝 Update docs about Swagger UI self-hosting with newer source links. MR #4813 by @Kastakin. -
📝 Add link to external article: Building the Poll App From Django Tutorial With FastAPI And React. MR #4778 by @jbrocher. -
📝 Add OpenAPI warning to "Body - Fields" docs with extra schema extensions. MR #4846 by @ml-evs.
Translations
-
🌐 Fix code examples in Japanese translation fordocs/ja/docs/tutorial/testing.md
. MR #4623 by @hirotoKirimaru.
Internal
-
♻ Refactor dict value extraction to minimize key lookupsfastapi/utils.py
. MR #3139 by @ShahriyarR. -
✅ Add tests for required nonable parameters and body fields. MR #4907 by @tiangolo. -
👷 Fix installing Material for MkDocs Insiders in CI. MR #4897 by @tiangolo. -
👷 Add pre-commit CI instead of custom GitHub Action. MR #4896 by @tiangolo. -
👷 Add pre-commit GitHub Action workflow. MR #4895 by @tiangolo. -
📝 Add dark mode auto switch to docs based on OS preference. MR #4869 by @ComicShrimp. -
🔥 Remove un-used old pending tests, already covered in other places. MR #4891 by @tiangolo. -
🔧 Add Python formatting hooks to pre-commit. MR #4890 by @tiangolo. -
🔧 Add pre-commit with first config and first formatting pass. MR #4888 by @tiangolo. -
👷 Disable CI installing Material for MkDocs in forks. MR #4410 by @dolfinus.
v0.77.1
Upgrades
Docs
-
📝 Add link to german article: REST-API Programmieren mittels Python und dem FastAPI Modul. MR #4624 by @fschuermeyer. -
📝 Add external link: PyCharm Guide to FastAPI. MR #4512 by @mukulmantosh. -
📝 Add external link to article: Building an API with FastAPI and Supabase and Deploying on Deta. MR #4440 by @aUnicornDev. -
✏ Fix small typo indocs/en/docs/tutorial/security/first-steps.md
. MR #4515 by @KikoIlievski.
Translations
-
🌐 Add Polish translation fordocs/pl/docs/tutorial/index.md
. MR #4516 by @MKaczkow. -
✏ Fix typo in deployment. MR #4629 by @raisulislam541. -
🌐 Add Portuguese translation fordocs/pt/docs/help-fastapi.md
. MR #4583 by @mateusjs.
Internal
-
🔧 Add notifications in issue for Uzbek translations. MR #4884 by @tiangolo.
v0.77.0
Upgrades
-
⬆ Upgrade Starlette from 0.18.0 to 0.19.0. MR #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. MR #4414 by @silvanmelchior. -
📝 Add external link to article: 5 Advanced Features of FastAPI You Should Try. MR #4436 by @kaustubhgupta. -
✏ Reword to improve legibility of docs aboutTestClient
. MR #4389 by @rgilton. -
📝 Add external link to blog post about Kafka, FastAPI, and Ably. MR #4044 by @Ugbot. -
✏ Fix typo indocs/en/docs/tutorial/sql-databases.md
. MR #4875 by @wpyoga. -
✏ Fix typo indocs/en/docs/async.md
. MR #4726 by @Prezu.
Translations
-
🌐 Update source example highlights fordocs/zh/docs/tutorial/query-params-str-validations.md
. MR #4237 by @caimaoy. -
🌐 Remove translation docs references to aiofiles as it's no longer needed since AnyIO. MR #3594 by @alonme. -
✏ 🌐 Fix typo in Portuguese translation fordocs/pt/docs/tutorial/path-params.md
. MR #4722 by @CleoMenezesJr. -
🌐 Fix live docs server for translations for some languages. MR #4729 by @wakabame. -
🌐 Add Portuguese translation fordocs/pt/docs/tutorial/cookie-params.md
. MR #4112 by @lbmendes. -
🌐 Fix French translation fordocs/tutorial/body.md
. MR #4332 by @Smlep. -
🌐 Add Japanese translation fordocs/ja/docs/advanced/conditional-openapi.md
. MR #2631 by @sh0nk. -
🌐 Fix Japanese translation ofdocs/ja/docs/tutorial/body.md
. MR #3062 by @a-takahashi223. -
🌐 Add Portuguese translation fordocs/pt/docs/tutorial/background-tasks.md
. MR #2170 by @izaguerreiro. -
🌐 Add Portuguese translation fordocs/deployment/deta.md
. MR #4442 by @lsglucas. -
🌐 Add Russian translation fordocs/async.md
. MR #4036 by @Winand. -
🌐 Add Portuguese translation fordocs/tutorial/body.md
. MR #3960 by @leandrodesouzadev. -
🌐 Add Portuguese translation oftutorial/extra-data-types.md
. MR #4077 by @luccasmmg. -
🌐 Update German translation fordocs/features.md
. MR #3905 by @jomue.
v0.76.0
Upgrades
Internal
-
👥 Update FastAPI People. MR #4847 by @github-actions[bot]. -
🔧 Add Budget Insight sponsor. MR #4824 by @tiangolo. -
🍱 Update sponsor, ExoFlare badge. MR #4822 by @tiangolo. -
🔧 Update sponsors, enable Dropbase again, update TalkPython link. MR #4821 by @tiangolo.
v0.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 fixedValidationError
JSON Schema. MR #4806 by @tiangolo. -
🐛 Fix JSON Schema forValidationError
at fieldloc
. MR #3810 by @dconathan. -
🐛 Fix support for prefix on APIRouter WebSockets. MR #2640 by @Kludex.
Upgrades
-
⬆ ️ Update ujson ranges for CVE-2021-45958. MR #4804 by @tiangolo. -
⬆ ️ Upgrade dependencies upper range for extras "all". MR #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. MR #4347 by @RAlanWright.
Internal
-
🔧 Update sponsors, add: ExoFlare, Ines Course; remove: Dropbase, Vim.so, Calmcode; update: Striveworks, TalkPython and TestDriven.io. MR #4805 by @tiangolo. -
⬆ ️ Upgrade Codecov GitHub Action. MR #4801 by @tiangolo.
v0.75.1
Translations
-
🌐 Start Dutch translations. MR #4703 by @tiangolo. -
🌐 Start Persian/Farsi translations. MR #4243 by @aminalaee. -
✏ Reword sentence about handling errors. MR #1993 by @khuhroproeza.
Internal
-
👥 Update FastAPI People. MR #4752 by @github-actions[bot]. -
➖ Temporarily remove typer-cli from dependencies and upgrade Black to unblock Pydantic CI. MR #4754 by @tiangolo. -
🔧 Add configuration to notify Dutch translations. MR #4702 by @tiangolo. -
👥 Update FastAPI People. MR #4699 by @github-actions[bot]. -
🐛 Fix FastAPI People generation to include missing file in commit. MR #4695 by @tiangolo. -
🔧 Update Classiq sponsor links. MR #4688 by @tiangolo. -
🔧 Add Classiq sponsor. MR #4671 by @tiangolo. -
📝 Add Jina's QA Bot to the docs to help people that want to ask quick questions. MR #4655 by @tiangolo based on original MR #4626 by @hanxiao.
v0.75.0
Features
-
✨ Add support for customgenerate_unique_id_function
and docs for generating clients. New docs: Advanced - Generate Clients. MR #4650 by @tiangolo.
v0.74.1
Features
-
✨ Include route in scope to allow middleware and other tools to extract its information. MR #4603 by @tiangolo.
v0.74.0
Breaking Changes
-
✨ Update internalAsyncExitStack
to fix context for dependencies withyield
. MR #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 MR #4575 from above also fixes the
contextvars
context for the code before and afteryield
. This was the main objective of that MR.
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 MR description #4575.
Internal
-
🔧 Add Striveworks sponsor. MR #4596 by @tiangolo. -
💚 Only build docs on push when on master to avoid duplicate runs from MRs. MR #4564 by @tiangolo. -
👥 Update FastAPI People. MR #4502 by @github-actions[bot].
v0.73.0
Features
-
✨ Add support for declaringUploadFile
parameters without explicitFile()
. MR #4469 by @tiangolo. New docs: Request Files - File Parameters with UploadFile. -
✨ Add support for tags with Enums. MR #4468 by @tiangolo. New docs: Path Operation Configuration - Tags with Enums. -
✨ Allow hiding from OpenAPI (and Swagger UI)Query
,Cookie
,Header
, andPath
parameters. MR #3144 by @astraldawn. New docs: Query Parameters and String Validations - Exclude from OpenAPI.
Docs
-
📝 Tweak and improve docs for Request Files. MR #4470 by @tiangolo.
Fixes
-
🐛 Fix bug preventing to use OpenAPI when using tuples. MR #3874 by @victorbenichoux. -
🐛 Prefer custom encoder over defaults if specified injsonable_encoder
. MR #2061 by @viveksunder.-
💚 Duplicate MR to trigger CI. MR #4467 by @tiangolo.
-
Internal
-
🐛 Fix docs dependencies cache, to get the latest Material for MkDocs. MR #4466 by @tiangolo. -
🔧 Add sponsor Dropbase. MR #4465 by @tiangolo.
v0.72.0
Features
-
✨ Enable configuring Swagger UI parameters. Original MR #2568 by @jmriebold. Here are the new docs: Configuring Swagger UI.
Docs
-
📝 Update Python Types docs, add missing 3.6 / 3.9 example. MR #4434 by @tiangolo.
Translations
-
🌐 Update Chinese translation fordocs/help-fastapi.md
. MR #3847 by @jaystone776. -
🌐 Fix Korean translation fordocs/ko/docs/index.md
. MR #4195 by @kty4119. -
🌐 Add Polish translation fordocs/pl/docs/index.md
. MR #4245 by @MicroPanda123. -
🌐 Add Chinese translation fordocs\tutorial\path-operation-configuration.md
. MR #3312 by @jaystone776.
Internal
-
🔧 Enable MkDocs Material Insiders'content.tabs.link
. MR #4399 by @tiangolo.
Configuration
-
If you want to rebase/retry this MR, check this box
This MR has been generated by Renovate Bot.