Vue d'ensemble
Uvicorn 0.15, publié le 13 août 2021, introduit le rechargement par motif glob et ajoute le support de Python 3.10.
Fonctionnalités principales
Rechargement par glob
Le paramètre --reload-include accepte des motifs glob pour cibler les fichiers déclenchant le rechargement automatique.
python
# Rechargement sur les fichiers .py et .html
# uvicorn app:app --reload --reload-include '*.html'
import uvicorn
uvicorn.run(
'app:app',
reload=True,
reload_includes=['*.py', '*.html', '*.yaml'],
)
Support Python 3.10
Uvicorn 0.15 est officiellement compatible avec Python 3.10 et ses nouvelles fonctionnalités asyncio.
python
# Compatible Python 3.10
# Les match/case peuvent être utilisés dans les apps ASGI
async def app(scope, receive, send):
match scope['type']:
case 'http':
await send({'type': 'http.response.start',
'status': 200,
'headers': []})
await send({'type': 'http.response.body',
'body': b'OK'})
case 'websocket':
pass # gestion WebSocket
