Created: 2012-03-24 20:56
Updated: 2018-03-14 08:01


The cube project is awesome for displaying aggregations of real-time data. I would like to create new "boards" with a really simple python call, and I want the boards to show the most interesting content in real time. An example could be trending tags/topics on a social network, and instead of just listing the tags it will display a graph of the tag's post frequency for the last minute/hour/day/whatever.

Connecting to cube

First you need to get cube up and running. Follow the instructions here. For a simple example running on your local machine, you'll need to install everything they suggest, then run these commands:

git clone
cd cube
npm install
mongod &
node bin/collector.js &
node bin/evaluator.js &

Installing pycube

I've had this up and working under python2.6 and 2.7.

The only dependency that I know of is pymongo, which is available through pip. The example also requires requests.

sudo pip install pymongo
sudo pip install requests
git clone
cd pycube
sudo python install

Creating a new type

Each mongodb collection is referred to as a type. A dashboard can have boards pulling data from multiple types, but I don't generally do that so we'll see how that plays out as this project makes progress. Once you launch the node and mongod processes, the actual code to get up and running is simple.

import pycube
cube = pycube.Cube()             # the collector is running on by default.
cube.initalize()                 # set up all of cube's internal collections (collectd, etc)

Logging actions

Now you want to fill it in with some data. Inserting a new record is easy:

action = {
    'time' :,
    'type' : 'actions',
    'data' : {
        'action_type' : 'follow',
        'action_source' : 'some_url',

The dict must have the keys 'type' (string) and 'data' (dict). The 'time' key is optional, and the current time stamp will be used if it is left out.


Check out the file. Loads the clickstream and puts the data into cube.

Then run the to launch cube with the trending info.

The demo uses some pretty sparse data, but the output will look something like this:

Viewing the graphs

The page will be hosted on http://localhost:1081/. See for example queries. More on this later.

Cookies help us deliver our services. By using our services, you agree to our use of cookies Learn more