diff options
| author | Devendra | 2014-06-18 01:02:15 +0530 |
|---|---|---|
| committer | Devendra | 2014-06-18 01:02:15 +0530 |
| commit | a1ee7f8bd90b463318bfa75f7ee4f58d458d2a24 (patch) | |
| tree | 9e260902f960f792a93fa25e3b619c42ecb5f4d4 /python/README.md | |
| parent | bfd5c64bdf7ed45f21207cb53c653e7220e39eff (diff) | |
| parent | 083127cde127dd78fc88ffe2b3b82144b2c07038 (diff) | |
| download | pubnub-python-a1ee7f8bd90b463318bfa75f7ee4f58d458d2a24.tar.bz2 | |
Merge branch 'master' into develop
Diffstat (limited to 'python/README.md')
| -rw-r--r-- | python/README.md | 136 |
1 files changed, 83 insertions, 53 deletions
diff --git a/python/README.md b/python/README.md index 68065f0..c077918 100644 --- a/python/README.md +++ b/python/README.md @@ -1,60 +1,93 @@ -## PubNub 3.3 Web Data Push Cloud-hosted API - PYTHON -#### www.pubnub.com - PubNub Web Data Push Service in the Cloud. -#### http://github.com/pubnub/python +## Contact support@pubnub.com for all questions +#### [PubNub](http://www.pubnub.com) Real-time Data Network +##### Standalone Python Client #### Init ``` -pubnub = Pubnub( - "demo", ## PUBLISH_KEY - "demo", ## SUBSCRIBE_KEY - None, ## SECRET_KEY - False ## SSL_ON? -) +pubnub = Pubnub(publish_key="demo", subscribe_key="demo", ssl_on=False) + ``` #### PUBLISH ``` -info = pubnub.publish({ - 'channel' : 'hello_world', - 'message' : { - 'some_text' : 'Hello my World' - } -}) -print(info) +channel = 'hello_world' +message = 'Hello World !!!' + +# Synchronous usage +print pubnub.publish(channel='hello_world', message='Hello World !!!') + +# Asynchronous usage + +def callback(message): + print(message) + +pubnub.publish(channel, message, callback=callback, error=callback) + ``` #### SUBSCRIBE ``` -# Listen for Messages *BLOCKING* -def receive(message) : +# Listen for Messages + +channel = 'hello_world' + +def callback(message, channel): print(message) - return True -pubnub.subscribe({ - 'channel' : 'hello_world', - 'callback' : receive -}) + +def error(message): + print("ERROR : " + str(message)) + + +def connect(message): + print("CONNECTED") + + +def reconnect(message): + print("RECONNECTED") + + +def disconnect(message): + print("DISCONNECTED") + + +pubnub.subscribe(channel, callback=callback, error=callback, + connect=connect, reconnect=reconnect, disconnect=disconnect) +``` + +#### UNSUBSCRIBE + +``` +# Listen for Messages + +channel = 'hello_world' + +pubnub.unsubscribe(channel=channel) ``` #### PRESENCE ``` -# Listen for Presence Event Messages *BLOCKING* +# Listen for Presence Event Messages + +channel = 'hello_world' -def pres_event(message) : +def callback(message, channel): print(message) - return True -pubnub.presence({ - 'channel' : 'hello_world', - 'callback' : receive -}) + +def error(message): + print("ERROR : " + str(message)) + + + +pubnub.presence(channel, callback=callback, error=callback) ``` #### HERE_NOW @@ -62,36 +95,33 @@ pubnub.presence({ ``` # Get info on who is here right now! -here_now = pubnub.here_now({ - 'channel' : 'hello_world', -}) +channel = 'hello_world' -print(here_now['occupancy']) -print(here_now['uuids']) -``` +# Synchronous usage +print pubnub.here_now(channel) -#### Channel Analytics -``` -analytics = pubnub.analytics({ - 'channel' : 'channel-name-here', ## Leave blank for all channels - 'limit' : 100, ## aggregation range - 'ago' : 0, ## minutes ago to look backward - 'duration' : 100 ## minutes offset -}) -print(analytics) +# Asynchronous usage + +def callback(message): + print(message) +pubnub.here_now(channel, callback=callback, error=callback) ``` #### HISTORY ``` -# Load Previously Published Messages -history = pubnub.detailedHistory({ - 'channel' : 'my_channel', - 'end' : my_end_time_token, # Optional - 'start' : my_start_time_token, # Optional - 'count' : num_of_msgs_to_return # Optional, default is 100 -}) -print(history) +# Synchronous usage + +print pubnub.history(channel, count=2) + +# Asynchronous usage + + +def callback(message): + print(message) + +pubnub.history(channel, count=2, callback=callback, error=callback) ``` +## Contact support@pubnub.com for all questions |
