SelectPython-Tornado Channel Groups API Reference for Realtime Apps

These docs are for version 3.9.0 of the Python-Tornado SDK. To check out the docs for the latest version Click Here.
 

PubNub 4.0 for Python-Tornado is our latest and greatest! Please click here for our PubNub 4.0 for Python docs and SDK.

PubNub 3.x for Python-Tornado will encounter End Of Life (EOL) July 1st, 2017. All users currently on 3.x should begin migrating to 4.x. The 3.x SDK will continue to work. We will no longer support it and if you run into an issue, we will request that you upgrade to the latest version before solving the issue.

If you have questions about the PubNub for Python SDK, please contact us at support@pubnub.com.

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


Requires Stream Controller add-on XRequires 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-.
This function adds a channel to a channel group.
Adding Channels is accomplished by using the following method(s) in the Python SDK:
  1. ParameterTypeRequiredDescription
    channelStringYesThe channel to add to the channel group.
    channel_groupStringOptionalThe channelGroup to add the channels to.
    callbackFunctionOptionalA callback method can be passed to the method. If set, the api works in async mode. Required argument when working with twisted or tornado
    errorFunctionOptionalAn error method can be passed to the method. If set, the api works in async mode. Required argument when working with twisted or tornado
channelGroup = 'family'
# Sync Example
print(pubnub.channel_group_add_channel(channel_group=channelGroup, channel='wife')
 
# Async Example
 
def _callback(message):
    print(message)
 
def _error(error):
    print(error)
 
pubnub.channel_group_add_channel(channel_group=channelGroup, channel='wife',  callback=_callback, error=_error)
{
    "service" : "channel-registry",
    "status"  : 200,
    "error"   : false,
    "message" : "OK"
}

Requires Stream Controller add-on XRequires 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-.
This function lists all the channels of the channel group.
Listing Channels is accomplished by using the following method(s) in the Python SDK:
  1. ParameterTypeRequiredDescription
    channel_groupStringYesChannel Group name.
    callbackFunctionOptionalCallback object which contains callbacks for success, error etc. Required argument when working with twisted or tornado.
    errorFunctionOptionalOptional variable. An error method can be passed to the method. If set, the api works in async mode. Required argument when working with twisted or tornado.
channelGroup = 'family'
# Sync Example
print(pubnub.channel_group_list_channels(channel_group='channel_group')
 
# Async Example
 
def _callback(message):
    print(message)
 
def _error(error):
    print(error)
 
pubnub.channel_group_list_channels(channel_group='channelGroup',  callback=_callback, error=_error)
 

{
	"status" : 200,
	"payload" : {
		"channels" : ["hi"], 
		"group" : "abcd"
	},
	"service" : "channel-registry",
	"error" : False
}

Requires Stream Controller add-on XRequires 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-.
This function removes the channels from the channel group.
Removing Channels is accomplished by using the following method(s) in the Python SDK:
  1. ParameterTypeRequiredDescription
    channel_groupStringYesChannel Group name.
    channelStringYesCan be a channel name, a list of channel names, or a comma separated list of channel names.
    callbackFunctionOptionalCallback object which contains callbacks for success, error etc. Required argument when working with twisted or tornado.
    errorFunctionOptionalOptional variable. An error method can be passed to the method. If set, the api works in async mode. Required argument when working with twisted or tornado.
Removing channels :
channelGroup = 'family'
# Sync Example
print(pubnub.channel_group_remove_channel(channel_group='channelGroup', channel='son')
 
# Async Example
 
def _callback(message):
    print(message)
 
def _error(error):
    print(error)
 
pubnub.channel_group_remove_channel(channel_group=channelGroup, channel='son', callback=_callback, error=_error)
 

{
	"status" : 200,
	"message" : "OK",
	"service" : "channel-registry",
	"error" : False
}

Requires Stream Controller add-on XRequires 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-.
This function removes the channel group.
Deleting Channel Group is accomplished by using the following method(s) in the Python SDK:
  1. ParameterTypeRequiredDescription
    channel_groupStringYesChannel Group name.
    callbackFunctionOptionalCallback object which contains callbacks for success, error etc. Required argument when working with twisted or tornado.
    errorFunctionOptionalOptional variable. An error method can be passed to the method. If set, the api works in async mode. Required argument when working with twisted or tornado.
Deleting Channel Group :
channelGroup = 'family'
# Sync Example
print(pubnub.channel_group_remove_group(channel_group=channelGroup)
 
# Async Example
 
def _callback(message):
    print(message)
 
def _error(error):
    print(error)
 
pubnub.channel_group_remove_group(channel_group=channelGroup',  callback=_callback, error=_error)

{
	"status" : 200,
	"message" : "OK",
	"service" : "channel-registry",
	"error" : False
}