What Sanic Does
- Async native —
async defhandlers throughout - Built-in server — no external WSGI/ASGI server needed
- WebSocket — native support
- Streaming — request and response streaming
- Middleware — request/response lifecycle hooks
- Blueprints — modular route grouping
- OpenAPI — auto-generated API docs
- Signals — event-based hooks
- Background tasks — via
app.add_task()
Comparison
| Framework | Server | Speed |
|---|---|---|
| Sanic | Built-in (uvloop) | Very fast |
| FastAPI | Uvicorn | Very fast |
| Flask | Gunicorn | Medium |
| Tornado | Built-in | Fast |
常见问题 FAQ
Q: Sanic vs FastAPI? A: FastAPI 有 Pydantic 验证 + 自动 OpenAPI + 更大社区;Sanic 有内置服务器、更灵活的中间件、更早的 async 支持。新 API 项目多选 FastAPI。
来源与致谢 Sources
- Docs: https://sanic.dev
- GitHub: https://github.com/sanic-org/sanic
- License: MIT