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
File details
Details for the file PushySDK-0.1.5-py2.py3-none-any.whl
.
File metadata
- Download URL: PushySDK-0.1.5-py2.py3-none-any.whl
- Upload date:
- Size: 6.9 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 07d506c03c34a97cc5d91a847f1d2178922ce5feb3e2a8db87b20fe400bf9480 |
|
MD5 | 80c00eea8883807f0f76b180e0913805 |
|
BLAKE2b-256 | 59806badb200db2af9034bdf1f394e78f2e4a24ea60928c5dbf26ede8c0181e8 |