Overview
Sanic 23.6, released on July 26, 2023, adds Unix socket support and performance optimizations.
Main Features
Unix sockets
Unix socket support allows deploying Sanic behind a reverse proxy (Nginx) with more efficient local communication.
python
from sanic import Sanic, json
app = Sanic('MyApp')
@app.get('/')
async def home(request):
return json({'message': 'Sanic 23.6'})
# Start with Unix socket
# app.run(unix='/tmp/sanic.sock')
# Nginx: upstream sanic { server unix:/tmp/sanic.sock; }
Optimizations
The router and HTTP parser benefit from optimizations that reduce latency under high throughput.
python
from sanic import Sanic, json
app = Sanic('FastApp')
@app.get('/api/<id:int>')
async def get_item(request, id: int):
return json({'id': id, 'status': 'ok'})
# Multi-worker for performance
# app.run(host='0.0.0.0', port=8000, workers=4)
