Skip to main content

Client library for juggernaut.

Project description

Dead simple Python library that connects to a juggernaut via redis. It also provides a very basic roster implementation that can be used as a daemon process to manage online users.

Basic usage

How to send a message to all subscribers of a channel:

from juggernaut import Juggernaut
jug = Juggernaut()
jug.publish('channel', {'message': 'Hello World!'})

Connection Events

Juggernaut also allows you to subscribe to events (new subscription, unsubscribe event) so that you can respond to users going online and offline:

from juggernaut import Juggernaut
jug = Juggernaut()
for event, data in jug.subscribe_listen():
    if event == 'subscribe':
        ...
    elif event == 'unsubscribe':
        ...

Since this is quite common this library also implements a Roster that can group multiple connections to the same user. For grouping this it uses a key in the meta part of the message. The default is user_id in the meta object.

Example usage:

from juggernaut import Juggernaut, Roster
jug = Juggernaut()
roster = Roster(jug)
roster.run()

By default it keeps the number of online users in redis so that you can use the roster class to see if users are online:

>>> roster.get_online_users()
[42, 23]
>>> roster.is_user_online(42)
True
>>> roster.is_user_online(99)
False

If you want to respond to users signing in and out you need to override the on_signed_in and on_signed_out methods:

class MyRoster(Roster):
    def on_signed_in(self, user_id):
        print 'User signed in', user_id
    def on_signed_out(self, user_id):
        print 'User signed out', user_id

You can for instance use juggernaut to broadcast that to other users that signed in.

copyright:
  1. 2011 by Armin Ronacher.

license:

BSD, see LICENSE for more details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

juggernaut-0.1.tar.gz (3.7 kB view details)

Uploaded Source

File details

Details for the file juggernaut-0.1.tar.gz.

File metadata

  • Download URL: juggernaut-0.1.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for juggernaut-0.1.tar.gz
Algorithm Hash digest
SHA256 46cf0c9e9c223fd9509100502c90b364138dce21ccd516b7d9e21da1275ef47c
MD5 008f3436df859d039743643c2463ab4a
BLAKE2b-256 61305484f545d56fee559cf74460cdf30cfda019114a85bad1e05c4caf3b35c2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page