Newbie: Proper database for the task?

Paul Mackinney paul at mackinney.net
Tue Dec 24 15:53:48 EST 2002


Hi, I'm writing a database to track a Maildir whose message filenames
are sequential integers padded to uniform length. The structure that
I've adopted is to a database whose keys are integers (corresponding to
the filenames) and whose values are dictionaries of a set of message
properties. For example,

db[234] = {'name':'Eric Idle','email':'parrot at itsonlysleeping.com'}

All of the database modules seem to use strings for keys and values, but
I don't want to call str() and eval() all the time. I want to use the
fact that my records are ordered to optimize searches & relative
lookups.

Bsddb's record number format supports integer keys, but only string
values. Shelve's BsdDBShelf module lets me store pickleable (non-string)
values, but doesn't work with a bsddb.rnopen() object and the other
bsddb formats use keys that are strings.

To keep my project moving I've written a db class that uses integer
keys, pickleable values, and has all of the dbm and bsddb methods, but
it really feels like a hack. Surely this problem has an existing
solution? (And yes, I've thought of using an SQL database. Users with
large datasets will need this but I'd like to have a solution in python
for small to moderate datasets.)

TIA, PM
-- 
Paul Mackinney
paul at mackinney.net




More information about the Python-list mailing list