---
source_url: https://www.pubnub.com/docs/sdks/python/api-reference/mobile-push
title: Mobile Push Notifications API for Python SDK
updated_at: 2026-06-05T11:13:02.047Z
sdk_name: PubNub Python SDK
sdk_version: 10.6.3
---

> Documentation Index
> For a curated overview of PubNub documentation, see: https://www.pubnub.com/docs/llms.txt
> For the full list of all documentation pages, see: https://www.pubnub.com/docs/llms-full.txt


# Mobile Push Notifications API for Python SDK

PubNub Python SDK, use the latest version: 10.6.3

Install:

```bash
pip install pubnub@10.6.3
```

The Mobile Push Notifications feature connects native PubNub publishing to third-party push services. Supported services include Google Android FCM (Firebase Cloud Messaging) and Apple iOS APNs (Apple Push Notification service).

To learn more, read about [Mobile Push Notifications](https://www.pubnub.com/docs/general/push/send).

:::note Request execution and return values
You can decide whether to perform the Python SDK operations synchronously or asynchronously.
* .sync() returns an Envelope object, which has two fields: Envelope.result, whose type differs for each API, and Envelope.status of type PnStatus. 1pubnub.publish() \2 .channel("myChannel") \3 .message("Hello from PubNub Python SDK") \4 .sync()
* .pn_async(callback) returns None and passes the values of Envelope.result and Envelope.status to a callback you must define beforehand. 1def my_callback_function(result, status):2 print(f'TT: {result.timetoken}, status: {status.category.name}')3 4pubnub.publish() \5 .channel("myChannel") \6 .message("Hello from PubNub Python SDK") \7 .pn_async(my_callback_function)
:::

## Add a device to a push notifications channel

:::note Requires Mobile Push Notifications add-on
Enable Mobile Push Notifications for your key in the [Admin Portal](https://admin.pubnub.com/). See how to [enable add-on features](https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-).
:::

Enable mobile push notifications on a set of channels.

### Method(s)

To run `Adding Device to Channel` you can use the following method(s) in the Python SDK:

```python
pubnub.add_channels_to_push() \
    .push_type(PNPushType) \
    .channels(List) \
    .device_id(String) \
    .topic(String) \
    .environment(PNPushEnvironment)
```

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| push_type | PNPushType | Yes |  | The push notification type. Accepted values: `PNPushType.FCM`, `PNPushType.APNS2`. |
| channels | List | Yes |  | The `channels` to add the mobile push notifications to. |
| device_id | String | Yes |  | The device ID (token) to associate with the mobile push notifications. |
| topic | String | Optional |  | The topic name for the notification. For the Apple platform, this is the application's bundle identifier. Required only if `push_type` is set to `PNPushType.APNS2`. |
| environment | String | Optional | `PNPushEnvironment.DEVELOPMENT` | The environment where the device should manage the list of channels with enabled notifications. Required only if `push_type` is set to `PNPushType.APNS2`. |

### Sample code

#### Add device to channel

:::tip Reference code
This example is a self-contained code snippet ready to be run. It includes necessary imports and executes methods with console logging. Use it as a reference when working with other examples in this document.
:::

###### Builder Pattern

```python
import os
from pubnub.pnconfiguration import PNConfiguration
from pubnub.pubnub import PubNub
from pubnub.enums import PNPushType, PNPushEnvironment
from pubnub.exceptions import PubNubException

def add_device_to_channel(pubnub: PubNub):
    try:
        # For FCM
        pubnub.add_channels_to_push() \
            .push_type(PNPushType.FCM) \
            .channels(["ch1", "ch2", "ch3"]) \
            .device_id("deviceId") \
            .sync()
        print("Device added to channels for FCM successfully.")

        # For APNS2 device token should be 32 or 100 byte hex
        pubnub.add_channels_to_push() \
            .push_type(PNPushType.APNS2) \
            .channels(["ch1", "ch2", "ch3"]) \
            .device_id("00000000000000000000000000000000") \
            .topic("myapptopic") \
            .environment(PNPushEnvironment.DEVELOPMENT) \
            .sync()
        print("Device added to channels for APNS2 successfully.")

    except PubNubException as e:
        print(f"Error: {e}")

def main():
    # Configuration for PubNub instance
    pn_config = PNConfiguration()
    pn_config.subscribe_key = os.getenv('SUBSCRIBE_KEY', 'demo')
    pn_config.publish_key = os.getenv('PUBLISH_KEY', 'demo')
    pn_config.user_id = os.getenv('USER_ID', 'my_custom_user_id')

    # Initialize PubNub client
    pubnub = PubNub(pn_config)

    # Add device to channel
    add_device_to_channel(pubnub)

if __name__ == "__main__":
    main()
```

###### Named Arguments

```python
import os
from pubnub.pnconfiguration import PNConfiguration
from pubnub.pubnub import PubNub
from pubnub.enums import PNPushType, PNPushEnvironment
from pubnub.exceptions import PubNubException

def add_device_to_channel(pubnub: PubNub):
    try:
        # For FCM
        pubnub.add_channels_to_push(
            push_type=PNPushType.FCM,
            channels=["ch1", "ch2", "ch3"],
            device_id="deviceId"
        ).sync()
        print("Device added to channels for FCM successfully.")

        # For APNS2
        pubnub.add_channels_to_push(
            push_type=PNPushType.APNS2,
            channels=["ch1", "ch2", "ch3"],
            device_id="00000000000000000000000000000000",
            topic="myapptopic",
            environment=PNPushEnvironment.DEVELOPMENT
        ).sync()
        print("Device added to channels for APNS2 successfully.")

    except PubNubException as e:
        print(f"Error: {e}")

def main():
    # Configuration for PubNub instance
    pn_config = PNConfiguration()
    pn_config.subscribe_key = os.getenv('SUBSCRIBE_KEY', 'demo')
    pn_config.publish_key = os.getenv('PUBLISH_KEY', 'demo')
    pn_config.user_id = os.getenv('USER_ID', 'my_custom_user_id')

    # Initialize PubNub client
    pubnub = PubNub(pn_config)

    # Add device to channel
    add_device_to_channel(pubnub)

if __name__ == "__main__":
    main()
```

### Returns

The `add_channels_to_push()` operation does not return actionable data. You can check the `status` object for the outcome by inspecting `status.is_error()`.

## List channels for device

:::note Requires Mobile Push Notifications add-on
This method requires that the Mobile Push Notifications add-on is enabled for your key in the [Admin Portal](https://admin.pubnub.com/). Read the [support page](https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-) on enabling add-on features on your keys.
:::

List channels that have push notifications enabled for the specified device token.

### Method(s)

Use the following method(s) in the Python SDK:

```python
pubnub.list_push_channels() \
    .push_type(PNPushType) \
    .device_id(String) \
    .topic(String) \
    .environment(PNPushEnvironment)
```

| Parameter | Description |
| --- | --- |
| `push_type` *Type: PNPushTypeDefault: n/a | The push notification type. Accepted values: `PNPushType.FCM`, `PNPushType.APNS2`. |
| `device_id` *Type: StringDefault: n/a | Device token. |
| `topic`Type: StringDefault: n/a | APNs topic (bundle identifier). Required if `push_type` is `PNPushType.APNS2`. |
| `environment`Type: StringDefault: `PNPushEnvironment.DEVELOPMENT` | APNs environment. Required if `push_type` is `PNPushType.APNS2`. |

### Sample code

#### List channels for device

##### Builder Pattern

```python
from pubnub.enums import PNPushType, PNPushEnvironment

# For FCM
envelope = pubnub.list_push_channels() \
    .push_type(PNPushType.FCM) \
    .device_id("deviceId") \
    .sync()

# For APNS2
envelope = pubnub.list_push_channels() \
    .push_type(PNPushType.APNS2) \
    .device_id("deviceId") \
    .topic("myapptopic") \
    .environment(PNPushEnvironment.DEVELOPMENT) \
    .sync()
```

##### Named Arguments

```python
from pubnub.enums import PNPushType, PNPushEnvironment

# For FCM
envelope = pubnub.list_push_channels(push_type=PNPushType.FCM, device_id="deviceId").sync()

# For APNS2
envelope = pubnub.list_push_channels(push_type=PNPushType.APNS2,
                                     device_id="deviceId",
                                     topic="myapptopic",
                                     environment=PNPushEnvironment.DEVELOPMENT) \
    .sync()
```

### Returns

The `list_push_channels()` operation returns an `Envelope` which contains the following fields:

| Field | Type | Description |
| --- | --- | --- |
| result | [PNPushListProvisionsResult](#pnpushlistprovisionsresult) | A detailed object containing the result of the operation. |
| status | `PNStatus` | A status object with additional information. |

#### PNPushListProvisionsResult

| Method | Description |
| --- | --- |
| `Channels`Type: List | List of `channels` associated for mobile push notifications. |

## Remove device from channel

:::note Requires Mobile Push Notifications add-on
Enable Mobile Push Notifications for your key in the [Admin Portal](https://admin.pubnub.com/). See how to [enable add-on features](https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-).
:::

Disable mobile push notifications on a set of channels.

### Method(s)

Use the following method(s) in the Python SDK:

```python
pubnub.remove_channels_from_push() \
    .push_type(PNPushType) \
    .channels(List) \
    .device_id(String) \
    .topic(String) \
    .environment(PNPushEnvironment)
```

| Parameter | Description |
| --- | --- |
| `push_type` *Type: PNPushTypeDefault: n/a | The push notification type. Accepted values: `PNPushType.FCM`, `PNPushType.APNS2`. |
| `channels` *Type: ListDefault: n/a | Channels to disable for push notifications. |
| `device_id` *Type: StringDefault: n/a | Device token. |
| `topic`Type: StringDefault: n/a | APNs topic (bundle identifier). Required if `push_type` is `PNPushType.APNS2`. |
| `environment`Type: StringDefault: `PNPushEnvironment.DEVELOPMENT` | APNs environment. Required if `push_type` is `PNPushType.APNS2`. |

### Sample code

#### Remove device from channel

##### Builder Pattern

```python
from pubnub.enums import PNPushType, PNPushEnvironment

# For FCM
envelope = pubnub.remove_channels_from_push() \
    .push_type(PNPushType.FCM) \
    .channels("ch1", "ch2", "ch3") \
    .device_id("deviceId") \
    .sync()

# For APNS2
envelope = pubnub.remove_channels_from_push() \
    .push_type(PNPushType.APNS2) \
    .channels("ch1", "ch2", "ch3") \
    .device_id("deviceId") \
    .topic("myapptopic") \
    .environment(PNPushEnvironment.DEVELOPMENT) \
    .sync()
```

##### Named Arguments

```python
from pubnub.enums import PNPushType, PNPushEnvironment

# For FCM
envelope = pubnub.remove_channels_from_push(channels=["ch1", "ch2", "ch3"],
                                            push_type=PNPushType.FCM,
                                            device_id="deviceId") \
    .sync()

# For APNS2
envelope = pubnub.remove_channels_from_push(channels=["ch1", "ch2", "ch3"],
                                            push_type=PNPushType.APNS2,
                                            device_id="deviceId",
                                            topic="myapptopic",
                                            environment=PNPushEnvironment.DEVELOPMENT) \
    .sync()
```

### Returns

The `remove_channels_from_push()` operation does not return actionable data. You can check the `status` object for the outcome by inspecting `status.is_error()`.

## Remove all mobile push notifications

:::note Requires Mobile Push Notifications add-on
Enable Mobile Push Notifications for your key in the [Admin Portal](https://admin.pubnub.com/). See how to [enable add-on features](https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-).
:::

Disable mobile push notifications from all channels registered with the specified device token.

### Method(s)

Use the following method(s) in the Python SDK:

```python
pubnub.remove_device_from_push() \
    .push_type(PNPushType) \
    .device_id(String) \
    .topic(String) \
    .environment(PNPushEnvironment)
```

| Parameter | Description |
| --- | --- |
| `push_type` *Type: PNPushTypeDefault: n/a | The push notification type. Accepted values: `PNPushType.FCM`, `PNPushType.APNS2`. |
| `device_id` *Type: StringDefault: n/a | Device token. |
| `topic`Type: StringDefault: n/a | APNs topic (bundle identifier). Required if `push_type` is `PNPushType.APNS2`. |
| `environment`Type: StringDefault: `PNPushEnvironment.DEVELOPMENT` | APNs environment. Required if `push_type` is `PNPushType.APNS2`. |

### Sample code

#### Remove all mobile push notifications

##### Builder Pattern

```python
from pubnub.enums import PNPushType, PNPushEnvironment

# For FCM
envelope = pubnub.remove_device_from_push() \
    .push_type(PNPushType.FCM) \
    .device_id("deviceId") \
    .sync()

# For APNS2
envelope = pubnub.remove_device_from_push() \
    .push_type(PNPushType.APNS2) \
    .device_id("deviceId") \
    .topic("myapptopic") \
    .environment(PNPushEnvironment.DEVELOPMENT) \
    .sync()
```

##### Named Arguments

```python
from pubnub.enums import PNPushType, PNPushEnvironment

# For FCM
envelope = pubnub.remove_device_from_push(device_id="deviceId", push_type=PNPushType.FCM).sync()

# For APNS2
envelope = pubnub.remove_device_from_push(device_id="deviceId",
                                          push_type=PNPushType.APNS2,
                                          topic="myapptopic",
                                          environment=PNPushEnvironment.DEVELOPMENT) \
    .sync()
```

### Returns

The `remove_device_from_push()` operation does not return actionable data. You can check the `status` object for the outcome by inspecting `status.is_error()`.

## Terms in this document

* **Channel** - A pathway for sending and receiving messages between devices, created automatically when you first use it, that can handle any number of users and messages for different communication needs, like 1-1 text chats, group conversations, and other data streaming.
* **PubNub** - PubNub is a real-time messaging platform that provides APIs and SDKs for building scalable applications. It handles the complex infrastructure of real-time communication, including: Message delivery and persistence, Presence detection, Access control, Push notifications, File sharing, Serverless processing with Functions and Events & Actions, Analytics and monitoring with BizOps Workspace, AI-powered insights with Illuminate.