Skip to main content

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

This version

0.3

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-async-stream-0.3.tar.gz (2.6 kB view hashes)

Uploaded Source

Built Distribution

django_async_stream-0.3-py3-none-any.whl (3.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page