FastAPI explained

FastAPI
Developer:Sebastián Ramírez
Released:[1]
Programming Language:Python
Genre:Web framework
License:MIT

FastAPI is a web framework for building HTTP-based service APIs in Python 3.8+.[2] It uses Pydantic and type hints to validate, serialize and deserialize data. It also automatically generates OpenAPI documentation for APIs built with it.[3] It was first released in 2018.

Components

Pydantic

Pydantic is a data validation library for Python. While writing code in an IDE, Pydantic provides type hints for schema validation and serialization through type annotations.[4]

Starlette

Starlette is a lightweight ASGI framework/toolkit, to support async functionality in Python.[5]

Uvicorn

Uvicorn is a minimal low-level server/application web server for async frameworks, following the ASGI specification. Technically, it implements a multi-process model with one main process, which is responsible for managing a pool of worker processes and distributing incoming HTTP requests to them. The number of worker processes is pre-configured, but can also be adjusted up or down at runtime.[6]

Example

The following code shows a simple web application that displays "Hello World!" when visited:

from fastapi import FastAPI

app = FastAPI

@app.get("/")def read_root: return "Hello World!"

See also

Notes and References

  1. Web site: fastapi repo . . 2018-12-05.
  2. Web site: FastAPI . 2024-04-10 . fastapi.tiangolo.com.
  3. Book: Lubanovic . Bill . Introducing Python: Modern Computing in Simple Packages . 2019-11-06 . O'Reilly Media, Inc . 9781492051367 . 397, 418 . 2nd .
  4. Web site: Why use Pydantic - Pydantic . 2023-09-21 . docs.pydantic.dev.
  5. Web site: Starlette . 2023-09-21 . www.starlette.io.
  6. Web site: Restarting 'uvicorn' Workers with the 'SIGHUP' Signal . 2024-06-17 . bugfactory.io.