---
source_url: https://www.pubnub.com/docs/sdks/asyncio/api-reference/mobile-push
title: Mobile Push Notifications API for Python-Asyncio SDK
updated_at: 2026-05-27T14:31:49.845Z
sdk_name: PubNub Python Asyncio SDK
---

> 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-Asyncio SDK

PubNub Python Asyncio SDK

Install:

```bash
pip install pubnub
```

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).

Use Mobile Push Notifications to eliminate the need to develop, configure, and maintain server-side components for third-party push notification providers.

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

## 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)

```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 |  | Push type. One of: `PNPushType.GCM`, `PNPushType.FCM`, `PNPushType.APNS2`. |
| channels | List | Yes |  | Channels to enable for push notifications. |
| device_id | String | Yes |  | Device token used for push notifications. |
| topic | String | Optional |  | APNs topic (bundle identifier). |
| environment | String | Optional | `PNPushEnvironment.DEVELOPMENT` | APNs environment. |

### 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.
:::

```python
# for FCM/GCM
import asyncio
import os
from pubnub.pnconfiguration import PNConfiguration
from pubnub.pubnub_asyncio import PubNubAsyncio
from pubnub.enums import PNPushType, PNPushEnvironment
from pubnub.exceptions import PubNubException

async def add_device_to_channel(pubnub: PubNubAsyncio, push_type, topic=None, environment=None):
    try:
        # Add Device to Channels for Push Notifications
        kwargs = {
            "push_type": push_type,
            "channels": ["ch1", "ch2", "ch3"],
            "device_id": "12345678901234567890123456789012", #  device_id has to have 32 characters
        }
        if topic:
            kwargs["topic"] = topic
        if environment:
            kwargs["environment"] = environment

        envelope = await pubnub.add_channels_to_push(**kwargs).future()

        if envelope.status.is_error():
            print("Error adding device to channels for push notifications")
        else:
            print("Device added to channels successfully")

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

if __name__ == "__main__":
    loop = asyncio.new_event_loop()
    asyncio.set_event_loop(loop)

    # Configuration for PubNub instance
    pn_config = PNConfiguration()
    pn_config.subscribe_key = os.getenv('SUBSCRIBE_KEY', 'demo')
    pn_config.user_id = "my_custom_user_id"

    pubnub = PubNubAsyncio(pn_config)

    try:
        # For FCM/GCM
        loop.run_until_complete(add_device_to_channel(pubnub, PNPushType.GCM))

        # For APNS2
        loop.run_until_complete(add_device_to_channel(pubnub, PNPushType.APNS2, topic="myapptopic", environment=PNPushEnvironment.DEVELOPMENT))
    finally:
        loop.run_until_complete(pubnub.stop())
        loop.close()
```

### Returns

No payload is returned. Check `status.is_error()` on the status object.

## List push notifications channels for a device

:::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-).
:::

Get all channels with push notifications for the specified push token.

### Method(s)

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

| Parameter | Description |
| --- | --- |
| `push_type` *Type: PNPushTypeDefault: n/a | Push type. One of: `PNPushType.GCM`, `PNPushType.FCM`, `PNPushType.APNS2`. |
| `device_id` *Type: StringDefault: n/a | Device token used for push notifications. |
| `topic`Type: StringDefault: n/a | APNs topic (bundle identifier). Required for APNS2. |
| `environment`Type: StringDefault: `PNPushEnvironment.DEVELOPMENT` | APNs environment. Required for APNS2. |

### Sample code

#### List channels for device

```python
# for FCM/GCM
from pubnub.enums import PNPushType

envelope = await pubnub.list_push_channels()\
    .push_type(PNPushType.GCM)\
    .device_id("deviceId")\
    .future()

# for APNS2
from pubnub.enums import PNPushType

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

### Returns

Returns `PNPushListProvisionsResult` with:

| Method | Description |
| --- | --- |
| `Channels`Type: List | Channels associated with push notifications. |

## Remove a device from push notifications channels

:::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 push notifications on selected channels. If `channels` is `nil`, the client removes push notifications from all channels for the push token.

### Method(s)

```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 | Push type. One of: `PNPushType.GCM`, `PNPushType.FCM`, `PNPushType.APNS2`. |
| `channels` *Type: ListDefault: n/a | Channels to disable for push notifications. |
| `device_id` *Type: StringDefault: n/a | Device token used for push notifications. |
| `topic`Type: StringDefault: n/a | APNs topic (bundle identifier). |
| `environment`Type: StringDefault: `PNPushEnvironment.DEVELOPMENT` | APNs environment. |

### Sample code

#### Remove device from channel

```python
# for FCM/GCM
from pubnub.enums import PNPushType

envelope = await pubnub.remove_channels_from_push()\
    .push_type(PNPushType.GCM)\
    .channels("ch1", "ch2", "ch3")\
    .device_id("deviceId")\
    .future()

# for APNS2
from pubnub.enums import PNPushType

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

### Returns

No payload is returned. Check `status.is_error()` on the status object.

## Remove a device from all push notifications channels

:::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 push notifications from all channels registered for the specified push token.

### Method(s)

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

| Parameter | Description |
| --- | --- |
| `push_type` *Type: PNPushTypeDefault: n/a | Push type. One of: `PNPushType.GCM`, `PNPushType.FCM`, `PNPushType.APNS2`, `PNPushType.MPNS`. |
| `device_id` *Type: StringDefault: n/a | Device token used for push notifications. |
| `topic`Type: StringDefault: n/a | APNs topic (bundle identifier). Required for APNS2. |
| `environment`Type: StringDefault: `PNPushEnvironment.DEVELOPMENT` | APNs environment. Required for APNS2. |

### Sample code

#### Remove all mobile push notifications

```python
# for FCM/GCM
from pubnub.enums import PNPushType

envelope = await pubnub.remove_device_from_push()\
    .push_type(PNPushType.GCM)\
    .device_id("deviceId")\
    .future()

# for APNS2
from pubnub.enums import PNPushType

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

### Rest response from server

No payload is returned. Check `status.is_error()` on the status object.

## 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.
* **Push token** - A device identifier issued by a push provider (APNs or FCM) used to register a device for receiving mobile push notifications.