whichdb – Identify DBM-style database formats

Purpose:Examine existing DBM-style database file to determine what library should be used to open it.
Available In:1.4 and later

The whichdb module contains one function, whichdb(). It can be used to examine an existing database file to determine which dbm library should be used to open it. It returns None if there is a problem opening the file, or the string name of the module to use to open the file. If it can open the file but cannot determine the library to use, it returns the empty string.

import anydbm
import whichdb

db = anydbm.open('/tmp/example.db', 'n')
db['key'] = 'value'
db.close()

print whichdb.whichdb('/tmp/example.db')

Your results will vary, depending on what modules are available in your PYTHONPATH.

$ python whichdb_whichdb.py

dbhash

See also

whichdb
Standard library documentation for this module.
anydbm
The anydbm module uses the best available DBM implementation when creating new databases.
shelve
The shelve module provides a mapping-style API for DBM databases.