Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

Handle push notifications at scale.

Project Description

Your push notifications handled at scale.

What does it do?

Python / Django app that provides push notifications functionality with celery. The main purpose of this app is to help you send push notifications to your users at scale. If you have lots of registered device keys, django-pushy will split your keys into smaller groups which run in parallel making the process of sending notifications faster.

Setup

You can install the library directly from pypi using pip:

$ pip install django-pushy

Add django-pushy to your INSTALLED_APPS:

INSTALLED_APPS = (
    ...
    "djcelery",
    "pushy"
)

Configurations:

PUSHY_GCM_API_KEY = 'YOUR_API_KEY_HERE'
PUSHY_QUEUE_DEFAULT_NAME = 'default'
PUSHY_DEVICE_KEY_LIMIT = 1000

If you’re using Django < 1.7 and using south, make sure you do the following:

pip install South==1.0
python manage.py syncdb
python manage.py migrate

If you’re using Django 1.7, you only have to perform:

python manage.py migrate

How do i use it?

There are 2 models provided by Pushy: 1) PushNotification 2) Device

You have to implement your own code to use the Device model to register keys into the database:

from pushy.models import Device
Device.objects.create(key='123', type=Device.DEVICE_TYPE_ANDROID, user=current_user)
Device.objects.create(key='123', type=Device.DEVICE_TYPE_IOS, user=None)

Whenever you need to push a notification, use the following code:

from pushy.utils import send_push_notification
send_push_notification('Push_Notification_Title', {'key': 'value' ...})

This will send a push notification to all registered devices. You can also send a single notification to a single device:

device = Device.objects.get(pk=1)
send_push_notification('YOUR TITLE', {YOUR_PAYLOAD}, device=device)

Or you can use the filter_user or filter_type to make pushy send to a specified queryset of devices:

send_push_notification('YOUR TITLE', {YOUR_PAYLOAD}, filter_user=user)
send_push_notification('YOUR TITLE', {YOUR_PAYLOAD}, filter_type=Device.DEVICE_TYPE_IOS)

If you would like to add a push notification without triggering any action right away, you should be setting the property “payload instead of adding your dict to body as follows:

notification = PushNotification.objects.create(
    title=title,
    payload=payload,
    active=PushNotification.PUSH_ACTIVE,
    sent=PushNotification.PUSH_NOT_SENT
)

As some serialization takes place to automatically convert the payload to a JSON string to be stored into the database.

Admin

Django-pushy also provides an admin interface to it’s models so that you can add a push notification from admin.

For that to work, you need to add “check_pending_push_notifications” task into your periodic tasks in celery admin. Make sure you setup:

djcelery.setup_loader()
CELERYBEAT_SCHEDULER = 'djcelery.schedulers.DatabaseScheduler'

And don’t forget to run celerybeat.

Running the tests

Install mock:

pip install mock

then run the following from the project’s root:

python tests/run_tests.py

TODO

  • APNS (Apple) dispatcher is still not implemented
Release History

Release History

History Node

1.0.2

History Node

1.0.1

History Node

1.0.0

History Node

0.1.13

History Node

0.1.12

History Node

0.1.11

History Node

0.1.10

History Node

0.1.9

History Node

0.1.8

History Node

0.1.7

History Node

0.1.6

History Node

0.1.5

This version
History Node

0.1.4

History Node

0.1.3

History Node

0.1.2

History Node

0.1.1

History Node

0.1.0

Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
Django-Pushy-0.1.4.tar.gz (6.9 kB) Copy SHA256 Checksum SHA256 Source Oct 21, 2014

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting