{"id":1980,"library":"daphne","title":"Daphne - ASGI Server","description":"Daphne is a pure-Python HTTP, HTTP/2, and WebSocket protocol server for ASGI (Asynchronous Server Gateway Interface) applications. It is primarily developed to power Django Channels and acts as the reference server for ASGI. It supports automatic negotiation of protocols, removing the need for URL prefixing for different endpoints. The current version is 4.2.1.","status":"active","version":"4.2.1","language":"en","source_language":"en","source_url":"https://github.com/django/daphne","tags":["ASGI","HTTP","HTTP/2","WebSocket","Django","Channels","server"],"install":[{"cmd":"pip install daphne","lang":"bash","label":"Install Daphne"}],"dependencies":[{"reason":"Daphne requires Python 3.9 or later.","package":"Python","optional":false}],"imports":[],"quickstart":{"code":"# myproject/asgi.py\nimport os\nfrom channels.routing import ProtocolTypeRouter\nfrom django.core.asgi import get_asgi_application\n\nos.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myproject.settings')\n\n# Initialize Django ASGI application early to ensure the AppRegistry\n# is populated before importing code that may import ORM models.\ndjango_asgi_app = get_asgi_application()\n\napplication = ProtocolTypeRouter({\n    \"http\": django_asgi_app,\n    # Add WebSocket protocol here if using Django Channels\n    # \"websocket\": URLRouter(websocket_urlpatterns)\n})\n\n# To run:\n# Ensure myproject is on the Python path (e.g., run from parent directory of myproject)\n# daphne -b 0.0.0.0 -p 8000 myproject.asgi:application\n","lang":"python","description":"Daphne is typically run from the command line, pointing it to your ASGI application. For a Django project, this involves creating or modifying the `asgi.py` file to define your ASGI application, then invoking Daphne as shown below. The example `asgi.py` demonstrates a basic setup for a Django project without WebSockets."},"warnings":[{"fix":"Ensure your environment uses Python 3.9 or a newer compatible version.","message":"Daphne requires Python 3.9 or later. Using older Python versions will lead to installation or runtime errors.","severity":"gotcha","affected_versions":"<4.0.0 (previous versions supported older Python) to current (4.x)"},{"fix":"Place `daphne` at the very beginning of your `INSTALLED_APPS` list in your Django settings to give it precedence.","message":"When `daphne` is added to `INSTALLED_APPS` for `runserver` integration, it can conflict with other third-party apps that also overload or replace the `runserver` command (e.g., Whitenoise's `runserver_nostatic`).","severity":"gotcha","affected_versions":"All versions"},{"fix":"Be aware of the limitations for HTTP/2 features. Configure your reverse proxy to correctly handle HTTP/2 passthrough if you intend to use it with Daphne.","message":"Daphne's HTTP/2 support is limited to 'normal' requests and does not include extended features like Server Push. If using a reverse proxy in front of Daphne for HTTP/2, ensure the proxy correctly understands and passes through the HTTP/2 connection.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Use either the `Daphne-Root-Path` header or `--root-path` option, ensuring the format is `/your_path` (e.g., `/forum`, not `/forum/`).","message":"Setting a root path (equivalent to WSGI's `SCRIPT_NAME`) can be done via the `Daphne-Root-Path` HTTP header or the `--root-path` command-line option. The header takes precedence. The root path value should start with a slash but not end with one.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}