Python client for OneSignal push notification service
pip install onesignal-python
pip 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
requirements.txt
or requirements-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
app_id
app_ids
contents
template_id
headings
subtitle
template_id
content_available
mutable_content
data
url
ios_attachments
big_picture
adm_big_picture
chrome_big_picture
android_background_layout
small_icon
large_icon
chrome_web_icon
firefox_icon
adm_small_icon
adm_large_icon
chrome_icon
ios_sound
android_sound
adm_sound
wp_sound
wp_wns_sound
android_led_color
android_accent_color
android_visibility
ios_badgeType
ios_badgeCount
collapse_id
send_after
delayed_option
delivery_time_of_day
ttl
priority