pypi fastapi 0.114.0

latest releases: 0.115.0, 0.114.2, 0.114.1...
12 days ago

You can restrict form fields to only include those declared in a Pydantic model and forbid any extra field sent in the request using Pydantic's model_config = {"extra": "forbid"}:

from typing import Annotated

from fastapi import FastAPI, Form
from pydantic import BaseModel

app = FastAPI()


class FormData(BaseModel):
    username: str
    password: str
    model_config = {"extra": "forbid"}


@app.post("/login/")
async def login(data: Annotated[FormData, Form()]):
    return data

Read the new docs: Form Models - Forbid Extra Form Fields.

Features

  • ✨ Add support for forbidding extra form fields with Pydantic models. PR #12134 by @tiangolo.

Docs

  • 📝 Update docs, Form Models section title, to match config name. PR #12152 by @tiangolo.

Internal

  • ✅ Update internal tests for latest Pydantic, including CI tweaks to install the latest Pydantic. PR #12147 by @tiangolo.

Don't miss a new fastapi release

NewReleases is sending notifications on new releases.