DBM-Style Databases

Python provides a number of DBM-style database interfaces

  • Key-based databases that store arbitrary strings.
  • Similar to shelve, but can't store arbitrary objects (strings only)
  • Examples: dbm, gdbm, bsddb

Example:

     import dbm
     d = dbm.open("database","r")
     d["foo"] = "bar"        # Store a value
     s = d["spam"]           # Retrieve a value
     del d["name"]           # Delete a value
     d.close()               # Close the database

Comments

  • The availability of DBM modules depends on optional libraries and may vary.
  • Don't use these if you should really be using a relational database (e.g., MySQL).
<<< O'Reilly OSCON 2000, Advanced Python Programming, Slide 49
July 17, 2000, beazley@cs.uchicago.edu
>>>