iOS Push Notifications (APNS) with Django

Posted on : 2nd Oct 2018

Sending iOS push notifications with python. I found this great and easy module named pyapns on github, developed by samuraisam. It is quite handy module to provide you Apple push notification services. It supports Ruby and Python.

To Install :

$ sudo easy_install pyapns
To keep it running continuosly we will be using twistd here, to start pyapns server using twistd follow this command :
>>> twistd -r epoll web --class=pyapns.server.APNServer --port=7077
Read more about twistd here.

With the command, we started twistd server for pyapns on port 7077. Import the necessary objects :

>>> from pyapns import configure, provision, notify

Now, using the configure imported from pyapns, start the server on localhost port 7077. Next, in the provision function parse your appname, pem file and the category of pem file (sandbox/production).

>>> provision('app-name-here', open('cert.pem').read(), 'sandbox') 

At last, using notify we will send the notification.

>>> notify('myapp', 'device_id_here', {'aps':{'alert': 'Hello!'}})

Full Documentation :
pyapns on Github

© 2021, All Rights Reserved · Vipin Joshi