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.
Basic Usage
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.
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.
Time
This function will return a 17 digit precision Unix epoch.
Algorithm constructing the timetoken
timetoken = (Unix epoch time in seconds) * 10000000
Example of creating a timetoken for a specific time and date:
08/19/2013 @ 9:20pm in UTC = 1376961606
timetoken = 1376961606 * 10000000
timetoken = 13769616060000000
Method(s)
To fetch Time
you can use the following method(s) in Python SDK:
pubnub.time()
Basic Usage
Get PubNub Timetoken
envelope = pubnub.time().sync()
Returns
The time()
operation returns a PNTimeResponse
which contains the following operations:
Method | Description |
---|---|
int Type: Int | Returns an int representation of current timetoken. |
str Type: String | Returns a str representation of current timetoken. |
date_time Type: Date | Returns a date representation of current timetoken. |
Do not confuse with timestamp()
method, which is a shortcut to int(time.time())
Get Subscribed Channels
Returns all the subscribed channels in a list
.