Python web frameworks compared
Django, Flask and FastAPI side by side, the smaller options worth knowing, and the case where you can skip the server.
A Python web framework is the code that sits between an HTTP request and your own functions. It matches the URL to a handler, parses the input, and sends back a response. Everything else, such as a database layer, templates, logins and an admin screen, is either included or left for you to add. How much is included is the main thing that separates one framework from another.
Three frameworks cover most Python web development today: Django, Flask and FastAPI. The rest are worth knowing about, and a few of them are the better choice for particular jobs.
The short version
| Framework | What it is | Best for | Async | Batteries included | Learning curve |
|---|---|---|---|---|---|
| Django | Full stack framework | Database-backed sites with accounts, forms and an admin | Partly: async views and queries, on a core written sync-first | Almost everything | Steeper at first, then steady |
| Flask | Microframework | Small apps and services where you pick the parts | Limited: async views work, the core is WSGI | Routing and templates, the rest from extensions | Gentle |
| FastAPI | API framework | JSON APIs and backends for a separate front end | Yes, built on ASGI | Validation and API docs, no database layer or admin | Gentle if you know type hints |
| Starlette | ASGI toolkit | Lean async services, or building your own framework | Yes | Very little | Moderate |
| Litestar | API framework | Larger async APIs that want more structure built in | Yes | More than FastAPI, less than Django | Moderate |
| Pyramid | General-purpose framework | Apps with unusual requirements, long-lived codebases | No, WSGI | Few, by design | Moderate |
| Bottle | Single-file microframework | Tiny tools, prototypes, teaching | No, WSGI | Routing and a simple template engine | Very gentle |
Django
Django is the closest thing Python has to a full stack framework. One install gives you an ORM with migrations, a template language, forms, user accounts, sessions and an admin site generated from your models. The parts are designed to work together, and it has been in production for long enough that most problems have a known answer.
The cost is that Django has opinions. Projects follow its layout, and working against its ORM or its idea of an app takes effort. Async support exists and keeps improving, but the framework was written for synchronous code and parts of it still are.
Flask
Flask starts from the other end. The core handles routing, requests and Jinja templates, and you add a database library, form handling and authentication from extensions as you need them. A working app fits in a few lines.
That freedom turns into decisions. Two Flask projects can look nothing alike, and on a larger team you end up writing down conventions that Django would have given you. Flask can run async def views, but it's a WSGI framework underneath. If you want Flask's API on an async server, its sibling project Quart is the usual answer.
FastAPI
FastAPI is built for APIs. You declare what a request and response look like with Python type hints, and it validates the input, serialises the output and generates interactive API documentation from the same declarations. It runs on ASGI, so async handlers, WebSockets and long-lived connections are first-class.
It doesn't ship a database layer, an admin or a login system. You choose those yourself. If the plan is a JSON backend with a React or mobile front end, FastAPI is usually the shortest path.
Smaller frameworks worth knowing
Starlette and Litestar. Starlette is the ASGI toolkit FastAPI is built on: routing, middleware, WebSockets and not much else. Use it directly when you want async without the layers on top. Litestar is a separate ASGI framework aimed at the same job as FastAPI, with more built in, including class-based controllers and tighter control over how data is serialised.
Pyramid and Bottle. Pyramid is an older framework that makes very few decisions for you and scales from one file to a large app. Bottle is a single file with no dependencies beyond the standard library, which makes it handy for a small internal tool or a script that needs a web page.
Python-only UI frameworks
A newer group lets you build the interface in Python too, without writing JavaScript:
- Streamlit turns a script into a data app. It's the fastest way to put a dashboard or model demo in front of people, and less suited to a general website.
- NiceGUI gives you buttons, tables and charts as Python objects, with a server keeping the browser in sync. Good for internal tools and control panels.
- Reflex is the one aimed most squarely at being a Python full stack framework: you write state and components in Python and it produces a React front end for you.
- FastHTML pairs Python functions that return HTML with HTMX, so the server sends fragments of a page instead of JSON.
All four need a Python server running for as long as the app is in use.
Which one should I pick?
- A product with user accounts, a database and an admin screen: Django.
- A JSON API for a separate front end or a mobile app: FastAPI, or Litestar if you want more structure.
- A small service, a webhook receiver or a prototype: Flask, or Bottle if it really is one file.
- You're learning how the web works: Flask. There's little hidden, so you see each piece.
- A dashboard or internal tool for a data team: Streamlit or NiceGUI.
- Lots of WebSockets or streaming: an ASGI framework, so FastAPI, Litestar or Starlette.
- You're joining an existing team: whatever they already run. Familiarity beats a better fit on paper.
When you don't need a framework at all
Every option above runs Python each time someone visits. That's necessary when the response depends on who is asking: a logged-in dashboard, a search, a checkout.
Plenty of sites aren't like that. Documentation, a blog, a marketing site and a portfolio show every visitor the same pages, and those pages only change when you edit them. For that kind of site a framework means a server to pay for, patch and keep running, in exchange for work that could have been done once, in advance.
A static site generator does that work ahead of time. You run a build, it writes plain HTML files, and any static host serves them.
Nitro CLI is a static site generator for people who would rather stay in Python. It isn't a web framework and it doesn't handle requests. Each page is a Python function, and the HTML comes from Nitro UI classes, not a template language:
from nitro_ui import HTML, Head, Title, Body, H1, UnorderedList, ListItem, Anchor
posts = [
{"title": "Hello, world", "url": "/blog/hello-world"},
{"title": "Why static", "url": "/blog/why-static"},
]
page = HTML(
Head(Title("Blog")),
Body(
H1("Blog"),
UnorderedList(
*[ListItem(Anchor(post["title"], href=post["url"])) for post in posts]
),
),
)
print(page.render(pretty=True))
In a Nitro site, a function like that lives in src/pages/, and nitro build turns each one into an HTML file. Make a website with Python walks through it from an empty folder.
The limits are real, though. If you need logins, forms that write to a database, or pages that differ per visitor, you need a framework from the table above.
Common questions
Is Django or Flask better for beginners? Flask is easier to start with because there's less to learn before something works. Django teaches you more of what a real application needs. If you want to understand the pieces, start with Flask. If you want to ship a full site, start with Django.
Is there a Python full stack framework? Django covers the server side from database to HTML and is what most people mean by the term. If you also want to avoid writing JavaScript, look at Reflex, NiceGUI or FastHTML.
Do I need a web framework to build a website with Python? No. If the pages are the same for every visitor, you can generate them ahead of time with a static site generator and host the files with no Python server at all.
This page uses Nitro CLI.
Build static sites with Python code instead of template engines. Live reload, incremental builds, deploy anywhere.
$ pip install nitro-cli