Skip to main content

Easy to use class mixins for Django Rest Framework and Pusher to keep your API realtime.

Project description

PyPI version Build Status

DRF Model Pusher

Easy to use class mixins for Django Rest Framework and Pusher to keep your API realtime.


Download from PyPI:

pip install drf_model_pusher


Settings Config

In your settings set your Pusher App Id and credentials, the cluster is optional


Update Installed Apps

Add drf_model_pusher to your INSTALLED_APPS:


Implement Pusher Backends

Define some PusherBackends for your models and serializers in a file. The PusherBackend class just needs to define a serializer_class attribute which inherits from ModelSerializer.

# example/

from django.db.models import Model
from rest_framework.serializers import ModelSerializer
from drf_model_pusher.backends import PusherBackend, PrivatePusherBackend

class MyModel(Model):

class MyModelSerializer(ModelSerializer):
    class Meta:
        model = MyModel

class MyModelPrivateSerializer(ModelSerializer):
    class Meta:
        model = MyModel

class MyModelPusherBackend(PusherBackend):
    serializer_class = MyModelSerializer
class MyModelPrivatePusherBackend(PrivatePusherBackend):
    serializer_class = MyModelPrivateSerializer

Implement Views

Add the ModelPusherViewMixin mixin class to your views and define a get_pusher_channels method which should return a list of strings to use as channels.

# example/

from rest_framework.viewsets import ModelViewSet
from drf_model_pusher.views import ModelPusherViewMixin
from example.serializers import MyModelSerializer

class MyModelViewSet(ModelPusherViewMixin, ModelViewSet):
    serializer_class = MyModelSerializer
    def get_pusher_channels(self):
        return ["<channel_id>"]

Ignoring the current connection

If you want to ignore the current connection when sending messages you should set a x-pusher-socket-id header on your requests. This may be useful if you're modifying resources and receiving the results in a response, you may not want the current connection to listen on these events to prevent duplicating content.

The PusherBackend.push_change method accepts an ignore boolean keyword argument which can toggle whether the pusher socket id is used, it defaults to True, so including the pusher socket id in the request will ignore the current connection for all pusher events sent by default.


  • DRF_MODEL_PUSHER_BACKENDS_FILE (default: - The file in your applications to import PusherBackends.
  • DRF_MODEL_PUSHER_DISABLED (default: False) - Determines whether or not to trigger Pusher events.

Common Issues

Unregistered Backends

If you have followed the above steps correctly and your backends are not registering, your app config may not be running it's ready method. To force this, in your apps add the line default_app_config = 'myapp.apps.MyAppConfig'


Be aware of any pusher limits and consult their documentation at for some common questions.

Pusher has a 10kb default size limit on messages, this can be increased to 256kb by contacting support.

Extending PusherBackend

If you want to extend PusherBackend or PrivatePusherBackend rather than declaring a new concrete backend, you need to make sure the class is abstract. For example your new base class would be similar to this:

class MyPusherBackend(PusherBackend):
    class Meta:
        abstract = True

    # Override whatever methods here

class MyModelBackend(MyPusherBackend):
    class Meta:
        model = MyModel


It's early days, but if you'd like to report any issues or work on an improvement then please check for any similar existing issues before you report them.

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_model_pusher-0.2.0.tar.gz (7.1 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page