Skip to main content

High-level framework for notifications

Project description

travis pypi codecov

High-level framework for notifications

This project is intended to provide a convenient way to send notifications using multiple notification backends (e.g., e-mail, SMS, push).


Setting up

To start using universal_notifications please add universal_notifications to INSTALLED_APPS in your Django project, and then migrate the app: ./manage.py migrate universal_notifications.

Basic usage

WebSocket notifications

To have Universal Notifications receive WS notifications (ie. to mark notification as received) add to your settings.py:

WS4REDIS_SUBSCRIBER = 'universal_notifications.backend.websockets.RedisSubscriber'

Simple example of using WS notifications:

class OrderShippedWS(WSNotification):
    message = 'order_shipped'
    serializer_class = OrderSerializer

# ... somewhere in a view
OrderShippedWS(item=order, receivers=[user], context={}).send()

E-mail notifications

class OrderShippedEmail(EmailNotification):
    email_name = 'order_shipped'
    email_subject = _('Order no. {{item.pk}} has been shipped.')

# ... somewhere in a view
OrderShippedEmail(item=order, receivers=[user], context={}).send()

E-mail notifications allow filtering e-mail addreses which are unsubscribed from receiving e-mails from your service. This can be achievied by setting the UNIVERSAL_NOTIFICATIONS_UNSUBSCRIBED_MODEL property in your project’s settings.

Sample UnsubscribedModel should at least contain the email property. As result, all addresses existing in UnsubscribedModel objects will not receive any e-mails.

SMS notifications

class OrderShippedSMS(SMSNotification):
    message = _('Order no. {{item.pk}} has been shipped.')

    def prepare_receivers(self):
        return {x.shipping_address.phone for x in self.receivers}

# ... somewhere in a view
OrderShippedSMS(item=order, receivers=[user], context={}).send(

Push notifications

First of all, to use push notifications, you must provide a list of available devices linked to users. For more information, please check out sources.

Supported platforms:
  • FCM - Android, iOS, Web

  • GCM - Android, iOS, Web

  • APNS - iOS

To make push notifications work on all supported platforms, a few properties need to be set:
  • UNIVERSAL_NOTIFICATIONS_MOBILE_APPS[app_id]
    • APNS_CERTIFICATE - APNS certificate file

    • FCM_API_KEY - Firebase API key

    • GCM_API_KEY - Google Cloud Messaging API key

  • GCM_POST_URL - Google Cloud Messaging post url

Settings related to Apple Push Notification service:
  • APNS_HOST

  • APNS_PORT

  • APNS_FEEDBACK_HOST

  • APNS_FEEDBACK_PORT

  • APNS_ERROR_TIMEOUT

  • APNS_MAX_NOTIFICATION_SIZE

Simple example of use:

class OrderShippedPush(PushNotification):
    message = _('Order no. {{item.pk}} has been shipped.')

# ... somewhere in a view
OrderShippedPush(item=order, receivers=[user], context={}).send()

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

universal_notifications-0.6.3.tar.gz (26.7 kB view hashes)

Uploaded Source

Built Distribution

universal_notifications-0.6.3-py2.py3-none-any.whl (38.1 kB view hashes)

Uploaded Python 2 Python 3

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