FastAPI framework, high performance, easy to learn, fast to code, ready for production
--- **Documentation**: https://fastapi.tiangolo.com **Source Code**: https://github.com/fastapi/fastapi --- # Overview FastAPI is a modern, fast (high‑performance) web framework for building APIs with Python 3.8+ based on standard Python type hints. It combines the speed of **Node.js** and **Go** with the developer friendliness of **Python**, delivering: * **Performance** – on par with the fastest Python frameworks because it is built on **Starlette** for the web parts and **Pydantic** for the data parts. * **Fast to code** – increase development speed by 200 %–300 % thanks to automatic request validation, serialization, interactive API docs, and editor autocompletion. * **Reduced bugs** – data validation and type checking catch many errors at runtime, lowering the chance of human‑introduced bugs. * **Intuitive** – editors provide instant completion and type checking for request bodies, query parameters, headers, and more. * **Production ready** – OpenAPI, JSON‑Schema, automatic interactive documentation (Swagger UI & ReDoc), dependency injection, security utilities, and extensive testing support. # Installation FastAPI is released on PyPI and can be installed with **pip**. It has no external runtime dependencies besides **uvicorn** (or another ASGI server) for development and production. ```bash pip install "fastapi[all]" # includes optional dependencies such as python‑multipart, email‑validator, jinja2 # Or, if you only need the core framework: pip install fastapi ``` > **Note**: FastAPI requires Python **3.8** or newer. # Quick start Below is a minimal example that demonstrates the core concepts: ```python from fastapi import FastAPI from pydantic import BaseModel app = FastAPI() class Item(BaseModel): name: str description: str | None = None price: float tax: float | None = None @app.get("/items/{item_id}") async def read_item(item_id: int, q: str | None = None): return {"item_id": item_id, "q": q} @app.post("/items/") async def create_item(item: Item): return {"item_id": 1, **item.dict()} ``` Run the application with **uvicorn**: ```bash uvicorn myapp:app --reload # where `myapp.py` contains the code above ``` Open your browser at