Skip to content

Releases: tiangolo/fastapi

0.75.2

17 Apr 21:11
Compare
Choose a tag to compare

This release includes upgrades to third-party packages that handle security issues. Although there's a chance these issues don't affect you in particular, please upgrade as soon as possible.

Fixes

  • ✅ Fix new/recent tests with new fixed ValidationError JSON Schema. PR #4806 by @tiangolo.
  • 🐛 Fix JSON Schema for ValidationError at field loc. PR #3810 by @dconathan.
  • 🐛 Fix support for prefix on APIRouter WebSockets. PR #2640 by @Kludex.

Upgrades

  • ⬆️ Update ujson ranges for CVE-2021-45958. PR #4804 by @tiangolo.
  • ⬆️ Upgrade dependencies upper range for extras "all". PR #4803 by @tiangolo.
  • ⬆ Upgrade Swagger UI - swagger-ui-dist@4. This handles a security issue in Swagger UI itself where it could be possible to inject HTML into Swagger UI. Please upgrade as soon as you can, in particular if you expose your Swagger UI (/docs) publicly to non-expert users. PR #4347 by @RAlanWright.

Internal

  • 🔧 Update sponsors, add: ExoFlare, Ines Course; remove: Dropbase, Vim.so, Calmcode; update: Striveworks, TalkPython and TestDriven.io. PR #4805 by @tiangolo.
  • ⬆️ Upgrade Codecov GitHub Action. PR #4801 by @tiangolo.

0.75.1

01 Apr 23:08
Compare
Choose a tag to compare

Translations

Internal

0.75.0

04 Mar 22:11
Compare
Choose a tag to compare

Features

0.74.1

21 Feb 15:56
Compare
Choose a tag to compare

Features

  • ✨ Include route in scope to allow middleware and other tools to extract its information. PR #4603 by @tiangolo.

0.74.0

17 Feb 16:11
Compare
Choose a tag to compare

Breaking Changes

  • ✨ Update internal AsyncExitStack to fix context for dependencies with yield. PR #4575 by @tiangolo.

Dependencies with yield can now catch HTTPException and custom exceptions. For example:

async def get_database():
    with Session() as session:
        try:
            yield session
        except HTTPException:
            session.rollback()
            raise
        finally:
            session.close()

After the dependency with yield handles the exception (or not) the exception is raised again. So that any exception handlers can catch it, or ultimately the default internal ServerErrorMiddleware.

If you depended on exceptions not being received by dependencies with yield, and receiving an exception breaks the code after yield, you can use a block with try and finally:

async def do_something():
    try:
        yield something
    finally:
        some_cleanup()

...that way the finally block is run regardless of any exception that might happen.

Features

  • The same PR #4575 from above also fixes the contextvars context for the code before and after yield. This was the main objective of that PR.

This means that now, if you set a value in a context variable before yield, the value would still be available after yield (as you would intuitively expect). And it also means that you can reset the context variable with a token afterwards.

For example, this works correctly now:

from contextvars import ContextVar
from typing import Any, Dict, Optional


legacy_request_state_context_var: ContextVar[Optional[Dict[str, Any]]] = ContextVar(
    "legacy_request_state_context_var", default=None
)

async def set_up_request_state_dependency():
    request_state = {"user": "deadpond"}
    contextvar_token = legacy_request_state_context_var.set(request_state)
    yield request_state
    legacy_request_state_context_var.reset(contextvar_token)

...before this change it would raise an error when resetting the context variable, because the contextvars context was different, because of the way it was implemented.

Note: You probably don't need contextvars, and you should probably avoid using them. But they are powerful and useful in some advanced scenarios, for example, migrating from code that used Flask's g semi-global variable.

Technical Details: If you want to know more of the technical details you can check out the PR description #4575.

Internal

0.73.0

23 Jan 22:43
Compare
Choose a tag to compare

Features

Docs

  • 📝 Tweak and improve docs for Request Files. PR #4470 by @tiangolo.

Fixes

Internal

  • 🐛 Fix docs dependencies cache, to get the latest Material for MkDocs. PR #4466 by @tiangolo.
  • 🔧 Add sponsor Dropbase. PR #4465 by @tiangolo.

0.72.0

16 Jan 20:11
Compare
Choose a tag to compare

Features

