FastAPI

{{Short description|Web framework for Python}}

{{Multiple issues|

{{Advert|date=February 2022}}

{{Primary sources|date=February 2022}}

}}

{{Infobox software

| name = FastAPI

| logo = FastAPI logo.svg

| logo size = 200px

| developer = Sebastián Ramírez

| released = {{Start date and age|2018|12|05}}{{cite web |title=fastapi repo | website=GitHub |url=https://github.com/tiangolo/fastapi/commits/master?after=eddbae948f04e13fe412dc45a569d10e34b698a4+1990&branch=master |date=2018-12-05}}

| latest release version = {{wikidata|property|reference|edit|P348}}

| latest release date = {{start date and age|{{wikidata|qualifier|P348|P577}}}}

| repo = {{URL|https://github.com/tiangolo/fastapi}}

| programming language = Python

| genre = Web framework

| license = MIT

| website = {{URL|https://fastapi.tiangolo.com/}}

}}

FastAPI is a high-performance web framework for building HTTP-based service APIs in Python 3.8+.{{Cite web |title=FastAPI |url=https://fastapi.tiangolo.com/ |access-date=2024-04-10 |website=fastapi.tiangolo.com}} It uses Pydantic and type hints to validate, serialize and deserialize data. FastAPI also automatically generates OpenAPI documentation for APIs built with it.{{cite book |last1=Lubanovic |first1=Bill |title=Introducing Python: Modern Computing in Simple Packages |date=2019-11-06 |publisher=O'Reilly Media, Inc |isbn=9781492051367 |pages=397, 418 |edition=2nd |url=https://www.oreilly.com/library/view/introducing-python-2nd/9781492051374/}} 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.{{Cite web |title=Why use Pydantic - Pydantic |url=https://docs.pydantic.dev/latest/why/#performance |access-date=2023-09-21 |website=docs.pydantic.dev}}

= Starlette =

Starlette is a lightweight ASGI framework/toolkit, to support async functionality in Python.{{Cite web |title=Starlette |url=https://www.starlette.io/ |access-date=2023-09-21 |website=www.starlette.io}}

= Uvicorn =

Uvicorn is a minimal low-level server/application web server for async frameworks, following the [https://asgi.readthedocs.io/en/latest/ 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.{{Cite web |title=Restarting 'uvicorn' Workers with the 'SIGHUP' Signal |url=https://bugfactory.io/articles/restarting-uvicorn-workers-with-the-sighup-signal/ |access-date=2024-06-17 |website=bugfactory.io}}

= OpenAPI Integration =

FastAPI automatically generates OpenAPI documentation for APIs. This documentation includes both Swagger UI and ReDoc, which provide interactive API documentation that you can use to explore and test your endpoints in real time. This is particularly useful for developing, testing, and sharing APIs with other developers or users.https://fastapi.tiangolo.com/reference/openapi/docs/

Example

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

from fastapi import FastAPI

app = FastAPI()

@app.get("/")

async def read_root():

return "Hello World!"

See also

{{Portal|Free and open-source software}}

References