Channel Groups API for Python-Asyncio SDK
Channel groups allow PubNub developers to bundle thousands of channels 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.
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
Requires Stream Controller add-on
This method requires that the Stream Controller add-on is enabled for your key in the PubNub Admin Portal. See Enable the features your app calls.
This function adds channels to a channel group.
Method(s)
Use the following method in the Python-Asyncio SDK:
Maximum number of channels
You can add up to 200 channels to a channel group per API call.
1pubnub.add_channel_to_channel_group() \
2 .channels(String|List|Tuple) \
3 .channel_group(String)
Sample code
Add channels
1import asyncio
2import os
3from pubnub.pnconfiguration import PNConfiguration
4from pubnub.pubnub_asyncio import PubNubAsyncio
5from pubnub.exceptions import PubNubException
6
7
8async def add_channels_to_group(pubnub: PubNubAsyncio):
9 try:
10 # Add Channels to a Channel Group
11 envelope = await pubnub.add_channel_to_channel_group() \
12 .channels(["ch1", "ch2"]) \
13 .channel_group("cg1") \
14 .future()
15
show all 40 linesList channels in a channel group
Requires Stream Controller add-on
This method requires that the Stream Controller add-on is enabled for your key in the Admin Portal. See Enable the features your app calls.
This function lists all channels in a channel group.
Method(s)
Use the following method in the Python-Asyncio SDK:
1pubnub.list_channels_in_channel_group() \
2 .channel_group(String)
channel_grouprequired#- The channel group for which to list channels.
Sample code
List channels
1envelope = pubnub.list_channels_in_channel_group().\
2 channel_group("cg1").future()
Remove channels from a channel group
Requires Stream Controller add-on
This method requires that the Stream Controller add-on is enabled for your key in the Admin Portal. See Enable the features your app calls.
This function removes channels from a channel group.
Method(s)
Use the following method in the Python-Asyncio SDK:
1pubnub.remove_channel_from_channel_group() \
2 .channels(String|List|Tuple) \
3 .channel_group(String)
Sample code
Remove channels
1envelope = await pubnub.remove_channel_from_channel_group().\
2 channels(["son", "daughter"]).\
3 channel_group("channel_group").\
4 future()
Delete a channel group
Requires Stream Controller add-on
This method requires that the Stream Controller add-on is enabled for your key in the Admin Portal. See Enable the features your app calls.
This function deletes a channel group.
Method(s)
Use the following method in the Python-Asyncio SDK:
1pubnub.remove_channel_group() \
2 .channel_group(String)
channel_grouprequired#- The channel group to delete.
Sample code
Delete channel group
1envelope = await pubnub.remove_channel_group() \
2 .channel_group("cg1").future()