Push Notifications API for PubNub Python-Twisted SDK
Python version support
Python SDK versions 5.0.0 and higher no longer support Python v2.7 and the Twisted and Tornado frameworks. If you require support for any of these, use SDK version 4.8.1.
Note that PubNub will stop supporting versions of Python lower than 3.7 by the end of 2021.
Deprecated
NOTICE: Based on current web trends and our own usage data, PubNub's Python Twisted SDK is deprecated as of May 1, 2019. Deprecation means we will no longer be updating the Python Twisted SDK but will continue to support users currently using it. Please feel free to use our other Python SDK offerings as they will continue to be supported and maintained. If you would like to use the Python Twisted SDK specifically, we would love to work with you on keeping this project alive!
PubNub's Mobile Push Gateway feature enables developers to bridge native PubNub publishing with 3rd-party push notification services including Google Android FCM (Firebase Cloud Messaging) and Apple iOS APNs (Apple Push Notification service).
By using the Mobile Push Gateway, developers can eliminate the need for developing, configuring, and maintaining additional server-side components for third-party push notification providers.
Adding Device to Channel
Requires Mobile Push Notifications add-on Requires that you enable the Mobile Push Notifications for your key. Refer to the following page for details on enabling add-on features on your keys:
https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-
Description
Enable push notifications on provided set of channels.
Method(s)
To run Adding Device to Channel
you can use the following method(s) in the Python-Twisted SDK:
pubnub.add_channels_to_push().push_type(PNPushType).channels(List).device_id(String).topic(String).environment(PNPushEnvironment)
Parameter Type Required Defaults Description push_type
PNPushType Yes n/a The available push types. Accepted values: PNPushType.GCM
,PNPushType.FCM
,PNPushType.APNS
,PNPushType.APNS2
channels
List Yes n/a The channels
to add the push notifications to.device_id
String Yes n/a The device ID (token) to associate with the push notifications. topic
String Required for PNPushType.APNS2
n/a The topic name for the notification. For the Apple platform, this is the application's bundle identifier. Required only if push_type
is set toPNPushType.APNS2
.environment
String Required for PNPushType.APNS2
PNPushEnvironment.DEVELOPMENT
The environment where the device should manage the list of channels with enabled notifications. Required only if push_type
is set toPNPushType.APNS2
.
Basic Usage
from pubnub.enums import PNPushType
d = pubnub.add_channels_to_push()\
.push_type(PNPushType.GCM)\
.channels(["ch1", "ch2", "ch3"])\
.device_id("deviceId")\
.deferred()
d.addCallback(my_callback)
Returns
The add_channels_to_push()
does not return actionable data, be sure to check the status object on the outcome of the operation by checking the status.is_error()
Listing Channels For Device
Requires Mobile Push Notifications add-on Requires that you enable the Mobile Push Notifications for your key. Refer to the following page for details on enabling add-on features on your keys:
https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-
Description
Request for all channels on which push notification has been enabled using specified pushToken.
Method(s)
To run Listing Channels For Device
you can use the following method(s) in the Python-Twisted SDK:
pubnub.list_push_channels().push_type(PNPushType).device_id(String).topic(String).environment(PNPushEnvironment)
Parameter Type Required Defaults Description push_type
PNPushType Yes n/a The available push types. Accepted values: PNPushType.GCM
,PNPushType.FCM
,PNPushType.APNS
,PNPushType.APNS2
device_id
String Yes n/a The device ID (token) to associate with the push notifications. topic
String Required for PNPushType.APNS2
n/a The topic name for the notification. For the Apple platform, this is the application's bundle identifier. Required only if push_type
is set toPNPushType.APNS2
.environment
String Required for PNPushType.APNS2
PNPushEnvironment.DEVELOPMENT
The environment where the device should manage the list of channels with enabled notifications. Required only if push_type
is set toPNPushType.APNS2
.
Basic Usage
from pubnub.enums import PNPushType
d = pubnub.list_push_channels()\
.push_type(PNPushType.GCM)\
.device_id("deviceId")\
.deferred()
d.addCallback(my_callback)
Returns
The list_push_channels()
operation returns a PNPushListProvisionsResult
which contains the following fields:
Method | Type | Description |
---|---|---|
Channels | List | List of channels associated for push notifications. |
Removing Device From Channel
Requires Mobile Push Notifications add-on Requires that you enable the Mobile Push Notifications for your key. Refer to the following page for details on enabling add-on features on your keys:
https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-
Description
Disable push notifications on provided set of channels. If nil
will be passed as channels then client will remove push notifications from all channels which associated with pushToken
.
Method(s)
To run Removing Device From Channel
you can use the following method(s) in the Python-Twisted SDK:
pubnub.remove_channels_from_push().push_type(PNPushType).channels(List).device_id(String).topic(String).environment(PNPushEnvironment)
Parameter Type Required Defaults Description push_type
PNPushType Yes n/a The available push types. Accepted values: PNPushType.GCM
,PNPushType.FCM
,PNPushType.APNS
,PNPushType.APNS2
channels
List Yes n/a The channels
to add the push notifications to.device_id
String Yes n/a The device ID (token) to associate with the push notifications. topic
String Required for PNPushType.APNS2
n/a The topic name for the notification. For the Apple platform, this is the application's bundle identifier. Required only if push_type
is set toPNPushType.APNS2
.environment
String Required for PNPushType.APNS2
PNPushEnvironment.DEVELOPMENT
The environment where the device should manage the list of channels with enabled notifications. Required only if push_type
is set toPNPushType.APNS2
.
Basic Usage
from pubnub.enums import PNPushType
d = pubnub.remove_channels_from_push()\
.push_type(PNPushType.GCM)\
.channels("ch1", "ch2", "ch3")\
.device_id("deviceId")\
.deferred()
d.addCallback(my_callback)
Returns
The remove_channels_from_push()
does not return actionable data, be sure to check the status object on the outcome of the operation by checking the status.is_error()
.