Skip to main content
Help us improve Python packaging – donate today!

Making Django REST Framework reactive

Project Description

Build Status

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.



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


There are several things that need to be configured in the Django settings file:

  • rest_framework_reactive needs to be added to INSTALLED_APPS.

  • DEFAULT_PAGINATION_CLASS needs to be set to rest_framework_reactive.pagination.LimitOffsetPagination (optionally, this pagination class can instead be set for all viewsets configured for reactivity).

  • WS4REDIS_SUBSCRIBER needs to be set to rest_framework_reactive.websockets.QueryObserverSubscriber.

  • DJANGO_REST_FRAMEWORK_REACTIVE needs to be configured with hostname and port where the internal RPC will live. It should be set to something like:

       'host': 'localhost',
       'port': 9432,

    The hostname and port must be such that they are reachable from the Django application server.

Each ViewSet that should support reactivity, must be registered by using:

from rest_framework_reactive.pool import pool

The best place to do this is inside or better, inside the ready handler of an AppConfig.

At the moment, you are required to change your project’s to monkey patch the runobservers command with support for gevent coroutines. Note that regular Django application server still runs as normal, only the observer process runs using coroutines.

The modified should look as follows:

#!/usr/bin/env python
import os
import sys

if __name__ == "__main__":
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "genesis.settings.development")

    # This is needed here so the monkey patching is done before Django ORM is loaded. If we
    # do it inside the 'runobservers' management command, it is already too late as a database
    # connection has already been created using thread identifiers, which become invalid
    # after monkey patching.
    if 'runobservers' in sys.argv:
        import gevent.monkey
        import psycogreen.gevent

        # Patch the I/O primitives and psycopg2 database driver to be greenlet-enabled.

    from import execute_from_command_line


And finally, need to be updated to include some additional paths:

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


In addition to running a Django application server instance, you need to also run a separate observer process. You may start it by running:

python runobservers

Release history Release notifications

This version
History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


Download files

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

Filename, size & hash SHA256 hash help File type Python version Upload date
djangorestframework-reactive-2.0.1.tar.gz (22.2 kB) Copy SHA256 hash SHA256 Source None Feb 5, 2018

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page