/django-instant

Websockets for Django with Centrifugo

Primary LanguageJavaScriptMIT LicenseMIT

Django Instant

Build Status Coverage Status

Websockets for Django with Centrifugo.

  • Push events into public or private channels.

  • Handle the events in javascript client-side.

☀️ Compatible: plug it on an existing Django instance without any modification in your main stack.

Straightforward: no particular concepts to know, no learning curve: just push events and handle them client-side.

Check the documentation for the install instructions.

Quick example

Push events in channels from anywhere in the code:

from instant.producers import publish

# Publish to a public channel
publish(message="Message for everyone", channel="mysite_public")

# Publish to a private channel with an event class set
publish(message="Message in private channel", channel="$private_chan", 
        event_class="test")

# Publish to the staff channel with an extra json data payload
data = {"field1":"value1","field2":[1,2]}
publish(message="Message for staff", channel="$mysite_staff", data=data)

Handle the events client-side in a template:

if (event_class === 'test') {
      console.log("This is a test message: " + message);
}

Using this

Django Presence: user presence notification widget

Django Mqueue Livefeed: multi-sites realtime application events and logs

Django Autoreloader: watches files change and autoreload in browser

Django Term: in browser terminal for Django

Django Rechat: basic chat app (toy app for now)

Why?

Most of the websockets solutions associated with Django today require some modification in the main stack, like uwsgi, and often come with a whole bunch of new concepts to figure out, making the newcomer to feel like he is walking in the dark.

We wanted a solution that could plug on a safe classic Django stack without having to do any tweaks on it. The Centrifugo websockets server handles the job very well, better than all the python solutions I know IMHO. This made it possible to build an app that just plugs on an existing Django stack. The API is simple and does not involve any new concept.

We are trying to ship a fully compatible, easy to install and ready to use websockets solution for Django: websockets in Django should not be a big deal.