# FastAPI

> A Python framework for building web APIs. It checks inputs and writes docs for you.

**Field:** Software Development  
**Category:** Web Development  
**Also known as:** Fast API, FastAPI Framework, Python FastAPI

## Think of it like

Think of it like a form with labelled boxes. Wrong kinds of answer are turned back at the door.

## Definition

FastAPI is a Python framework for building web APIs. You write a plain Python function for each route. Type hints on the inputs tell FastAPI what to expect. It checks every request against them and turns away bad ones. It also writes interactive API docs for you, at /docs. It is built on two other libraries, Starlette and Pydantic.

## Example

Jack writes a route that takes an item_id typed as int. When someone sends /items/abc, FastAPI answers with a clear error.

## Example code

```python
from fastapi import FastAPI

app = FastAPI()

@app.get("/items/{item_id}")
def read_item(item_id: int):
    return {"item_id": item_id}
```

One route. The int type hint means /items/abc is refused before your code runs.

## Why it matters

Many Python teams build APIs with it, including for AI models. The free docs page saves hours of writing.

## Common mistake

Leaving out type hints. They are what FastAPI uses to check data and write the docs.

## Three principles

- **Type hints drive it.** They decide what each route accepts.
- **Checks for you.** Bad input is refused with a clear error.
- **Free docs.** A live API page appears at /docs.

## Related terms

- [Python](https://learn.benibix.com/term/development/python)
- [Flask](https://learn.benibix.com/term/development/flask)
- [Django](https://learn.benibix.com/term/development/django)
- [Type Annotation](https://learn.benibix.com/term/development/type-annotation)
- [OpenAPI Specification](https://learn.benibix.com/term/development/openapi)
- [REST API](https://learn.benibix.com/term/development/rest-api)

![A request, GET /orders, passes left to right through two boxes, middleware 1 that logs it and middleware 2 that checks the login, then reaches the route, which gets the orders and sends a reply, 200 OK. A dashed arrow drops down from the login check to a box saying not logged in, stops here with 401.](https://learn.benibix.com/diagrams/dev-middleware.svg)

---

Source: https://learn.benibix.com/term/development/fastapi
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-17
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
