Real time third party app for DRF (using Channels 2.0)

Skip to first unread message

Daniel Gilge

Feb 12, 2018, 11:45:11 AM2/12/18
to Django REST framework

I'm currently working on a real time app for one of our projects. So I thought why not make it an open source package until DRF has native real time support (which is not included in the DRF 3.8 milestone due 31-03-18).

The idea is to pass an APIView (or a subclass there of) to a RealTime instance which takes (almost) everything from the view it needs to provide a WebSockets API endpoint. It works quite well so far but I think it's quite a hack. Python 3.5+, Channels 2.0 and Redis are required. By the way this was my first public Django app and advice from experienced programmers is highly appreciated.

So what are your thoughts on this?

Some limitations in the current implementation:
  • Supported are creation, updates and deletion. You can receive updates via subscription. Listing is not implemented so far.
  • Out of the box support for authentication (authenication_classes) is quite limited because it makes quite use of the Request instance (which I have to simulate).
  • Several (Generic)APIView methods are not used. (I'd give a detailed list which are and which are not.)

Aims for the future:

  • I'd like to just use a project's API routing to additionally support WebSockets. As a result you had equal URIs for HTTPS and WSS requests and you had to write just a few lines of backend code to get real time running (except you want the real time API to be different, which is also possible via subclassing).

I'd be happy to get some feedback.


Tom Christie

Feb 15, 2018, 9:26:59 AM2/15/18
to Django REST framework
Sounds interesting. Not sure I have any particular suggestions, but can add some context around the plans I had. (Possibly still *have* , at a later date.)

My rough plan for Websockets support is a little similar, in that it'd be able easy ways to mirror an existing HTTP endpoint with an equivalent WS endpoint that provides streaming updates whenever the content changes. Personally I was planning to approach it as a separate proxy service, and use Redis Pub/Sub for the webapp to notify the Websocket server whenever there are changes.

An approach that works entirely in Django would be great tho.

Separate issue this, but I think the biggest thing missing for folks ATM is probably just a lack of tutorials or blog posts on using Channels and REST framework together.

  - T.

Daniel Gilge

Mar 22, 2018, 2:17:58 PM3/22/18
Thanks for sharing your thoughts! I gave them my consideration.

However, when I understand you correctly your plan was (is) to send updates from the server to the client using WS but not the other way around. We’ll have live updates for cooperation on texts and therefore I wanted to use WS in both directions. I also thought about leaving some dependencies out but I think I can hardly do without any of them.

Here is my package if somebody is interested:


You received this message because you are subscribed to a topic in the Google Groups "Django REST framework" group.
To unsubscribe from this topic, visit
To unsubscribe from this group and all its topics, send an email to
For more options, visit

Miguel Expósito

Dec 5, 2018, 1:16:55 PM12/5/18
to Django REST framework
Hi, Tom:

I'm thinking of starting a new asynchronous project with a Vue frontend and a DRF backend. I'd need events and updates from the server, and I thought of Django Channels. What is the current status of this feature in DRF? Is there any roadmap? Any estimated release date? What would be your advice in a situation like this? Maybe using Daniel's or somebody's plugin or extension?

I'm considering using other technology such as node.js, which has native support for this. But I'd like to use DRF because of our existing knowledge of Python.

Any advise is welcome.

Thanks a lot in advance.

Kit La Touche

Dec 12, 2018, 5:45:31 PM12/12/18
to Django REST framework

You motivated me to write up an intro blog post to using Channels and DRF together. It's here if you want to take a look

I hope it's helpful, and I'll try to answer any other questions you might have!

Reply all
Reply to author
0 new messages