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.

1disconnect()

This method doesn't take any arguments.

Sample code​

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.
1import os
2from pubnub.pnconfiguration import PNConfiguration
3from pubnub.pubnub import PubNub
4
5
6def disconnect_from_pubnub(pubnub: PubNub):
7 pubnub._subscription_manager.disconnect()
8 print("Disconnected from PubNub.")
9
10
11def main():
12 # Configuration for PubNub instance
13 pn_config = PNConfiguration()
14 pn_config.subscribe_key = os.getenv('PUBNUB_SUBSCRIBE_KEY', 'demo')
15 pn_config.user_id = os.getenv('PUBNUB_USER_ID', 'my_custom_user_id')
show all 25 lines

Reconnect​

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.

1pubnub.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​

1channels = pubnub.get_subscribed_channels()

Returns​

List

1["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​

1channels = pubnub.get_subscribed_channel_groups()

Returns​

List

1["my_group1", "my_group2"]

Was this page useful?

Last updated on