---
source_url: https://www.pubnub.com/docs/sdks/python/api-reference/misc
title: Utility Methods API for Python SDK
updated_at: 2026-06-19T11:38:22.246Z
sdk_name: PubNub Python SDK
sdk_version: 10.7.1
---

> Documentation Index
> For a curated overview of PubNub documentation, see: https://www.pubnub.com/docs/llms.txt
> For the full list of all documentation pages, see: https://www.pubnub.com/docs/llms-full.txt


# Utility Methods API for Python SDK

PubNub Python SDK, use the latest version: 10.7.1

Install:

```bash
pip install pubnub@10.7.1
```

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.

```python
disconnect()
```

This method doesn't take any arguments.

### Sample code

:::tip 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.
:::

```python
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')

    # Initialize PubNub client
    pubnub = PubNub(pn_config)

    # Disconnect from PubNub
    disconnect_from_pubnub(pubnub)

if __name__ == "__main__":
    main()
```

## 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.

```python
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

```python
channels = pubnub.get_subscribed_channels()
```

### Returns

`List`

```python
["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

```python
channels = pubnub.get_subscribed_channel_groups()
```

### Returns

`List`

```python
["my_group1", "my_group2"]
```