PythonNativeNativeTwistedTornadoAsyncioPython V4 Misc API Reference for Realtime Apps

 

These docs are for PubNub 4.0 for Python V4 which is our latest and greatest! For the docs of the older versions of the SDK, please check PubNub 3.0 for Python, PubNub 3.0 for Python-Tornado and PubNub 3.0 for Python-Twisted.

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

The methods on this page are utility methods that don't fit into other categories.
This function will return a 17 digit precision Unix epoch.
 
Timetoken
The timetoken is constructed using the following algorithm:
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
To fetch Time you can use the following method(s) in Python V4 SDK
envelope = pubnub.time()
The time() operation returns a PNTimeResponse which contains the following operations:
MethodTypeDescription
int
Int
Returns an int representation of current time token.
str
String
Returns a str representation of current time token.
date_time
Date
Returns a date representation of current time token.
 Do not confuse with timestamp() method, which is a shortcut to int(time.time())
Returns all the subscribed channels in a list.
To Get Subscribed Channels you can use the following method(s) in the Python V4 SDK:
  1. pubnub.get_subscribed_channels()
channels = pubnub.get_subscribed_channels()
List

["my_ch1", "my_ch2"]
Returns all the subscribed channel groups in a list.
To Get Subscribe Channel Groups you can use the following method(s) in the Python V4 SDK
  1. pubnub.get_subscribed_channel_groups()
channels = pubnub.get_subscribed_channel_groups()
List

["my_group1", "my_group2"]
This function allows to encrypt the data.
To encrypt the data you can use the following method(s) in Python V4 SDK.
  1. ParameterTypeRequiredDescription
    filebytesYesThe file to encrypt.
    cipher_keyStringOptionalCipher key used for encryption. If it's not provided, the cipher key from config is used.
payload_to_encrypt = b'knights_who_say_ni'

encrypted_payload = pubnub.encrypt("test_cipher_key", payload_to_encrypt)
Bytes object with encrypted data.
This function allows to decrypt the data.
To decrypt the data you can use the following method(s) in Python V4 SDK.
  1. ParameterTypeRequiredDescription
    filebytesYesThe file to decrypt.
    cipher_keyStringOptionalCipher key used for encryption. If it's not provided, the cipher key from config is used.
decrypted_payload = pubnub.decrypt(cipher_key, payload_to_decrypt_in_bytes)
Bytes object with decrypted data.