SelectPython-Tornado Presence API Reference for Realtime Apps

These docs are for version 3.9.0 of the Python-Tornado SDK. To check out the docs for the latest version Click Here.
 

PubNub 4.0 for Python-Tornado is our latest and greatest! Please click here for our PubNub 4.0 for Python docs and SDK.

PubNub 3.x for Python-Tornado will encounter End Of Life (EOL) July 1st, 2017. All users currently on 3.x should begin migrating to 4.x. The 3.x SDK will continue to work. We will no longer support it and if you run into an issue, we will request that you upgrade to the latest version before solving the issue.

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

Presence enables you to track the online and offline status of users and devices in realtime, as well as store custom state information. Presence provides authoritative information on:

  • When a user has joined or left a channel
  • Who, and how many, users are subscribed to a particular channel
  • Which channel(s) an individual user is subscribed to
  • Associated state information for these users

Learn more about our Presence feature here.


Requires Presence add-on XRequires that the Presence add-on is enabled for your key. See this page on enabling add-on features on your keys:

http://www.pubnub.com/knowledge-base/discussion/644/how-do-i-enable-add-on-features-for-my-keys.
You can obtain information about the current state of a channel including a list of unique user-ids currently subscribed to the channel and the total occupancy count of the channel by calling the here_now function in your application.
To call Here Now you can use the following method(s) in the Python SDK:
  1. ParameterTypeRequiredDescription
    channelStringOptionalSpecifies the channel name to return occupancy results. If channel is not provided, here_now will return data for all channels.
    channel_groupStringOptionalSpecifies the channel group name to return occupancy results. If both channel and channel group are not provided, here_now will return data for all channels.
    callbackFunctionOptionalA callback method should be passed to the method. If set, the api works in async mode. Required argument when working with twisted or tornado.
    errorFunctionOptionalOptional variable. An error method can be passed to the method. If set, the api works in async mode. Required argument when working with twisted or tornado.
 def _callback(message, channel):
   print(message)
 
 def _error(message):
     print(message)
 
 pubnub.here_now(channel="my_channel", callback=_callback, error=_error)
The here_now function returns a list of uuid s currently subscribed to the channel.
  • uuids:["String","String", ... ,"String"] - List of UUIDs currently subscribed to the channel.
  • occupancy: Number - Total current occupancy of the channel.

{
	occupancy : 4,
	uuids : ['123123234t234f34fq3dq', '143r34f34t34fq34q34q3', '23f34d3f4rq34r34rq23q', 'w34tcw45t45tcw435tww3']
}