A while ago I wrote a little post about alternative column stores. One that I mentioned was Tokyo Cabinet (and its associated server Tokyo Tyrant. Tokyo Cabinet it is a key-value store written in C and with bindings for multiple languages (including Python and Java). It can maintain data bases in memory or spin them to disk (you can pick between hash or B-tree based stores).
Having heard a bunch of good things, I finally gave it a try. I just installed both Cabinet and Tyrant (you may find useful installation instructions here using the usual configure, make, make install cycle). Another nice feature of Tyrant is that it also supports HTTP gets and puts. So having all this said, I just wanted to check how easy it was to use it from Python. And the answer was very simple. Joseph Turian’s examples got me running in less than 2 minutes—see the piece of code below—when dealing with a particular data base. Using Tyrant over HTTP is quite simple too—see PeteSearch blog post.
import pytc,pickle from numpy import * hdb = pytc.HDB() hdb.open('casket.tch',pytc.HDBOWRITER|pytc.HDBOCREAT) a = arange(100) hdb.put('test',pickle.dumps(a)) b = pickle.loads(hdb.get('test')) if (a==b).all() : print 'OK' hdb.close()
Related posts: