Skip to main content

Simple Resource binding and Consumer Mixin for Django Rest Framework and Channels 2

Project description

DRF Channels

https://travis-ci.org/iamriel/drf-channels.svg?branch=master

DRF Channels provides a simple django-channels bindings and consumer mixin that can be used to automatically listen and send to groups everytime a Resource is created/updated/deleted.

It requires Python >= 3.5, Channels >= 2.0, Django >=1.11, and Django Rest Framework 3.x

This is like a port of Channels 1.x’s Data_Binding and Channels API with few differences.

The data sent to the clients are based on the Serializer class provided.

How does it work?

The API exposes a ResourceBinding class that holds your Model, Serializer class, and Consumer class. Your Consumer class needs to be a subclass of AsyncJsonWebsocketConsumer from channels and have a AsyncConsumerActionMixin mixin.

The ResourceBinding class binds pre_save, pre_delete, post_save, and post_delete signals to your model. These signals will then send to the corresponding Consumer groups that listens to your stream.

The first thing you need to do is connect to your consumer and pass the actions you want to subscribe to via url parameters.

For example, you want to subscribe to the create and update actions Job Resource (Model), and the channels route is /jobs/, You will connect to the websocket like below, if you are using Channels Websocket Wrapper:

const webSocketBridge = new channels.WebSocketBridge()
webSocketBridge.connect('/jobs/?subscribe=create,update')

You then need to add a listener on your webSocketBridge to receive the messages sent by the Consumer via signals.

webSocketBridge.socket.addEventListener('message', function(event) {

})

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

drf_channels-0.1.1.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

drf_channels-0.1.1-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file drf_channels-0.1.1.tar.gz.

File metadata

File hashes

Hashes for drf_channels-0.1.1.tar.gz
Algorithm Hash digest
SHA256 f9a1d30a1ab998c45d2400300c93fe2ea3d474459305516f6a797003671f8e21
MD5 8ac4f7716d8a772963826640f841a72b
BLAKE2b-256 8ddb72c482f202590d2abd55c041818af247cedce44e436ff01e79b123ac1f3f

See more details on using hashes here.

File details

Details for the file drf_channels-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for drf_channels-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 35311a7ccf01f9e4b3f2a84a5a7809e051424c65d2441978e7cdd3341b677830
MD5 31c941c3d40ccec1a16f07d6ba06bdd6
BLAKE2b-256 10c9e69ca9d4597def1c85b4297cab252b5a0596354d31d1deacfe1b09874420

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