# 8.5 `dbm` -- Simple ``database'' interface

Availability: Unix.

The `dbm` module provides an interface to the Unix `(n)dbm` library. Dbm objects behave like mappings (dictionaries), except that keys and values are always strings. Printing a dbm object doesn't print the keys and values, and the `items()` and `values()` methods are not supported.

See also the `gdbm` module, which provides a similar interface using the GNU GDBM library.

The module defines the following constant and functions:

`error`
  Raised on dbm-specific errors, such as I/O errors. `KeyError` is raised for general mapping errors like specifying an incorrect key.

`open` (filename, [flag, [mode]])
  Open a dbm database and return a dbm object. The filename argument is the name of the database file (without the "`.dir`" or "`.pag`" extensions).

  The optional flag argument can be `'r'` (to open an existing database for reading only -- default), `'w'` (to open an existing database for reading and writing), `'c'` (which creates the database if it doesn't exist), or `'n'` (which always creates a new empty database).

  The optional mode argument is the Unix mode of the file, used only when the database has to be created. It defaults to octal `0666`.

See Also:

Module `anydbm` (Generic interface to `dbm`-style databases.)

Module `whichdb` (Utility module used to determine the type of an existing database.)