Docs

  • 📝 Update Python Types docs, add missing 3.6 / 3.9 example. PR #4434 by @tiangolo.

Translations

  • 🌐 Update Chinese translation for docs/help-fastapi.md. PR #3847 by @jaystone776.
  • 🌐 Fix Korean translation for docs/ko/docs/index.md. PR #4195 by @kty4119.
  • 🌐 Add Polish translation for docs/pl/docs/index.md. PR #4245 by @MicroPanda123.
  • 🌐 Add Chinese translation for docs\tutorial\path-operation-configuration.md. PR #3312 by @jaystone776.

Internal

  • 🔧 Enable MkDocs Material Insiders' content.tabs.link. PR #4399 by @tiangolo.

0.71.0

07 Jan 17:11
Compare
Choose a tag to compare

Features

  • ✨ Add docs and tests for Python 3.9 and Python 3.10. PR #3712 by @tiangolo.
    • You can start with Python Types Intro, it explains what changes between different Python versions, in Python 3.9 and in Python 3.10.
    • All the FastAPI docs are updated. Each code example in the docs that could use different syntax in Python 3.9 or Python 3.10 now has all the alternatives in tabs.
  • ⬆️ Upgrade Starlette to 0.17.1. PR #4145 by @simondale00.

Internal

0.70.1

12 Dec 11:41
Compare
Choose a tag to compare

There's nothing interesting in this particular FastAPI release. It is mainly to enable/unblock the release of the next version of Pydantic that comes packed with features and improvements. 🤩

Fixes

  • 🐛 Fix JSON Schema for dataclasses, supporting the fixes in Pydantic 1.9. PR #4272 by @PrettyWood.

Translations

  • 🌐 Add Korean translation for docs/tutorial/request-forms-and-files.md. PR #3744 by @NinaHwang.
  • 🌐 Add Korean translation for docs/tutorial/request-files.md. PR #3743 by @NinaHwang.
  • 🌐 Add portuguese translation for docs/tutorial/query-params-str-validations.md. PR #3965 by @leandrodesouzadev.
  • 🌐 Add Korean translation for docs/tutorial/response-status-code.md. PR #3742 by @NinaHwang.
  • 🌐 Add Korean translation for Tutorial - JSON Compatible Encoder. PR #3152 by @NEONKID.
  • 🌐 Add Korean translation for Tutorial - Path Parameters and Numeric Validations. PR #2432 by @hard-coders.
  • 🌐 Add Korean translation for docs/ko/docs/deployment/versions.md. PR #4121 by @DevDae.
  • 🌐 Fix Korean translation for docs/ko/docs/tutorial/index.md. PR #4193 by @kimjaeyoonn.
  • 🔧 Add CryptAPI sponsor. PR #4264 by @tiangolo.
  • 📝 Update docs/tutorial/dependencies/classes-as-dependencies: Add type of query parameters in a description of Classes as dependencies. PR #4015 by @0417taehyun.
  • 🌐 Add French translation for Tutorial - First steps. PR #3455 by @Smlep.
  • 🌐 Add French translation for docs/tutorial/path-params.md. PR #3548 by @Smlep.
  • 🌐 Add French translation for docs/tutorial/query-params.md. PR #3556 by @Smlep.
  • 🌐 Add Turkish translation for docs/python-types.md. PR #3926 by @BilalAlpaslan.

Internal

0.70.0

07 Oct 17:39
Compare
Choose a tag to compare

This release just upgrades Starlette to the latest version, 0.16.0, which includes several bug fixes and some small breaking changes.

These last three consecutive releases are independent so that you can migrate gradually:

  • First to FastAPI 0.68.2, with no breaking changes, but upgrading all the sub-dependencies.
  • Next to FastAPI 0.69.0, which upgrades Starlette to 0.15.0, with AnyIO support, and a higher chance of having breaking changes in your code.
  • Finally to FastAPI 0.70.0, just upgrading Starlette to the latest version 0.16.0 with additional bug fixes.

This way, in case there was a breaking change for your code in one of the releases, you can still benefit from the previous upgrades. ✨

Breaking Changes - Upgrade

Also upgrades the ranges of optional dependencies:

  • "jinja2 >=2.11.2,<4.0.0"
  • "itsdangerous >=1.1.0,<3.0.0"