Tambur.io aims to provide a pain-free websocket experience. You can publish messages to your subscribers via a REST-API by giving a stream name. All the clients subscribed to the stream will get your message. Your role in the following notes is that of a Publisher.
Install this library preferably using pip:
pip install git+git://github.com/tamburio/python-tambur.git
Please register on Tambur.io and create at least one app. This will give you the unique API_KEY, an APP_ID and a SECRET, which you need to initialize the publisher.
from tambur import Tambur tambur = Tambur(api_key=API_KEY app_id=APP_ID, secret=SECRET) tambur.publish('mystream', 'some message')
The example above publishes the given message to all subscribed clients. Clients can set different modes for streams they're subscribed to. Currently Tambur supports an 'auth', a 'presence', and a 'direct' mode. You'll have to grant permission by issuing a specific mode token. To generate a token you typically need the StreamName, the SubscriberId, and for direct- and presence-modes the UserId. The SubscriberId is the only parameter your clients must send you e.g. through some AJAX request which you can answer with the generated mode token.
If you issue an auth mode token, the client can authenticate himself for a particular stream. If you use the
auth: stream prefix you can control how we deliver your message.
tambur.publish('auth:mystream', 'some auth message')
The example above publishes the given message to all subscribed clients that have the auth mode enabled. Issuing an auth mode token is straight forward:
If you issue a presence mode token, the client can switch on and off presence mode. If presence mode is switched on the client will receive join- and leave-events of all the other presence clients in that particular stream. Issuing a presence mode token needs an extra 'User-Id' parameter, which enables you to connect a tambur.io subscriber-id to a User-Id used in your application:
tambur.generate_presence_token('mystream', 'Alice', subscriber_id)
If you issue a direct mode token, the client can switch on and off direct mode. If direct mode is switched on the client can send and receive messages from other clients in that particular stream. Issuing a direct mode token needs an extra 'User-Id' parameter, which enables you to connect a tambur.io subscriber-id to a User-Id used in your application:
tambur.generate_direct_token('mystream', 'Alice', subscriber_id)
If you want to further limit your receivers to one specific subscriber you can do this using the 'private' stream.
tambur.publish('private:' + subscriber_id, 'some private message')
Copyright (c) <2012> <Tambur.io>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.