python-asgiref
Port variant v14
Summary ASGI specs, helper code, and adapters (3.14)
Package version 3.13.0
Homepage https://github.com/django/asgiref/
Keywords python
Maintainer Python Automaton
License Not yet specified
Other variants v15
Ravenports Buildsheet | History
Ravensource Port Directory | History
Last modified 13 NOV 2026, 13:25:52 UTC
Port created 03 DEC 2019, 03:21:45 UTC
Subpackage Descriptions
single asgiref ======= ASGI is a standard for Python asynchronous web apps and servers to communicate with each other, and positioned as an asynchronous successor to WSGI. You can read more at https://asgi.readthedocs.io/en/latest/ This package includes ASGI base libraries, such as: * Sync-to-async and async-to-sync function wrappers, ``asgiref.sync`` * Server base classes, ``asgiref.server`` * A WSGI-to-ASGI adapter, in ``asgiref.wsgi`` Function wrappers ----------------- These allow you to wrap or decorate async or sync functions to call them from the other style (so you can call async functions from a synchronous thread, or vice-versa). In particular: * AsyncToSync lets a synchronous subthread stop and wait while the async function is called on the main thread's event loop, and then control is returned to the thread when the async function is finished. * SyncToAsync lets async code call a synchronous function, which is run in a threadpool and control returned to the async coroutine when the synchronous function completes. The idea is to make it easier to call synchronous APIs from async code and asynchronous APIs from synchronous code so it's easier to transition code from one style to the other. In the case of Channels, we wrap the (synchronous) Django view system with SyncToAsync to allow it to run inside the (asynchronous) ASGI server. Note that exactly what threads things run in is very specific, and aimed to keep maximum compatibility with old synchronous code. See "Synchronous code & Threads" below for a full explanation. By default, sync_to_async will run all synchronous code in the program in the same thread for safety reasons; you can disable this for more performance with ``@sync_to_async(thread_sensitive=False)``, but make sure that your code does not rely on anything bound to threads (like database connections) when you do. Thread-sensitive contexts ------------------------- ThreadSensitiveContext gives thread-sensitive sync_to_async calls a shared, single-worker executor for an async block. This allows you to group thread-sensitive calls, for example, per-request in a web application, rather than per-process:: class ASGIHandler(...): ... async def __call__(...): ... async with ThreadSensitiveContext(): await self.handle(...) By default, only the outermost ThreadSensitiveContext sets the context. Nested calls are a no-op and reuse it. Nested contexts can be created by passing the explicit executor keyword argument. * The executor must run one call at a time on one thread, such as ``ThreadPoolExecutor(max_workers=1)``. Recall, it is used for ``sync_to_async(…, thread_sensitive=True)`` calls. * The calling code is responsible for the executor lifetime: the context does not shut it down. You may use it again for a later block, for example in a pool. * Do not use one executor for two blocks at the same time. By providing an executor, nested work can be run on a separate thread from the parent context's, including when the block is reached through async_to_sync:: from concurrent.futures import ThreadPoolExecutor from asgiref.sync import ThreadSensitiveContext, sync_to_async worker = ThreadPoolExecutor(max_workers=1) async with ThreadSensitiveContext(): await sync_to_async(parent_work)() async with ThreadSensitiveContext(executor=worker):
Configuration Switches (platform-specific settings discarded)
PY314 ON Build using Python 3.14 PY315 OFF Build using Python 3.15
Package Dependencies by Type
Build (only) python314:dev:std
python-pip:single:v14
autoselect-python:single:std
Build and Runtime python314:primary:std
Download groups
main mirror://PYPIWHL/2e/b0/ec211e1f7966247cb6469158d856bac9aa4c2fe13621bd6a352e4f850453
Distribution File Information
f9596a2434512686473d50f96ff6207fbba49ae1a785dfac614df4aeb085674d 27593 python-src/asgiref-3.13.0-py3-none-any.whl
Ports that require python-asgiref:v14
python-Django:v14 High-level Python Web framework (3.14)
python-django-cors-headers:v14 Django handler for CORS server headers (3.14)
python-django-htmx:v14 Extensions for using Django with htmx (3.14)
python-social-auth-app-django:v14 Social authentication for Django (3.14)
python-strawberry-graphql-django:v14 Strawberry GraphQL Django extension (3.14)