---
source_url: https://www.pubnub.com/docs/sdks/asyncio/api-reference/channel-groups
title: Channel Groups API for Python-Asyncio SDK
updated_at: 2026-06-19T11:36:39.510Z
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


# Channel Groups API for Python-Asyncio SDK

PubNub Python Asyncio SDK

Install:

```bash
pip install pubnub
```

[Channel groups](https://www.pubnub.com/docs/general/channels/subscribe#channel-groups) allow PubNub developers to bundle thousands of [channels](https://www.pubnub.com/docs/general/channels/overview) into a group that can be identified by a name. These channel groups can then be subscribed to, receiving data from the many back-end channels the channel group contains.

:::note Channel group operations
You can't publish to a channel group. You can only subscribe to it. To publish within the channel group, you need to publish to each channel individually.
:::

## Add channels to a channel group

:::note Requires Stream Controller add-on
This method requires that the *Stream Controller* add-on is enabled for your key in the PubNub [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.
:::

This function adds channels to a channel group.

### Method(s)

Use the following method in the Python-Asyncio SDK:

:::note Maximum number of channels
You can add up to 200 channels to a channel group per API call.
:::

```python
pubnub.add_channel_to_channel_group() \
    .channels(String|List|Tuple) \
    .channel_group(String)
```

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| channels | String | Yes |  | The channels to add to the channel group. |
| channel_group | String | Yes |  | The channel group to add the channels to. |

### Sample code

#### Add channels

:::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
import asyncio
import os
from pubnub.pnconfiguration import PNConfiguration
from pubnub.pubnub_asyncio import PubNubAsyncio
from pubnub.exceptions import PubNubException

async def add_channels_to_group(pubnub: PubNubAsyncio):
    try:
        # Add Channels to a Channel Group
        envelope = await pubnub.add_channel_to_channel_group() \
            .channels(["ch1", "ch2"]) \
            .channel_group("cg1") \
            .future()

        if envelope.status.is_error():
            print("Error adding channels to channel group")
        else:
            print("Channels added 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:
        loop.run_until_complete(add_channels_to_group(pubnub))
    finally:
        loop.run_until_complete(pubnub.stop())
        loop.close()
```

## List channels in a channel group

:::note Requires Stream Controller add-on
This method requires that the *Stream Controller* 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.
:::

This function lists all channels in a channel group.

### Method(s)

Use the following method in the Python-Asyncio SDK:

```python
pubnub.list_channels_in_channel_group() \
    .channel_group(String)
```

| Parameter | Description |
| --- | --- |
| `channel_group` *Type: String | The channel group for which to list channels. |

### Sample code

#### List channels

```python
envelope = pubnub.list_channels_in_channel_group().\
    channel_group("cg1").future()
```

## Remove channels from a channel group

:::note Requires Stream Controller add-on
This method requires that the *Stream Controller* 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.
:::

This function removes channels from a channel group.

### Method(s)

Use the following method in the Python-Asyncio SDK:

```python
pubnub.remove_channel_from_channel_group() \
    .channels(String|List|Tuple) \
    .channel_group(String)
```

| Parameter | Description |
| --- | --- |
| `channels` *Type: String | List | Tuple | The channels to remove from the channel group. |
| `channel_group` *Type: String | The channel group from which to remove the channels. |

### Sample code

#### Remove channels

```python
envelope = await pubnub.remove_channel_from_channel_group().\
    channels(["son", "daughter"]).\
    channel_group("channel_group").\
    future()
```

## Delete a channel group

:::note Requires Stream Controller add-on
This method requires that the *Stream Controller* 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.
:::

This function deletes a channel group.

### Method(s)

Use the following method in the Python-Asyncio SDK:

```python
pubnub.remove_channel_group() \
    .channel_group(String)
```

| Parameter | Description |
| --- | --- |
| `channel_group` *Type: String | The channel group to delete. |

### Sample code

#### Delete channel group

```python
envelope = await pubnub.remove_channel_group() \
    .channel_group("cg1").future()
```

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