PyPush
PyPush is a rewrite/fork of apns-python-wrapper, that is, PyPush is a python module for interacting with Apples Push Notification Server.
Code is available from here where bugs can also be reported. Licensed under the Apache 2.0 license.
Usage:
In order to connect to the push server you will need to export the certificates given to you by Apple in the right format. This is demonstrated here.
First you'll want to create a connection to the push notification server:
gateway = NotificationGateway('apns-dev.pem') |
This will open up a connection the the sandbox push notification server. If you want to use the production server do the following instead:
gateway = NotificationGateway('apns.pem', True) |
In both instances the keep-alive property is set on the socket.
Next we'll need to create a message
notification = Notification() notification.device_token_hex = 'hex token value' notification.alert = 'Hello World!' notification.sound = 'default' notification.badge = 3 |
This notification has a text alert of 'Hello World!', will set the badge to '3' and will play the default sound effect.
gateway.append(notification) |
This appends the notification, but doesn't actually send it. This is so we can setup many messages by creating a new Notification object for each and calling gateway.append for each of them.
Finally, to send the notification a simple
gateway.notify() |
is all that is needed. This will send every queued up notification to the Apple push notification server.
When we are finished with the connection we can call
gateway.close() |
Now, of course we want to be able to receive feedback about the messages we send, the following snippet of code demonstrates how
feedback = NotificationFeedback('apns-dev.pem') feedback.receive() for timestamp, device_token in feedback.feedbacks: print timestamp, binascii.b2a_hex(device_token) |
Each iteration of the loop will give a timestamp and device token which can be used as needed.



