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.urls import path

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.
        path('ws/<slug: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-7.0.1a2.tar.gz (35.7 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file djangorestframework-reactive-7.0.1a2.tar.gz.

File metadata

  • Download URL: djangorestframework-reactive-7.0.1a2.tar.gz
  • Upload date:
  • Size: 35.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for djangorestframework-reactive-7.0.1a2.tar.gz
Algorithm Hash digest
SHA256 40ddb8e31af02dd5942640158b56fb82858d855ae2452669b373ac94ad190bb9
MD5 741d5ce911f97c573e6b49c1a8a9fb30
BLAKE2b-256 5d664db7152c3629dee051fb65aee94f4cd7141f870a3014491ce66eb6ae7661

See more details on using hashes here.

File details

Details for the file djangorestframework_reactive-7.0.1a2-py3-none-any.whl.

File metadata

  • Download URL: djangorestframework_reactive-7.0.1a2-py3-none-any.whl
  • Upload date:
  • Size: 27.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for djangorestframework_reactive-7.0.1a2-py3-none-any.whl
Algorithm Hash digest
SHA256 c8a60b48112178787e8b2f6f812f6c76d73c7e65dcd1edcda23a319258d32318
MD5 096bcfbc60f5d6a769e3b8761a4ff0d9
BLAKE2b-256 2a2d80bc5fdd8e1c08e0ab2efd04c7aa24fb6569d4e52566855ed8c76a50aeca

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