Uvicorn¶
Fast ASGI server for async Django apps. Supports WebSockets and async views.
Use when: Async Django (3.1+), WebSockets Don’t use when: Traditional sync apps without async needs (use Gunicorn)
Installation¶
pip install django-prodserver[uvicorn]
# For better performance
pip install uvicorn[standard]
Backends¶
ASGI Mode¶
For async Django with WebSocket support:
PRODUCTION_PROCESSES = {
"web": {
"BACKEND": "django_prodserver.backends.servers.uvicorn.UvicornServer",
"ARGS": {
"host": "0.0.0.0",
"port": "8000",
"workers": "4",
}
}
}
WSGI Mode¶
For traditional Django with Uvicorn performance:
PRODUCTION_PROCESSES = {
"web": {
"BACKEND": "django_prodserver.backends.servers.uvicorn.UvicornWSGIServer",
"ARGS": {
"host": "0.0.0.0",
"port": "8000",
"workers": "4",
}
}
}
Common ARGS¶
Argument |
Default |
Description |
|---|---|---|
|
|
Host to bind |
|
|
Port to bind |
|
|
Worker processes |
|
|
Event loop ( |
|
|
Log level |
|
|
Disable access logging |
|
|
Trust proxy headers |
|
|
Keep-alive timeout |
|
|
Max concurrent connections |
|
|
Restart after N requests |
Examples¶
Production¶
"ARGS": {
"host": "0.0.0.0",
"port": "8000",
"workers": "4",
"loop": "uvloop",
"no-access-log": "True",
}
Behind Reverse Proxy¶
"ARGS": {
"host": "127.0.0.1",
"port": "8000",
"proxy-headers": "True",
"forwarded-allow-ips": "*",
}
WebSocket Support¶
"ARGS": {
"host": "0.0.0.0",
"port": "8000",
"timeout-keep-alive": "60",
}
ASGI vs WSGI¶
Feature |
ASGI |
WSGI |
|---|---|---|
Async views |
Yes |
No |
WebSockets |
Yes |
No |
Traditional Django |
Yes |
Yes |
Troubleshooting¶
ASGI app not found: Ensure asgi.py exists with application defined
No async support: Use ASGI backend, not WSGI