A very simple Python client for the Pushy notification service API.
Project description
A very simple Python client for the Pushy notification service API.
Installation
Simply install using pip:
$ pip install PushySDK
or clone this repository and run the following:
$ python setup.py install
You will need to install the following dependencies: * requests * six * pypandoc
This can be done either manually or via pip with the included requirements.txt file as follows:
$ pip install -r requirements.txt
Usage
You will first need to signup for a Pushy account and integrate the Pushy SDK into your Android and/or iOS mobile application (please refer to the comprehensive Pushy Documentation). Once you have successfully sent a test notification from the Pushy Dashboard you are ready to write some python!
First, get your application API key from the Pushy Dashboard (Applications > Your App > API Authentication). Once you have this you can then do the following:
>>> from PushySDK import Pushy
>>> pushy=Pushy('<YOUR_API_KEY>')
You can now request information regarding a specific device (you can get device IDs from the Pushy Dashboard):
>>> pushy.deviceInfo('<YOUR_DEVICE_ID>')
This will return a python dictionary object of information about the device as follows:
{
'device': {'date': 1445207358, 'platform': 'android'},
'presence': {
'online': True,
'last_active': {'date': 1464006925, 'seconds_ago': 215}
},
pending_notifications': [
{
'date': 1464008196,
'expiration': 1466600196,
'payload': {'message': 'Hello World!'}, 'id': '5742fe0407c3674e226892f9'
}
]
}
You can also return presence information for single or multiple devices as follows:
>>> pushy.devicePresence(['<YOUR_DEVICE_ID>'])
{'presence': [
{
'online': False,
'last_active': 1429406442,
'id': 'a6f36efb913f1def30c6'
},
{
'online': True,
'last_active': 1468349965,
'id': 'fe8f7b2c12e83e5b41d2'
}
]}
To send a notification to a device or devices:
>>> data={'message':'Hello from Python and Pushy!'}
>>> pushy.push('<YOUR_DEVICE_ID>', data)
>>> pushy.push(['<YOUR_DEVICE_ID_1>', '<YOUR_DEVICE_ID_2>'], data)
To add extra data for iOS APNs notifications, a utility function exists to form the request as follows:
>>> title="Python/Pushy Notification"
>>> message='Hello from Python and Pushy!'
>>> badge=1
>>> sound="ping.aiff"
>>> apn=pushy.makeIOSNotification(message, badge, sound, title)
>>> pushy.push(['<YOUR_ANDROID_DEVICE_ID>', '<YOUR_IOS_DEVICE_ID>'], data, notification=apn)
The push() method will return a dictionary which reports the success or failure and a unique ID for the notification which can be used to track its status:
{'success': True, 'id': '5742ea5dacf3a92e17ba7126'}
You can track a notifications status as follows:
>>> pushy.notificationStatus('<YOUR_NOTIFICATION_ID>')
{
"push": {
"date": 1464003935,
"payload": {
"message": "Hello World!"
},
"expiration": 1466595935,
"pending_devices": [
"fe8f7b2c102e883e5b41d2"
]
}
}
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Hashes for PushySDK-0.1.3-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7b17a19cc5fd78a38b2ce4aeb9f08da27ae313032638c2388282e1998a589367 |
|
MD5 | a4d55e21aa8d5d16e8848bbb6f448cc0 |
|
BLAKE2b-256 | 74838fe3dec4f7b72c6ad6c50e510a84e59c5ff47ec16725fe1833fd14ee6d83 |