ASGI Ref

3.11.1 · active · verified Sat Mar 28

ASGI specification and utilities, version 3.11.1, released on a regular cadence. Provides ASGI specs, helper code, and adapters for Python applications.

Warnings

Install

Imports

Quickstart

A basic ASGI application setup using asgiref and Channels, including routing and middleware.

import os
from asgiref.sync import AsyncToSync
from channels.routing import ProtocolTypeRouter, URLRouter
from channels.auth import AuthMiddlewareStack
from django.urls import path

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'your_project.settings')

application = ProtocolTypeRouter({
    'http': get_asgi_application(),
    'websocket': AuthMiddlewareStack(
        URLRouter([
            path('ws/some_path/', your_consumer.as_asgi()),
        ])
    ),
})

view raw JSON →