Install LevelDB and the python bindings py-leveldb on ubuntu

As Wouter pointed out in the comments, the following notes on the installation process are outdated. Have a look at the great plyvel library for an up to date python interface to leveldb.

Google has open sourced LevelDB, a fast and lightweight key/value store. Chromium/Chrome uses LevelDB to power its IndexedD and there are bindings for Riak and Kyoto Tycoon (see Gabors Response on The LevelDB Benchmark shows some impressive numbers compared against SQLite and Kyoto TreeDB.

Here are my installation notes on how to get LevelDB and the python bindings working on a fresh Ubuntu 11.04 installation.

Install development environment and get the LevelDB and py-leveldb source.

~$ sudo aptitude install build-essential python-dev
~$ mkdir ~/svn
~$ cd ~/svn
~/svn$ svn checkout py-leveldb-read-only
~/svn$ cd py-leveldb-read-only

After checking out the source I had to build leveldb by hand and than run the normal python install

~/svn/py-leveldb-read-only$ cd leveldb-read-only
~/svn/py-leveldb-read-only/leveldb-read-only$ make
~/svn/py-leveldb-read-only/leveldb-read-only$ cd ..
~/svn/py-leveldb-read-only$ sudo python install

Now you can fire up ipython and play around with the python api:

In [1]: import leveldb

In [2]: db = leveldb.LevelDB('/tmp/testdb')

In [3]: db.Put('some key', 'some val')

In [4]: db.Put('another key', 'another val')

In [5]: db.Get('some key')
Out[5]: 'some val'

In [6]: for a in db.RangeIter():
   ...:     print a
('another key', 'another val')
('some key', 'some val')

I'm going to do some micro benchmarks with the python bindings soon and add a UserDict based wrapper to the api. Until then there are some worth reading commments on the implementation and datastructures on news.ycombinator.