Overview

Sanic 22.12, released on December 28, 2022, adds automatic TLS and experimental WebTransport support.

Main Features

Auto TLS

Sanic can now automatically generate TLS certificates for local development, simplifying HTTPS testing.

python
from sanic import Sanic, text

app = Sanic('MyApp')

@app.get('/')
async def index(request):
    return text('Automatic HTTPS!')

# Run with automatic TLS
# sanic server:app --auto-tls

WebTransport

Experimental WebTransport support offers an alternative to WebSocket with better performance for real-time data streams.

python
from sanic import Sanic, text

app = Sanic('MyApp')

@app.route('/stream')
async def stream_handler(request):
    async def generate():
        for i in range(10):
            yield f'data: {i}\n\n'
    return text('Streaming available')

Sources