Popular Python Frameworks
Django, FastAPI, and Flask -- what each is built for and a minimal hello-world route in each.
2 min read
Python's standard library can handle basic HTTP, but virtually no real backend is built on it directly. Three frameworks dominate the ecosystem, each with a different philosophy about how much structure to give you upfront.
Django: batteries included
Django is a full-stack, "batteries included" framework — an ORM, an admin panel generated from your models, authentication, a templating engine, and a migrations system all ship together and are meant to be used as a cohesive whole. It's the default choice for content-heavy sites and internal tools where you'd otherwise spend weeks wiring up the same pieces yourself.
# views.py
from django.http import HttpResponse
def hello(request):
return HttpResponse("Hello, world!")# urls.py
from django.urls import path
from .views import hello
urlpatterns = [
path("hello/", hello),
]Django's opinionated structure (apps, models, views, templates, a specific project layout) is a strength once a project grows past a handful of endpoints — everyone on a team ends up organizing things the same way — but it's more setup than a five-route API needs.
FastAPI: modern and async-first
FastAPI is a newer framework built around Python's type hints, automatic request validation, and native async/await support. Type-annotate a function's parameters and FastAPI validates incoming data against them automatically, generating interactive API documentation (via Swagger UI) for free in the process.
from fastapi import FastAPI
app = FastAPI()
@app.get("/hello")
async def hello():
return {"message": "Hello, world!"}Run it with an ASGI server like uvicorn main:app --reload. FastAPI has become the default choice for new API projects, particularly ones serving JSON to a separate frontend or powering machine learning model endpoints, where its async performance and automatic docs pay off immediately.
Flask: minimal and unopinionated
Flask is a micro-framework — it gives you routing and request handling and deliberately leaves the rest (which ORM, which templating approach, how to structure folders) up to you, adding pieces only as extensions when you need them.
from flask import Flask
app = Flask(__name__)
@app.route("/hello")
def hello():
return "Hello, world!"
if __name__ == "__main__":
app.run(debug=True)That minimalism makes Flask a natural fit for small services, prototypes, and projects where Django's full structure would be more scaffolding than the project needs — though as a project grows, more of that structure ends up being rebuilt by hand.
Choosing between them
- Django — content sites, admin-heavy internal tools, projects that benefit from one prescribed way of doing things.
- FastAPI — JSON APIs, especially ones needing high concurrency, strict request validation, or auto-generated docs.
- Flask — small services, prototypes, or anywhere you want full control over the pieces you add.
All three sit on top of the same core Python covered throughout this course — functions, classes, dictionaries for JSON-like data, decorators (the @app.route/@app.get syntax) for registering routes. Learning any one of them well makes the others easier to pick up, since the underlying language and most of the concepts transfer directly.
Test what you just learned
4 quick questions. Get all of them right to unlock the next lesson.
You can take the quiz without an account — logging in just lets your result count toward your progress.