Riak Docs

This is a little module to save me time by modeling Riak docs and then providing common operations.

It is nowhere near complete and is probably unsuitable for whatever you want to do. Do NOT use this in production unless you know what you're doing and by that I mean: you're me.

Example Usage

from riakdoc.documents import BaseDocument
from riakdoc.indexes import StrFieldsIndex
from blinker import signal

class MyDoc(BaseDocument):
    Create a Riak document that:
        1. Automatically creates a 2i index called "complex_index" which holds an id and category as {id}_{cat}
        2. Initializes data if created without data.
    complex_index = StrFieldsIndex(['id', 'person.category'])

    def initialize_data(self, *args, **kwargs):
        # Extra args/kwargs are passed to the initialize_data call, making it easy to pass data to help init docs.
        return {'id': self.key, 'violations': [], 'tag': kwargs.get('tag', '')}

# Listen for the post save event, but only from MyDoc, and then print.
def announce(sender, **kwargs):
    print "just saved: {0}".format(kwargs.pop('document').data)
signal('post-document save').connect(announce, sender=MyDoc)

doc = MyDoc('abc1', tag='noodle')
# Doc can be accessed like a dict since initialize_data(), above, returns a dict.
doc['person'] = {'category': 'engineer'}
print doc.complex_index                        # prints "abc1_engineer"                                     # stores to Riak, prints "just saved: {'id': 'abc1', 'tag': 'noodle', 'person': ..."