0Pricing
Python Academy · Lesson

FastAPI Project Setup and First Endpoint

Install FastAPI, create a project, and write your first GET endpoint.

What Is FastAPI?

FastAPI is a modern Python web framework for building REST APIs. It provides automatic OpenAPI docs, type-checked request/response models via Pydantic, and async-native performance.

# pip install fastapi uvicorn
from fastapi import FastAPI

app = FastAPI()

@app.get("/")
def root():
    return {"message": "Hello, FastAPI"}

Running the Server

Run with uvicorn. The --reload flag restarts automatically on code changes during development.

# main.py
from fastapi import FastAPI
app = FastAPI()

@app.get("/health")
def health(): return {"status": "ok"}

# Terminal:
# uvicorn main:app --reload
# → http://127.0.0.1:8000
# → http://127.0.0.1:8000/docs  (Swagger UI)

All lessons in this course

  1. FastAPI Project Setup and First Endpoint
  2. Path Parameters, Query Params, and Request Bodies
  3. Dependency Injection and Authentication
  4. Async Endpoints and Database Integration
← Back to Python Academy