Description #
FastAPI is a modern, high-performance web framework for building APIs with Python 3.7+ based on standard Python type hints. It is designed to be easy to use while providing fast execution speeds, automatic validation, and interactive documentation out of the box.
History #
FastAPI was created by Sebastián Ramírez and released in 2018. It quickly became popular for its combination of speed (thanks to Starlette and Pydantic), ease of use, and automatic OpenAPI documentation. FastAPI is widely adopted in startups, data science teams, and large companies needing performant Python APIs.
Hello World Code #
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
def read_root():
return {"message": "Hello, World!"}
How to Run #
Option 1: Online
Option 2: Local
Install FastAPI and Uvicorn:
pip install fastapi uvicorn
Save code in main.py
Run the server:
uvicorn main:app --reload
Visit: http://127.0.0.1:8000
Bonus: View interactive API docs at:
Key Concepts #
- Asynchronous and synchronous support
- Type hinting for validation and editor support
- Built-in OpenAPI (Swagger) and ReDoc documentation
- Fast performance using Starlette + Pydantic
- Dependency injection system
- Automatic request parsing and response generation
- Built for REST APIs and microservices
- Native JSON support
- Path and query parameter validation
- Popular in ML, backend, and startup projects
Try It Online #
Fun Facts #
- FastAPI is as fast as Node.js and Go for many use cases.
- It automatically generates interactive docs for any API endpoint.
- Used by Netflix, Microsoft, and Uber in production environments.