PubNub LogoDocs
SupportContact SalesLoginTry Our APIs

›API Reference

python

  • Getting Started
  • API Reference

    • Configuration
    • Publish & Subscribe
    • Presence
    • Access Manager
    • Channel Groups
    • Message Persistence
    • Mobile Push
    • Objects
    • Files
    • Message Actions
    • Miscellaneous
  • Status Events
  • Troubleshooting
  • Change Log
  • Feature Support
  • Platform Support
  • Reconnection Policies

Channel Groups API for PubNub Python SDK

Python version support

Python SDK versions 5.0.0 and higher no longer support Python v2.7 and the Twisted and Tornado frameworks. If you require support for any of these, use SDK version 4.8.1.

Note that PubNub will stop supporting versions of Python lower than 3.7 by the end of 2021.

Channel Groups allows PubNub developers to bundle thousands of channels into a group that can be identified by name. These Channel Groups can then be subscribed to, receiving data from the many backend-channels the channel group contains.

Learn more about our Channel Groups here.

Adding Channels

Requires Stream Controller add-onRequires that the Stream Controller add-on is enabled for your key. See this page on enabling add-on features on your keys:
https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-

Description

This function adds a channel to a channel group.

Method(s)

Adding Channels is accomplished by using the following method(s) in the Python SDK:

Note

200 channels can be added to the channel group per API call.

pubnub.add_channel_to_channel_group().channels(String|List|Tuple).channel_group(String)
ParameterTypeRequiredDescription
channelsString | List | TupleYesThe channel to add to the channel_group.
channel_groupStringYesThe channel_group to add the channels to.

Basic Usage

Adding Channels :

pubnub.add_channel_to_channel_group().\
    channels(["ch1", "ch2"]).\
    channel_group("cg1").\
    sync()

Listing Channels

Requires Stream Controller add-onRequires that the Stream Controller add-on is enabled for your key. See this page on enabling add-on features on your keys:
https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-

Description

This function lists all the channels of the channel group.

Method(s)

Listing Channels is accomplished by using the following method(s) in the Python SDK:

pubnub.list_channels_in_channel_group().channel_group(String)
ParameterTypeRequiredDescription
channel_groupStringYesThe channel group to fetch channels.

Basic Usage

Listing Channels:

pubnub.list_channels_in_channel_group().\
    channel_group("cg1").sync()

Removing Channels

Requires Stream Controller add-onRequires that the Stream Controller add-on is enabled for your key. See this page on enabling add-on features on your keys:
https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-

Description

This function removes the channels from the channel group.

Method(s)

Removing Channels is accomplished by using the following method(s) in the Python SDK:

pubnub.remove_channel_from_channel_group().channels(String|List|Tuple).channel_group(String)
ParameterTypeRequiredDescription
channelsString | List | TupleYesThe channels to remove from the channel group.
channel_groupStringYesSpecifies channel_group to remove the channels from.

Basic Usage

Removing channels:

pubnub.remove_channel_from_channel_group().\
    channels(["son", "daughter"]).\
    channel_group("channel_group").\
    sync()

Deleting Channel Group

Requires Stream Controller add-onRequires that the Stream Controller add-on is enabled for your key. See this page on enabling add-on features on your keys:
https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-

Description

This function removes the channel group.

Method(s)

Deleting Channel Group is accomplished by using the following method(s) in the Python SDK:

pubnub.remove_channel_group().channel_group(String)
ParameterTypeRequiredDescription
channel_groupStringYesThe channel group to remove.

Basic Usage

Deleting Channel Group:

pubnub.remove_channel_group().\
    channel_group("cg1").sync()
← Access ManagerMessage Persistence →
  • Adding Channels
    • Description
    • Method(s)
    • Basic Usage
  • Listing Channels
    • Description
    • Method(s)
    • Basic Usage
  • Removing Channels
    • Description
    • Method(s)
    • Basic Usage
  • Deleting Channel Group
    • Description
    • Method(s)
    • Basic Usage
© PubNub Inc. - Privacy Policy