Added section on passing contextual information to logging and documentation for...
[python.git] / Doc / library / dbm.rst
blob52923e826de1927b4144203b6fb90c7b3989b765
2 :mod:`dbm` --- Simple "database" interface
3 ==========================================
5 .. module:: dbm
6    :platform: Unix
7    :synopsis: The standard "database" interface, based on ndbm.
10 The :mod:`dbm` module provides an interface to the Unix "(n)dbm" library.  Dbm
11 objects behave like mappings (dictionaries), except that keys and values are
12 always strings. Printing a dbm object doesn't print the keys and values, and the
13 :meth:`items` and :meth:`values` methods are not supported.
15 This module can be used with the "classic" ndbm interface, the BSD DB
16 compatibility interface, or the GNU GDBM compatibility interface. On Unix, the
17 :program:`configure` script will attempt to locate the appropriate header file
18 to simplify building this module.
20 The module defines the following:
23 .. exception:: error
25    Raised on dbm-specific errors, such as I/O errors. :exc:`KeyError` is raised for
26    general mapping errors like specifying an incorrect key.
29 .. data:: library
31    Name of the ``ndbm`` implementation library used.
34 .. function:: open(filename[, flag[, mode]])
36    Open a dbm database and return a dbm object.  The *filename* argument is the
37    name of the database file (without the :file:`.dir` or :file:`.pag` extensions;
38    note that the BSD DB implementation of the interface will append the extension
39    :file:`.db` and only create one file).
41    The optional *flag* argument must be one of these values:
43    +---------+-------------------------------------------+
44    | Value   | Meaning                                   |
45    +=========+===========================================+
46    | ``'r'`` | Open existing database for reading only   |
47    |         | (default)                                 |
48    +---------+-------------------------------------------+
49    | ``'w'`` | Open existing database for reading and    |
50    |         | writing                                   |
51    +---------+-------------------------------------------+
52    | ``'c'`` | Open database for reading and writing,    |
53    |         | creating it if it doesn't exist           |
54    +---------+-------------------------------------------+
55    | ``'n'`` | Always create a new, empty database, open |
56    |         | for reading and writing                   |
57    +---------+-------------------------------------------+
59    The optional *mode* argument is the Unix mode of the file, used only when the
60    database has to be created.  It defaults to octal ``0666`` (and will be
61    modified by the prevailing umask).
64 .. seealso::
66    Module :mod:`anydbm`
67       Generic interface to ``dbm``\ -style databases.
69    Module :mod:`gdbm`
70       Similar interface to the GNU GDBM library.
72    Module :mod:`whichdb`
73       Utility module used to determine the type of an existing database.