Mobile Push API for Python-Asyncio SDK

The Mobile Push Notifications API of the PubNub SDK for Python-Asyncio registers a device token on channels. PubNub forwards a message with a push payload to each device registered on its channel, through Google Android FCM (Firebase Cloud Messaging) or Apple iOS APNs (Apple Push Notification service). To learn more, read about Mobile Push Notifications.

A builder sends its request when you await its future(). A request that fails, or fails validation, does not raise an exception. future() resolves with a PubNubAsyncioException whose result is None and whose status holds the error. Call is_error() on the awaited value before you read result.

Every parameter is also a builder method of the same name, so you can pass device_id as a keyword argument or chain .device_id().

Add a device to a push notifications channel​

pubnub.add_channels_to_push() enables mobile push notifications for a device on a set of channels with a PubNub client for Python-Asyncio.

required
channels required#
Type: List[str]
Default: no default
Channels on which to enable mobile push notifications for the device. Pass a list of channel names. A single string is not accepted. Pass at least one channel. A missing value, an empty list, or a string fails validation with the message Channel missing.
device_id required#
Type: str
Default: no default
Device token that identifies the device. The push service issues the token when the app registers for notifications. For PNPushType.APNS2, the token is a hexadecimal string of any length, and the service rejects any other format. For PNPushType.FCM, the token is an opaque string and the service accepts any value. An empty value fails validation with the message Device ID is missing for push operation.
push_type required#
Type: PNPushType
Default: no default
Push service that delivers the notifications to the device. Accepted values: PNPushType.FCM, PNPushType.APNS2. PNPushType.GCM is deprecated. Use PNPushType.FCM instead. A missing value fails validation with the message Push Type is missing.
topic#
Type: str
Default: no default
APNs topic of the app, which is its bundle identifier. The APNs2 push service requires a topic. A request with PNPushType.APNS2 and no topic fails validation with the message Push notification topic is missing. Required only if push type is APNS2..
environment#
Type: str
Default: PNPushEnvironment.DEVELOPMENT
APNs environment in which the device is registered. Only the APNs2 push service uses the environment. Accepted values: PNPushEnvironment.DEVELOPMENT, PNPushEnvironment.PRODUCTION. The SDK applies the default only when push_type is PNPushType.APNS2.

Returns​

add_channels_to_push() resolves with an AsyncioEnvelope whose result is a PNPushAddChannelResult and whose status is a PNStatus.

PNPushAddChannelResult has no fields, and str(result) returns Channel successfully added.

Syntax

1await pubnub.add_channels_to_push(
2 channels: List[str],
3 device_id: str,
4 push_type: PNPushType,
5 topic: Optional[str] = None,
6 environment: Optional[str] = None
7).future() -> AsyncioEnvelope

List push notifications channels for a device​

pubnub.list_push_channels() returns the channels on which a device receives mobile push notifications, using a PubNub client for Python-Asyncio.

required
device_id required#
Type: str
Default: no default
Device token that identifies the device. The push service issues the token when the app registers for notifications. For PNPushType.APNS2, the token is a hexadecimal string of any length, and the service rejects any other format. For PNPushType.FCM, the token is an opaque string and the service accepts any value. An empty value fails validation with the message Device ID is missing for push operation.
push_type required#
Type: PNPushType
Default: no default
Push service that delivers the notifications to the device. Accepted values: PNPushType.FCM, PNPushType.APNS2. PNPushType.GCM is deprecated. Use PNPushType.FCM instead. A missing value fails validation with the message Push Type is missing.
topic#
Type: str
Default: no default
APNs topic of the app, which is its bundle identifier. The APNs2 push service requires a topic. A request with PNPushType.APNS2 and no topic fails validation with the message Push notification topic is missing. Required only if push type is APNS2..
environment#
Type: str
Default: PNPushEnvironment.DEVELOPMENT
APNs environment in which the device is registered. Only the APNs2 push service uses the environment. Accepted values: PNPushEnvironment.DEVELOPMENT, PNPushEnvironment.PRODUCTION. The SDK applies the default only when push_type is PNPushType.APNS2.

Returns​

list_push_channels() resolves with an AsyncioEnvelope whose result is a PNPushListProvisionsResult and whose status is a PNStatus.

