Skip to main content

Making Django REST Framework reactive

Project description

Build Status Documentation Status Version on PyPI Supported Python versions Number of downloads from PyPI Code style: black

This package enables regular Django REST Framework views to become reactive, that is so that client-side applications may get notified of changes to the underlying data as soon as they happen, without the need to poll the API again. While the initial request is done as a regular HTTP request, all the update notifications come through WebSockets.

Install

Prerequisites

The reactive extensions for Django REST Framework require the use of Django Channels for push notifications via WebSockets.

From PyPI

pip install djangorestframework-reactive

From source

pip install https://github.com/genialis/django-rest-framework-reactive/archive/<git-tree-ish>.tar.gz

where <git-tree-ish> can represent any commit SHA, branch name, tag name, etc. in DRF Reactive’s GitHub repository. For example, to install the latest version from the master branch, use:

pip install https://github.com/genialis/django-rest-framework-reactive/archive/master.tar.gz

Configure

First, add rest_framework_reactive to INSTALLED_APPS.

Configure your Django Channels routing.py to include the required paths:

from django.conf.urls import url

from channels.routing import ChannelNameRouter, ProtocolTypeRouter, URLRouter

from rest_framework_reactive.consumers import ClientConsumer, MainConsumer, WorkerConsumer
from rest_framework_reactive.protocol import CHANNEL_MAIN, CHANNEL_WORKER

application = ProtocolTypeRouter({
    # Client-facing consumers.
    'websocket': URLRouter([
        # To change the prefix, you can import ClientConsumer in your custom
        # Channels routing definitions instead of using these defaults.
        url(r'^ws/(?P<subscriber_id>.+)$', ClientConsumer),
    ]),

    # Background worker consumers.
    'channel': ChannelNameRouter({
        CHANNEL_MAIN: MainConsumer,
        CHANNEL_WORKER: WorkerConsumer,
    })
})

Also, urls.py need to be updated to include some additional paths:

urlpatterns = [
  # ...
  url(r'^api/queryobserver/', include('rest_framework_reactive.api_urls')),
  # ...
]

Run

In addition to running a Django application server instance, you need to also run a separate observer worker process (or multiple of them). You may start it by running:

python manage.py runworker rest_framework_reactive.main rest_framework_reactive.worker

Project details


Download files

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

Source Distribution

djangorestframework-reactive-6.0.0a1.tar.gz (35.7 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file djangorestframework-reactive-6.0.0a1.tar.gz.

File metadata

  • Download URL: djangorestframework-reactive-6.0.0a1.tar.gz
  • Upload date:
  • Size: 35.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.7

File hashes

Hashes for djangorestframework-reactive-6.0.0a1.tar.gz
Algorithm Hash digest
SHA256 44fbd1291eb1386897e581dad305d512469ec8a7fed986714122692721ef0711
MD5 305436763092a57a602f7505af031140
BLAKE2b-256 e5e53b8f833eb3a283b0e6926202374edcfc2d971fb3a401b5e0fb7d2bd21742

See more details on using hashes here.

File details

Details for the file djangorestframework_reactive-6.0.0a1-py3-none-any.whl.

File metadata

  • Download URL: djangorestframework_reactive-6.0.0a1-py3-none-any.whl
  • Upload date:
  • Size: 26.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.7

File hashes

Hashes for djangorestframework_reactive-6.0.0a1-py3-none-any.whl
Algorithm Hash digest
SHA256 77ea3bb70f74e9d49d0e277748c9373f4d380b35b44906f5b6bca41644d31f2e
MD5 e1f82e2107aa7602e200407f7d772e18
BLAKE2b-256 5005dfb0a78b9f61a2a03834fb110a5dd18ab9382580fc152b3ac34b766ce6cc

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