{"id":425,"library":"asgiref","title":"ASGI Ref","description":"ASGI specification and utilities, version 3.11.1, released on a regular cadence. Provides ASGI specs, helper code, and adapters for Python applications.","status":"active","version":"3.11.1","language":"python","source_language":"en","source_url":"https://github.com/django/asgiref","tags":["ASGI","Python","Web Framework","Channels","Asynchronous"],"install":[{"cmd":"pip install asgiref","lang":"bash","label":"Install asgiref"}],"dependencies":[{"reason":"Provides backports of Python 3.5+ typing features for earlier versions","package":"typing-extensions","optional":false}],"imports":[{"note":"Importing ASGIApp from asgiref.typing is the correct approach.","symbol":"ASGIApp","correct":"from asgiref.typing import ASGIApp"},{"note":"AsyncToSync is used to call asynchronous code from synchronous code.","symbol":"AsyncToSync","correct":"from asgiref.sync import AsyncToSync"}],"quickstart":{"code":"import os\nfrom asgiref.sync import AsyncToSync\nfrom channels.routing import ProtocolTypeRouter, URLRouter\nfrom channels.auth import AuthMiddlewareStack\nfrom django.urls import path\n\nos.environ.setdefault('DJANGO_SETTINGS_MODULE', 'your_project.settings')\n\napplication = ProtocolTypeRouter({\n    'http': get_asgi_application(),\n    'websocket': AuthMiddlewareStack(\n        URLRouter([\n            path('ws/some_path/', your_consumer.as_asgi()),\n        ])\n    ),\n})","lang":"python","description":"A basic ASGI application setup using asgiref and Channels, including routing and middleware."},"warnings":[{"fix":"Update import statements to reflect the new module structure.","message":"Import paths have changed in asgiref 3.11.1; ensure correct imports to avoid ImportError.","severity":"breaking","affected_versions":"3.11.1"},{"fix":"Use AsyncToSync within an event loop or ensure it's called from an asynchronous context.","message":"Using AsyncToSync without proper context can lead to deadlocks; ensure it's used within an appropriate event loop.","severity":"gotcha","affected_versions":"3.11.1"},{"fix":"Install the 'channels' package using pip: `pip install channels`.","message":"The 'channels' package is not found. Ensure it is installed in the environment.","severity":"breaking","affected_versions":"3.11.1"},{"fix":"Install the 'channels' package using pip: `pip install channels`.","message":"The 'channels' module is not found. Ensure it is installed in your environment.","severity":"breaking","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-12T13:43:33.273Z","next_check":"2026-06-26T00:00:00.000Z","problems":[{"fix":"Ensure there are no extra spaces in the requirements.txt file; use 'asgiref==3.5.2' instead of 'asgiref 3.5.2'.","cause":"The requirements.txt file contains an invalid format with extra spaces between the package name and version number.","error":"ERROR: Invalid requirement: 'asgiref 3.5.2'"},{"fix":"Replace 'asgi_redis' with 'channels_redis', which is compatible with newer versions of 'asgiref'.","cause":"The 'asgi_redis' package depends on an outdated version of 'asgiref' that no longer includes 'base_layer'.","error":"ModuleNotFoundError: No module named 'asgiref.base_layer'"},{"fix":"Update the code to remove references to 'ThreadSensitiveContext' and use alternative approaches for thread-sensitive operations.","cause":"The 'ThreadSensitiveContext' class has been removed in newer versions of 'asgiref'.","error":"ImportError: cannot import name 'ThreadSensitiveContext' from 'asgiref.sync'"},{"fix":"Install 'asgiref' using 'pip install asgiref' and ensure it's included in your project's dependencies.","cause":"The 'asgiref' package is either not installed or not properly included in the project.","error":"ModuleNotFoundError: No module named 'asgiref.sync'"},{"fix":"Remove the specific version constraint for 'asgiref' in 'requirements.txt' to allow compatibility with Django's required version.","cause":"The specified version of 'asgiref' conflicts with the version required by Django.","error":"ERROR: Cannot install -r requirements.txt (line 8) and asgiref==3.2.5 because these package versions have conflicting dependencies."}],"ecosystem":"pypi","meta_description":null,"install_score":0,"install_tag":"stale","quickstart_score":0,"quickstart_tag":"stale","pypi_latest":null,"install_checks":{"last_tested":"2026-05-12","tag":"stale","tag_description":"widespread failures or data too old to trust","results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null}]},"quickstart_checks":{"last_tested":"2026-04-23","tag":"stale","tag_description":"widespread failures or data too old to trust","results":[{"runtime":"python:3.10-alpine","exit_code":1},{"runtime":"python:3.10-slim","exit_code":1},{"runtime":"python:3.11-alpine","exit_code":1},{"runtime":"python:3.11-slim","exit_code":1},{"runtime":"python:3.12-alpine","exit_code":1},{"runtime":"python:3.12-slim","exit_code":1},{"runtime":"python:3.13-alpine","exit_code":1},{"runtime":"python:3.13-slim","exit_code":1},{"runtime":"python:3.9-alpine","exit_code":1},{"runtime":"python:3.9-slim","exit_code":1}]}}