Python / Uvicorn Fundamentals Interview Questions
What is Uvicorn's --interface flag and what application types does it support?
The --interface flag tells Uvicorn which application protocol to expect. The default auto setting detects the interface automatically, but you can force a specific mode.
| Value | Interface | WebSocket support | Notes |
|---|---|---|---|
| auto (default) | Auto-detect ASGI3, ASGI2, or WSGI | If ASGI | Recommended for most cases |
| asgi3 | ASGI 3.0 (current standard) | Yes | Explicit ASGI3 |
| asgi2 | ASGI 2.0 (legacy double-callable) | Yes | Legacy - rarely needed |
| wsgi | WSGI (synchronous) | No | Always disables WebSocket support |
# Auto-detect (default - recommended) uvicorn main:app --interface auto # Explicit ASGI3 (FastAPI, Starlette, modern frameworks) uvicorn main:app --interface asgi3 # WSGI mode (for Django without channels, Flask) uvicorn main:app --interface wsgi # WARNING: WSGI mode disables WebSocket support entirely # Programmatic: uvicorn.run("main:app", interface="asgi3")
WSGI mode deprecation note: Uvicorn's native WSGI implementation is deprecated. For running WSGI applications through Uvicorn, you should use the a2wsgi adapter (pip install a2wsgi) which wraps your WSGI app in an ASGI-compatible interface. This approach keeps the full ASGI pipeline while supporting legacy WSGI apps.
More Related questions...