Sanic is a Python 3.10+ ASGI-capable framework and server for building non-blocking HTTP APIs and sites with async route handlers.
Overview
Sanic combines a web framework with an embedded HTTP server oriented toward asyncio workloads. Developers declare routes with async functions, return JSON or text responses, and run apps from the sanic CLI or an ASGI host when needed.
Installation pulls optional uvloop and ujson helpers for speed, with environment flags to skip them. Built-in features cover WebSockets, static file and directory serving, TLS termination, lifecycle hooks, signal dispatch, structured exceptions, and an inspect command for live worker status and scaling.
Official extensions add CORS, Jinja templates, OpenAPI docs, validation, health checks, and related conveniences. Development mode can auto-reload on file saves, generate local TLS certificates, and surface detailed error pages.
The design stays minimal and unopinionated so teams can assemble middleware, deployment, and persistence choices themselves while keeping request handling asynchronous end to end.
Key features
- Async await route handlers
- Bundled production HTTP server
- ASGI deployment compatibility
- Built-in WebSocket endpoints
- Static file and directory serving
- TLS and dev auto-TLS support
- Lifecycle and signal hooks
- CLI inspect and scale controls
Use cases
- High-throughput JSON APIs
- Async microservice backends
- Real-time WebSocket feeds
- Lightweight internal web tools
- ASGI-compatible deployments