Django extension that allow using asynchronous generators in StreamingHttpResponse
Project description
Django-Async-Stream
Django extension that allow using asynchronous generators in StreamingHttpResponse
Usage
django-async-stream provides AsyncStreamingHttpResponse
class, that you can use instead of StreamingHttpResponse
But for this to work, you need to override one method in the ASGIHandler.
asgi.py
, one of the possible options
# django default file content
import os
from django.core.asgi import get_asgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'projectname.settings')
application = get_asgi_application()
# PATCH BELOW
import django_async_stream
django_async_stream.patch_application(application)
views.py
import asyncio
from django_async_stream import AsyncStreamingHttpResponse
async def my_view(request):
return AsyncStreamingHttpResponse(_my_async_generator())
async def _my_async_generator():
for i in range(10):
yield i
await asyncio.sleep(2)
Installation
pip install django-async-stream
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for django_async_stream-0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 77e98a656f18b4476ae8dc9afbb626383c86c3871ff39525c85c5124c89cc4ad |
|
MD5 | 9d9fdcfbe3bd51a61d73690148182c66 |
|
BLAKE2b-256 | e2a4178f94a99250e0882f5ddb906689a22a1e9221677360024712c85fdff812 |