What Starlette Does
- ASGI — fully async, works with uvicorn, hypercorn, daphne
- Routing — path parameters, Mount for sub-apps
- Middleware — CORS, GZip, HTTPS redirect, Trusted Host
- WebSocket — native support
- Background tasks — fire-and-forget after response
- Streaming — StreamingResponse for large files
- Static files — StaticFiles mount
- Test client — httpx-based test client
- Event handlers — startup/shutdown lifecycle
Comparison
| Framework | Level | Validation |
|---|---|---|
| Starlette | Low-level ASGI | Manual |
| FastAPI | High-level (on Starlette) | Pydantic |
| Litestar | High-level ASGI | msgspec/Pydantic |
| Django | Full-stack WSGI/ASGI | Django forms |
常见问题 FAQ
Q: Starlette vs FastAPI? A: FastAPI 就是 Starlette + Pydantic + OpenAPI 自动生成。需要更多控制或更轻量选 Starlette,需要自动文档和验证选 FastAPI。
来源与致谢 Sources
- Docs: https://www.starlette.io
- GitHub: https://github.com/Kludex/starlette
- License: BSD 3-Clause