Python bindings for Berkeley DB (pybsddb)

Off late, I have been using the pretty fast and robust Berkeley DB (BDB) (which is now owned by Oracle!) to store some data (in fact, for this project, its a LOT of data – around a couple of gigs per db file, and there’s a bunch of db files). I write most of my apps outside work in Python and needed to access BDB files.

There is built in support for BDB in any modern Python installation and its pretty easy to use. However, you won’t benefit from the latest additions unless you’re willing to wait for a new version of Python to be shipped out.

Well, there’s an alternative called pybsddb, and there is support for the latest BDB in the works. The installation is pretty simple:

  1. Install BDB runtime and development packages. I’m using Ubuntu, so, that’s pretty straight forward:
    sudo apt-get install libdb4.5 libdb4.5-dev
  2. Download the latest file from here. I downloaded bsddb3-4.6.3.
  3. Extract it out using:
    tar xvf bsddb3-4.6.3.tar.gz
  4. cd bsddb3-4.6.3
  5. Build pybsddb:
    python setup.py build
  6. Run the tests (optional):
    python test.py
  7. Install it:
    sudo python setup.py install

Simple as that. You should be able to create DBEnv() and DB() objects and start manipulating the BDB files!

Tags: ,

Leave a Reply