Back to Home
python
fastapi

FastAPI

Modern, fast web framework for building APIs with Python type hints

3/20/2024
10 min read
fastapi, python, api, async, rest, web

Getting Started

Installation and basic setup

Installation & Setup

Install FastAPI and create your first app

bash
# Install FastAPI with all dependencies
pip install "fastapi[all]"
 
# Or minimal install
pip install fastapi
pip install uvicorn[standard]
FastAPI Features
  • Fast: Very high performance, on par with NodeJS and Go.
  • 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.
installationsetup

Basic Application

Create your first FastAPI application

Creating the App

python
from fastapi import FastAPI
 
app = FastAPI()
 
@app.get("/")
async def root():
    return {"message": "Hello World"}
 
# Run with: uvicorn main:app --reload
Automatic Docs
  • Interactive API docs: Automatic interactive API documentation (provided by Swagger UI).
  • Alternative API docs: Alternative automatic documentation (provided by ReDoc).