Thursday, January 13, 2011

Python Database !

Link : http://code.activestate.com/recipes/496770-pydblite-a-small-in-memory-database-engine/

Recipe 496770: PyDbLite, a small in-memory database engine (Python) by Pierre Quentel
ActiveState Code (http://code.activestate.com/recipes/496770/)


A small, fast, in-memory database management program

The database object supports the iterator protocol, so that requests can be expressed with list comprehensions or generator expressions instead of SQL. The equivalent of : cursor.execute("SELECT name FROM table WHERE age=30")
rows = cursor.fetchall()



is : rows = [ row["name"] for row in table if row["age"] == 30 ]



The module stores data in a cPickled file. Records are indexed by a unique record identifier, that can be used for direct access. Since operations are processed in memory they are extremely fast, nearly as fast as SQLite in the few tests I made, and MUCH faster than other pure-Python modules such as Gadfly or KirbyBase. An index can be created on a field to speed up selections

Concurrency control is supported by a version number set for each record

Complete documentation is here




Despite its ridiculously small footprint, this module can be a good alternative when other database management systems would be overkill (say up to 5 Mbytes of data), and Python programmers should find the syntax very intuitive