Sending iOS Push Notifications using Python module PyAPNS

python-django

I have written a small module, that sends a push notification using PyAPNS.

This is how my sender.py module looks like:

Here is a Sender class inside sender.py module. It has one method send. Inside this method I create an object of APNs class, create a payload and send it using this object.
Cert.pem and Key.pem files are inside the folder with this module. They can be created using this tutorial. Also that folder contains apns.py module file with PyAPNS code.

To send a sample push notification from a command line I use following commands. First, I enter the folder with module. It is called notification_sender:

Or on server:

Then I enter to the python console:

Then I import Sender class from sender module:

Create a sender object of a Sender class:

And finally send a notification:

All you need to do to finish the job is to enter a PEM pass phrase:

Currently, the device token is hardcoded, I am planning to use SQLite entries with collected tokens. I use Django to collect tokens.

I would like to add that if you change somehow the source file of a module, you should reenter python console and recreate object to make changes work.

Leave a Reply

Your email address will not be published. Required fields are marked *