channels#
Type: List[str]
The names of the channels with mobile push notifications enabled for the device. The list is empty when the device has none.

Syntax

1await pubnub.list_push_channels(
2 device_id: str,
3 push_type: PNPushType,
4 topic: Optional[str] = None,
5 environment: Optional[str] = None
6).future() -> AsyncioEnvelope

Remove a device from push notifications channels​

pubnub.remove_channels_from_push() disables mobile push notifications for a device on the selected channels with a PubNub client for Python-Asyncio.

required
channels required#
Type: List[str]
Default: no default
Channels on which to disable mobile push notifications for the device. Pass a list of channel names. A single string is not accepted. Pass at least one channel. A missing value, an empty list, or a string fails validation with the message Channel missing.
device_id required#
Type: str
Default: no default
Device token that identifies the device. The push service issues the token when the app registers for notifications. For PNPushType.APNS2, the token is a hexadecimal string of any length, and the service rejects any other format. For PNPushType.FCM, the token is an opaque string and the service accepts any value. An empty value fails validation with the message Device ID is missing for push operation.
push_type required#
Type: PNPushType
Default: no default
Push service that delivers the notifications to the device. Accepted values: PNPushType.FCM, PNPushType.APNS2. PNPushType.GCM is deprecated. Use PNPushType.FCM instead. A missing value fails validation with the message Push Type is missing.
topic#
Type: str
Default: no default
APNs topic of the app, which is its bundle identifier. The APNs2 push service requires a topic. A request with PNPushType.APNS2 and no topic fails validation with the message Push notification topic is missing. Required only if push type is APNS2..
environment#
Type: str
Default: PNPushEnvironment.DEVELOPMENT
APNs environment in which the device is registered. Only the APNs2 push service uses the environment. Accepted values: PNPushEnvironment.DEVELOPMENT, PNPushEnvironment.PRODUCTION. The SDK applies the default only when push_type is PNPushType.APNS2.

Returns​

remove_channels_from_push() resolves with an AsyncioEnvelope whose result is a PNPushRemoveChannelResult and whose status is a PNStatus.

PNPushRemoveChannelResult has no fields, and str(result) returns Channel successfully removed.

Syntax

1await pubnub.remove_channels_from_push(
2 channels: List[str],
3 device_id: str,
4 push_type: PNPushType,
5 topic: Optional[str] = None,
6 environment: Optional[str] = None
7).future() -> AsyncioEnvelope

Remove a device from all push notifications channels​

pubnub.remove_device_from_push() disables mobile push notifications for a device on all channels registered for its device token, using a PubNub client for Python-Asyncio.

required
device_id required#
Type: str
Default: no default
Device token that identifies the device. The push service issues the token when the app registers for notifications. For PNPushType.APNS2, the token is a hexadecimal string of any length, and the service rejects any other format. For PNPushType.FCM, the token is an opaque string and the service accepts any value. An empty value fails validation with the message Device ID is missing for push operation.
push_type required#
Type: PNPushType
Default: no default
Push service that delivers the notifications to the device. Accepted values: PNPushType.FCM, PNPushType.APNS2. PNPushType.GCM is deprecated. Use PNPushType.FCM instead. A missing value fails validation with the message Push Type is missing.
topic#
Type: str
Default: no default
APNs topic of the app, which is its bundle identifier. The APNs2 push service requires a topic. A request with PNPushType.APNS2 and no topic fails validation with the message Push notification topic is missing. Required only if push type is APNS2..
environment#
Type: str
Default: PNPushEnvironment.DEVELOPMENT
APNs environment in which the device is registered. Only the APNs2 push service uses the environment. Accepted values: PNPushEnvironment.DEVELOPMENT, PNPushEnvironment.PRODUCTION. The SDK applies the default only when push_type is PNPushType.APNS2.

Returns​

remove_device_from_push() resolves with an AsyncioEnvelope whose result is a PNPushRemoveAllChannelsResult and whose status is a PNStatus.

PNPushRemoveAllChannelsResult has no fields, and str(result) returns All channels successfully removed.

Syntax

1await pubnub.remove_device_from_push(
2 device_id: str,
3 push_type: PNPushType,
4 topic: Optional[str] = None,
5 environment: Optional[str] = None
6).future() -> AsyncioEnvelope

Was this page useful?

Last updated on