FastAPI: The Modern Web Framework

2 min readOctober 5, 2023

Powerful tool for building APIs with Python

Introduction

FastAPI is a modern, fast (high-performance), web framework for building APIs with Python 3.6+ based on standard Python type hints. It is designed to be easy to use and to help developers build robust and performant APIs quickly.

Key Features

  • Fast: Very high performance, on par with NodeJS and Go (thanks to Starlette and Pydantic).
  • Fast to code: Increase the speed to develop features by about 200% to 300%.
  • Fewer bugs: Reduce about 40% of human (developer) induced errors.
  • Intuitive: Great editor support. Completion everywhere. Less time debugging.
  • Easy: Designed to be easy to use and learn. Less time reading docs.
  • Short: Minimize code duplication. Multiple features from each parameter declaration.
  • Robust: Get production-ready code. With automatic interactive documentation.

Installation

You can install FastAPI using pip:

pip install "fastapi[standard]"

Hello World Example

main.py
from fastapi import FastAPI
 
app = FastAPI()
 
@app.get("/")
def read_root():
    return {"Hello": "World"}

To run the application, use the following command:

pip install uvicorn
uvicorn main:app --reload

Interactive API Docs

FastAPI automatically generates interactive API documentation using Swagger UI and ReDoc. You can access them at:

Conclusion

FastAPI is an excellent choice for building APIs with Python due to its speed, ease of use, and automatic documentation generation. Whether you are building a small project or a large-scale application, FastAPI can help you develop your API quickly and efficiently.