FastAPI: Python Web Framework for Building APIs
GitHub Repo
MIT
October 22, 2026 at 01:32 PM
0 views

FastAPI: Python Web Framework for Building APIs

@fastapiProject Author

What FastAPI is

FastAPI is a Python web framework for building APIs, based on standard Python type hints. You declare path, query and body parameters as typed function arguments, and FastAPI uses those declarations to validate input, convert data to and from JSON, and generate an OpenAPI schema with interactive documentation. The README lists its goals as high performance, fast development, fewer bugs, strong editor support, short code, production readiness, and compatibility with open standards: OpenAPI (previously Swagger) and JSON Schema.

It is for Python developers building REST or JSON APIs, ML model serving endpoints, internal services and backends. The README quotes engineers at Microsoft, Uber, Netflix and Cisco describing their use of it, including ML services and Netflix's open-sourced Dispatch crisis-management framework. FastAPI is MIT-licensed and was created in December 2018.

How it works

FastAPI "stands on the shoulders of giants": Starlette handles the web parts and Pydantic the data parts. Starlette provides the ASGI routing, requests, responses, WebSockets and middleware; Pydantic models describe request and response bodies and do the validation and serialisation. Applications are served by an ASGI server, and the standard install includes Uvicorn.

The core idea is that one declaration does several jobs. Writing item_id: int as a function parameter gives editor completion and type checks, validates that the value is an integer (returning a clear error if not), converts it from the URL, and documents it in the OpenAPI schema. A parameter with a default of None becomes optional. A Pydantic model parameter such as item: Item tells FastAPI to read the request body as JSON, check required and optional fields, and validate nested objects. Handlers can be plain def or async def.

From that schema FastAPI serves two documentation UIs: Swagger UI at /docs, where you can try requests directly, and ReDoc at /redoc. The same OpenAPI output can feed client code generators for other languages.

Key features

  • Type-hint driven validation of path, query, header, cookie, form and file parameters, including deeply nested JSON bodies.
  • Automatic data conversion for str, int, float, bool, lists, datetime, UUID, database models and more.
  • Interactive API docs: Swagger UI and ReDoc generated from the OpenAPI schema.
  • Dependency injection: the README calls it a very powerful and easy to use system, and the tutorial and user guide cover it in depth.
  • Security utilities: OAuth2 with JWT tokens and HTTP Basic auth.
  • Validation constraints such as maximum length or regular expressions on parameters.
  • Starlette extras: WebSockets, CORS, cookie sessions, and tests based on HTTPX and pytest.
  • GraphQL integration through Strawberry and other libraries.
  • FastAPI CLI: fastapi dev finds the app in main.py and starts Uvicorn with auto-reload; fastapi run is the production counterpart.

Getting started

The README recommends installing uv first and adding FastAPI with its standard extras (keep the quotes so every shell accepts it):

uv add "fastapi[standard]"

Create main.py:

from fastapi import FastAPI

app = FastAPI()


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


@app.get("/items/{item_id}")
def read_item(item_id: int, q: str | None = None):
    return {"item_id": item_id, "q": q}

Run the development server, which watches for changes and reloads:

uv run fastapi dev

Then open http://127.0.0.1:8000/items/5?q=somequery to see the JSON response, /docs for Swagger UI and /redoc for ReDoc. Adding a Pydantic BaseModel and a PUT route updates the docs automatically, including the new request body.

Adding a request body

The README's next step declares the body with a Pydantic model and a PUT route that accepts item: Item. The model looks like this:

from fastapi import FastAPI
from pydantic import BaseModel

app = FastAPI()


class Item(BaseModel):
    name: str
    price: float
    is_offer: bool | None = None

With that single declaration, a PUT to /items/{item_id} must carry a JSON body with a string name and a float price, while is_offer is optional. Invalid input gets an automatic, descriptive error response, editors can autocomplete item.name and item.price inside the handler, and the Swagger UI page gains a "Try it out" form for the new body without any extra code. The user guide builds on the same pattern for headers, cookies, form fields, file uploads and nested models.

The standard extra pulls in Uvicorn, fastapi-cli, Jinja2, python-multipart, email-validator and an HTTP client for the TestClient. For a minimal install, or one without the cloud deploy tool, the README offers:

uv add fastapi
uv add "fastapi[standard-no-fastapi-cloud-cli]"

Use cases

  • JSON and REST APIs where request validation and accurate documentation should come from the same code.
  • Serving machine learning models behind prediction endpoints, a pattern the README's quotes describe at Microsoft and Uber.
  • Internal microservices whose OpenAPI schema is used to generate typed clients for other teams.
  • Backends that mix HTTP endpoints with WebSockets.
  • Prototypes that need working, browsable docs from day one.

How it compares

For performance, the README cites independent TechEmpower benchmarks placing FastAPI applications under Uvicorn among the fastest Python frameworks, below only Starlette and Uvicorn themselves, which FastAPI uses internally. As always, benchmark results depend on the test and the workload. Compared with Starlette alone, FastAPI adds the type-driven validation, dependency injection and documentation layer on top. Among other Python frameworks, Flask and Django are the obvious points of reference: they are older and broader in scope (Django in particular ships an ORM, admin and templating), while FastAPI focuses on APIs and leans on Pydantic and ASGI. Its documentation also points to Typer, a sibling project from the same author, for building CLIs in the same style.

Things to know before adopting

  • FastAPI Cloud is bundled by default: fastapi[standard] includes fastapi-cloud-cli, which adds fastapi deploy for the commercial FastAPI Cloud service built by the same team. Use the standard-no-fastapi-cloud-cli extra if you do not want it. The README says FastAPI Cloud is the primary sponsor and funding provider for the FastAPI family of projects; apps can be deployed to any provider.
  • Productivity figures are estimates: the README's claims of 200% to 300% faster feature development and about 40% fewer developer-induced errors are, by its own footnote, based on tests by an internal development team.
  • Dependencies: the core depends on Pydantic and Starlette, so their release cycles and breaking changes affect you. Optional extras include pydantic-settings, pydantic-extra-types, orjson and ujson.
  • Choosing def or async def: both work, and the README sends readers who are unsure to the "In a hurry?" section of the async docs before deciding which to use for a given handler.
  • Related tooling: fastapi dev and fastapi run come from fastapi-cli, which the README lists as part of the standard extra along with Uvicorn.
  • Licence: MIT.

Project activity

As of October 2026 the repository has about 103,500 stars and roughly 10,100 forks. It was created in December 2018, is written in Python, is licensed under MIT, and was last pushed in October 2026. Documentation is at fastapi.tiangolo.com and the source is at github.com/fastapi/fastapi.

Enjoying this project?

Discover more amazing open-source projects on TechLogHub. We curate the best developer tools and projects.

Project
fastapi
Created
October 22
Last Updated
October 22, 2026 at 01:32 PM

Maintain FastAPI: Python Web Framework for Building APIs? Add the badge to your README

Show that the project is featured on TechLogHub and send readers to this write-up.

Featured on TechLogHub
[![Featured on TechLogHub](https://techloghub.com/badge-neutral.svg)](https://techloghub.com/open-source/fastapi?utm_source=techloghub_badge&utm_medium=referral&utm_campaign=readme)

Find more projects like this

One email a week: new and trending developer tools, fresh comparisons, and what shipped. Unsubscribe in one click.