Starlette ASGI — ELI5
Imagine a restaurant kitchen. In a traditional setup, one chef takes an order, cooks it completely, serves it, then takes the next order. If someone orders a steak that takes 20 minutes, everyone behind them waits.
Starlette is like redesigning that kitchen so the chef can start the steak, then while it’s grilling, take the next order and start chopping vegetables. The steak isn’t forgotten — the chef comes back when it’s ready. Multiple meals get prepared at the same time.
In web terms, a server gets requests from people’s browsers. Old-style Python servers (called WSGI servers) handle one request completely before touching the next. If one request needs to wait for a database answer, everything pauses.
Starlette uses a newer approach called ASGI (Asynchronous Server Gateway Interface). It lets your Python code say “I’m waiting for the database — go handle someone else while I wait.” When the database responds, your code picks up right where it left off.
What makes Starlette special is that it’s a toolkit, not a giant framework. It gives you the essential pieces — routing (directing requests to the right code), middleware (doing stuff before or after every request), and WebSocket support (real-time two-way communication) — without forcing you into a specific way of building your app.
FastAPI, one of the most popular Python web frameworks today, is actually built on top of Starlette. So when people use FastAPI, they’re using Starlette underneath without realizing it.
The one thing to remember: Starlette is a lightweight, fast toolkit for building Python web apps that can handle many users at once by not waiting around when things are slow.
See Also
- Python Aiohttp Client Understand Aiohttp Client through a practical analogy so your Python decisions become faster and clearer.
- Python Api Client Design Why building your own API client in Python is like creating a TV remote that only has the buttons you actually need.
- Python Api Documentation Swagger Swagger turns your Python API into an interactive playground where anyone can click buttons to try it out — no coding required.
- Python Api Mocking Responses Why testing with fake API responses is like rehearsing a play with stand-ins before the real actors show up.
- Python Api Pagination Clients Why APIs send data in pages, and how Python handles it — like reading a book one chapter at a time instead of swallowing the whole thing.