Utility Methods API for Python SDK
The methods on this page are utility methods that don't fit into other categories.
Disconnect
Call the disconnect()
method to force the SDK to stop all requests to PubNub server when there are active subscribe channels.
Method(s)
To disconnect()
the data transmission you can use the following method(s) in Python SDK.
disconnect()
This method doesn't take any arguments.
Sample code
Reference code
import os
from pubnub.pnconfiguration import PNConfiguration
from pubnub.pubnub import PubNub
def disconnect_from_pubnub(pubnub: PubNub):
pubnub._subscription_manager.disconnect()
print("Disconnected from PubNub.")
def main():
# Configuration for PubNub instance
pn_config = PNConfiguration()
pn_config.subscribe_key = os.getenv('PUBNUB_SUBSCRIBE_KEY', 'demo')
pn_config.user_id = os.getenv('PUBNUB_USER_ID', 'my_custom_user_id')
show all 25 linesReconnect
Call the reconnect()
method to force the SDK to try and reach out PubNub.
Method(s)
To reconnect()
the data transmission you can use the following method(s) in Python SDK.
pubnub.reconnect()
This method doesn't take any arguments.
Get subscribed channels
Returns all the subscribed channels in a list
.
Method(s)
To Get Subscribed Channels
you can use the following method(s) in the Python SDK:
pubnub.get_subscribed_channels()
Sample code
Get subscribed channels
channels = pubnub.get_subscribed_channels()
Returns
List
["my_ch1", "my_ch2"]
Get subscribed channel groups
Returns all the subscribed channel groups in a list
.
Method(s)
To Get Subscribe Channel Groups
you can use the following method(s) in the Python SDK:
pubnub.get_subscribed_channel_groups()
Sample code
Get subscribed channel groups
channels = pubnub.get_subscribed_channel_groups()
Returns
List
["my_group1", "my_group2"]