Python client for OneSignal push notification service
pip install onesignal-pythonpip install git+https://github.com/joaobarbosa/onesignal-python.git
Example, sending push to specific devices (currently, only way supported).
from requests.exceptions import HTTPError
from onesignalclient.app_client import OneSignalAppClient
from onesignalclient.notification import Notification
player_id = 'sample00-play-er00-id00-000000000000'
os_app_id = 'sample00-app0-id00-0000-000000000000'
os_apikey = 'your-rest-api-key-goes-here'
# Init the client
client = OneSignalAppClient(app_id=os_app_id, app_api_key=os_apikey)
# Creates a new notification
notification = Notification(app_id, Notification.DEVICES_MODE)
notification.include_player_ids = [player_id] # Must be a list!
try:
# Sends it!
result = client.create_notification(notification)
except HTTPError as e:
result = e.response.json()
print(result)
# Success: {'id': '1d63fa3a-2205-314f-a734-a1de7e27cc2a', 'recipients': 1}
# Error: {'errors': ['Invalid app_id format']} - or any other message- Python 3.3+
requirements.txtorrequirements-test.txt
Using make:
make run_tests
Using pytest:
py.test --pep8 --cov=. --cov-report=term-missing --cov-config=.coveragerc -r a -v -s
List of API methods to be covered by our client.
[U] - requires User Auth | [A] - requires App API Key
- [A] Create notification
- Segments mode settings & params
Devices mode settings & params- Improve tests as new params are added
- Filters mode settings & params
- Common Parameters
- App
app_idapp_ids
- Content
contents- Behaviour when using
template_id
- Behaviour when using
headingssubtitletemplate_idcontent_availablemutable_content
- Attachments
dataurlios_attachmentsbig_pictureadm_big_picturechrome_big_picture
- Appearance
android_background_layoutsmall_iconlarge_iconchrome_web_iconfirefox_iconadm_small_iconadm_large_iconchrome_iconios_soundandroid_soundadm_soundwp_soundwp_wns_soundandroid_led_colorandroid_accent_colorandroid_visibilityios_badgeTypeios_badgeCountcollapse_id
- Delivery
send_afterdelayed_optiondelivery_time_of_dayttlpriority
- Others coming soon
- App
- Export data for request
[A] Cancel notification[U] View apps[U] View an app- [U] Create an app
- [U] Update an app
- [A] View devices
- View device
- [U] Add a device
- Edit device
- [U] New session
- New purchase
- Increment session length
- [A] CSV export
Regular exportExtra fields- Make it available in the user client
- [U] View notification
- [A] View notifications
- Track open