Python Client SDK

The OneSignal Python client is a server OneSignal SDK for Python. Integrate OneSignal with your backend events, data, and more.

🚧

Backend SDKs in User Model Beta

You still can try using new User Model endpoints, we advise customers to not use these SDKs in production.

Python API Client

Requirements.

Python >=3.6

Installation & Usage

pip install

pip install onesignal-python-api

You can also install directly from GitHub using:

pip install git+https://github.com/GIT_USER_ID/GIT_REPO_ID.git

You may need to run pip with root permission:

sudo pip install git+https://github.com/GIT_USER_ID/GIT_REPO_ID.git

Setuptools

Install via Setuptools.

python setup.py install --user

To install the package for all users:

sudo python setup.py install

Getting Started

Please follow the installation procedure and then run the following:

import onesignal
from onesignal.api import default_api

# See configuration.py for a list of all supported configuration parameters.
# Some of the OneSignal endpoints require USER_KEY bearer token for authorization as long as others require APP_KEY
# (also knows as REST_API_KEY). We recommend adding both of them in the configuration page so that you will not need
# to figure it yourself.
configuration = onesignal.Configuration(
    app_key = "YOUR_API_KEY",
    user_key = "YOUR_USER_KEY"
)


# Enter a context with an instance of the API client
with onesignal.ApiClient(configuration) as api_client:
    # Create an instance of the API class
    api_instance = default_api.DefaultApi(api_client)

Authorization

All the OneSignal endpoints require either an app_key or user_key tokens for authorization. It is recommended to set up both of those keys during the initial config initialization so that you don't need to worry about which endpoint requires app_key and which user_key. You can get the value of these keys from your app dashboard and user settings pages.

Documentation for API Endpoints

All URIs are relative to https://onesignal.com/api/v1

ClassMethodHTTP requestDescription
DefaultApibegin_live_activityPOST /apps/{app_id}/live_activities/{activity_id}/tokenStart Live Activity
DefaultApicancel_notificationDELETE /notifications/{notification_id}Stop a scheduled or currently outgoing notification
DefaultApicreate_appPOST /appsCreate an app
DefaultApicreate_notificationPOST /notificationsCreate notification
DefaultApicreate_playerPOST /playersAdd a device
DefaultApicreate_segmentsPOST /apps/{app_id}/segmentsCreate Segments
DefaultApicreate_subscriptionPOST /apps/{app_id}/users/by/{alias_label}/{alias_id}/subscriptions
DefaultApicreate_userPOST /apps/{app_id}/users
DefaultApidelete_aliasDELETE /apps/{app_id}/users/by/{alias_label}/{alias_id}/identity/{alias_label_to_delete}
DefaultApidelete_playerDELETE /players/{player_id}Delete a user record
DefaultApidelete_segmentsDELETE /apps/{app_id}/segments/{segment_id}Delete Segments
DefaultApidelete_subscriptionDELETE /apps/{app_id}/subscriptions/{subscription_id}
DefaultApidelete_userDELETE /apps/{app_id}/users/by/{alias_label}/{alias_id}
DefaultApiend_live_activityDELETE /apps/{app_id}/live_activities/{activity_id}/token/{subscription_id}Stop Live Activity
DefaultApiexport_playersPOST /players/csv_export?app_id={app_id}CSV export
DefaultApifetch_aliasesGET /apps/{app_id}/subscriptions/{subscription_id}/user/identity
DefaultApifetch_userGET /apps/{app_id}/users/by/{alias_label}/{alias_id}
DefaultApifetch_user_identityGET /apps/{app_id}/users/by/{alias_label}/{alias_id}/identity
DefaultApiget_appGET /apps/{app_id}View an app
DefaultApiget_appsGET /appsView apps
DefaultApiget_eligible_iamsGET /apps/{app_id}/subscriptions/{subscription_id}/iams
DefaultApiget_notificationGET /notifications/{notification_id}View notification
DefaultApiget_notification_historyPOST /notifications/{notification_id}/historyNotification History
DefaultApiget_notificationsGET /notificationsView notifications
DefaultApiget_outcomesGET /apps/{app_id}/outcomesView Outcomes
DefaultApiget_playerGET /players/{player_id}View device
DefaultApiget_playersGET /playersView devices
DefaultApiidentify_user_by_aliasPATCH /apps/{app_id}/users/by/{alias_label}/{alias_id}/identity
DefaultApiidentify_user_by_subscription_idPATCH /apps/{app_id}/subscriptions/{subscription_id}/user/identity
DefaultApitransfer_subscriptionPATCH /apps/{app_id}/subscriptions/{subscription_id}/owner
DefaultApiupdate_appPUT /apps/{app_id}Update an app
DefaultApiupdate_live_activityPOST /apps/{app_id}/live_activities/{activity_id}/notificationsUpdate a Live Activity via Push
DefaultApiupdate_playerPUT /players/{player_id}Edit device
DefaultApiupdate_player_tagsPUT /apps/{app_id}/users/{external_user_id}Edit tags with external user id
DefaultApiupdate_subscriptionPATCH /apps/{app_id}/subscriptions/{subscription_id}
DefaultApiupdate_userPATCH /apps/{app_id}/users/by/{alias_label}/{alias_id}

Documentation For Models