Overview
Uvicorn 0.19, released on October 19, 2022, adds official Python 3.11 support and improves ASGI lifespan handling.
Main Features
Python 3.11 support
Python 3.11 is officially supported, with significant performance gains from CPython optimizations.
python
# Python 3.11 brings ~25% performance gain
import uvicorn
uvicorn.run(
'app:app',
host='0.0.0.0',
port=8000,
loop='asyncio', # optimized asyncio loop in 3.11
)
ASGI lifespan
ASGI lifespan event handling is improved with better error propagation on startup and shutdown.
python
from contextlib import asynccontextmanager
from starlette.applications import Starlette
@asynccontextmanager
async def lifespan(app):
print('Starting...')
yield
print('Shutting down...')
app = Starlette(lifespan=lifespan)
