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 details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

Details for the file django-async-stream-0.3.tar.gz.

File metadata

  • Download URL: django-async-stream-0.3.tar.gz
  • Upload date:
  • Size: 2.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.25.1

File hashes

Hashes for django-async-stream-0.3.tar.gz
Algorithm Hash digest
SHA256 070e0dff90237e555abeae6c4ec6b1a83ac486f6ec35516cff398c7283d48cc3
MD5 2200fc9324c12725ae67a895b9345f85
BLAKE2b-256 a6bdaffdb5667029f26c80001dcf6dd86ba237356f7c788ad32fa9925bc25349

See more details on using hashes here.

File details

Details for the file django_async_stream-0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for django_async_stream-0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 77e98a656f18b4476ae8dc9afbb626383c86c3871ff39525c85c5124c89cc4ad
MD5 9d9fdcfbe3bd51a61d73690148182c66
BLAKE2b-256 e2a4178f94a99250e0882f5ddb906689a22a1e9221677360024712c85fdff812

See more details on using hashes here.

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