Skip to content

0.89.0

Compare
Choose a tag to compare
@tiangolo tiangolo released this 07 Jan 17:22
· 1694 commits to master since this release

Features

  • ✨ Add support for function return type annotations to declare the response_model. Initial PR #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

Translations

  • 🌐 Add Russian translation for docs/ru/docs/fastapi-people.md. PR #5577 by @Xewus.
  • 🌐 Fix typo in Chinese translation for docs/zh/docs/benchmarks.md. PR #4269 by @15027668g.
  • 🌐 Add Korean translation for docs/tutorial/cors.md. PR #3764 by @NinaHwang.

Internal