1. Three Frameworks, Three Jobs

Most Python web apps start with Flask, Django or FastAPI. All three are mature, popular and free. Each one makes a different trade.

Flask gives you a small core and lets you add only what you need. Django gives you almost everything at once, including logins and an admin site. FastAPI gives you speed and automatic API docs.

Your choice also decides how your app runs in production. It changes the server you use, the memory you pay for and the way you query your database. This guide compares those costs.

2. WSGI vs. ASGI in Plain Terms

The biggest difference is how each framework handles waiting.

WSGI (Flask and Django)

A WSGI app handles one request per worker at a time. The worker waits while the database answers or the template renders. To serve more people at once, Gunicorn starts more worker processes. Think of a bank with several tellers. Each teller serves one customer until that customer leaves.

ASGI (FastAPI)

FastAPI runs on ASGI, through Starlette and the Uvicorn server. ASGI uses an event loop from Python's asyncio module. When a request waits for the network or the database, the loop starts work on the next request. One worker can juggle many slow requests at once. This model shines for APIs that spend most of their time waiting on other services.

3. How Much Memory Each One Needs

Memory is usually the limit that decides your hosting bill. These ranges are typical for a small app. Your own numbers depend on your libraries and data.

  • Flask uses about 35 to 60 MB per Gunicorn worker. A 512 MB plan fits three workers with room to spare.
  • Django uses about 80 to 150 MB per worker, because it loads its ORM, admin and middleware. A 512 MB plan fits two workers.
  • FastAPI uses about 45 to 80 MB per worker. One Uvicorn worker often handles the traffic that needs several WSGI workers, so FastAPI APIs tend to need the least memory.

4. Talking to the Database

Your database code must match your framework's style. A mismatch here causes the slowest bugs to track down.

Django's ORM started out synchronous. Recent versions add async queries, but many third-party Django packages still make synchronous calls. Treat Django as a synchronous framework unless you check every package.

FastAPI works best with async drivers. Use asyncpg for PostgreSQL, aiosqlite for SQLite, or async SQLAlchemy 2.0. Watch for one common mistake. A synchronous query inside an async def route freezes the whole event loop, and every other request waits with it. If you must use a synchronous library, define the route with plain def. FastAPI then runs it in a separate thread.

Flask is synchronous and pairs well with SQLAlchemy or plain sqlite3.

5. Feature Table

Here is how the three frameworks compare on the features people ask about most.

Feature Flask Django FastAPI
Production server Gunicorn (WSGI) Gunicorn (WSGI) Uvicorn (ASGI)
Input validation Add a library, such as Marshmallow Django Forms Built in, with Pydantic
API docs (OpenAPI) Add-on needed Add-on needed Built in
Admin site None Built in None
WebSockets Needs an extension Django Channels Built in
Time to learn Short Medium Short to medium

6. How to Choose

Use these three rules. They cover most projects.

  1. Choose Django for a full website with user accounts, database migrations and an admin dashboard. You will write less code because Django ships those parts.
  2. Choose FastAPI for a REST API, a service that calls many other services, or anything that needs WebSockets and automatic API docs.
  3. Choose Flask for small apps, quick prototypes and projects where you want to pick every library yourself.

Still unsure? Pick the one you can build fastest with today. All three run well in production, and Cloudilio detects and starts each of them for you. See the exact start commands on the supported frameworks page.

Cloudilio Engineering Team
Web Performance Group • Cloudilio

Cloudilio hosts Python apps. You publish Flask, Django, FastAPI, Streamlit and plain Python scripts without managing a server, and your app's data stays safe between updates.