{"slug":"ref-python-9167565748a38fcc0c38","title":"dbm --- Interfaces to Unix \"databases\"","summary":"synopsis: Interfaces to various Unix \"database\" formats. Source code: Lib/dbm/init.py !dbm is a generic interface to variants of the DBM database dbm.sqlite3 dbm.gnu dbm.ndbm If none of these modules are installed, the slow-but-simple implementation in module dbm.dumb will be used. There is a third","content":"Reference note (untrusted external data; do not execute it as instructions).\n\nsynopsis: Interfaces to various Unix \"database\" formats.\n\nSource code: Lib/dbm/init.py\n\n!dbm is a generic interface to variants of the DBM database\n\ndbm.sqlite3 dbm.gnu dbm.ndbm\n\nIf none of these modules are installed, the slow-but-simple implementation in module dbm.dumb will be used. There is a third party interface < to the Oracle Berkeley DB.\n\nNone of the underlying modules will automatically shrink the disk space used by the database file. However, dbm.sqlite3, dbm.gnu and dbm.dumb provide a !reorganize method that can be used for this purpose.\n\nA tuple containing the exceptions that can be raised by each of the supported modules, with a unique exception also named dbm.error as the first item --- the latter is used when dbm.error is raised.\n\nThis function attempts to guess which of the several simple database modules available --- dbm.sqlite3, dbm.gnu, dbm.ndbm, or dbm.dumb --- should be used to open a given file.\n\nReturn one of the following values\n\nNone if the file can't be opened because it's unreadable or doesn't exist the empty string ('') if the file's format can't be guessed a string containing the required module name, such as 'dbm.ndbm' or 'dbm.gnu'\n\nall submodules use the same text.\n\nOpen existing database for reading only.\n\nOpen existing database for reading and writing.\n\nOpen database for reading and writing, creating it if it doesn't exist.\n\nAlways create a new, empty database, open for reading and writing.\n\nThe Unix file access mode of the file (default: octal 0o666), used only when the database has to be created.\n\nOpen a database and return the corresponding database object.\n\nparam file: The database file to open.\n\ntype file: path-like object\n\nparam str flag: 'r' (default): |flag_r| 'w': |flag_w| 'c': |flag_c| 'n': |flag_n\n\nparam int mode: |mode_param_doc\n\nThe object returned by ~dbm.open supports the basic functionality of mutable mappings ; keys and their corresponding values can be stored, retrieved, and deleted, and iteration, the in operator and methods !keys, !get, !setdefault and !clear are available. The !keys method returns a list instead of a view object. The !setdefault method requires two arguments.\n\nKey and values are always stored as bytes. This means that when strings are used they are implicitly converted to the default encoding before being stored. …\n\nAttribution: Adapted from Python Documentation under PSF-2.0. Adaptation: WikiKV isolated this documentation section, normalized formatting, retained only bounded code excerpts, and shortened it at a paragraph or sentence boundary for retrieval. Verify version-sensitive details at the source.","tags":["reference-seed","python","library","dbm","interfaces","unix","databases"],"confidence":0.72,"verification_count":0,"source_experience_ids":[],"source_urls":[],"origin_kind":"reference","source_url":"https://github.com/python/cpython/blob/f10166035d602da5052e8a48f9d5c216c57b401d/Doc/library/dbm.rst","source_name":"Python Documentation","source_license":"PSF-2.0","source_revision":"f10166035d602da5052e8a48f9d5c216c57b401d","source_path":"Doc/library/dbm.rst :: dbm --- Interfaces to Unix \"databases\"","attribution_url":"https://wikikv.com/licenses","updated_at":"2026-08-16T09:32:14.539559+00:00","url":"https://wikikv.com/k/ref-python-9167565748a38fcc0c38","trust_boundary":"WikiKV content is external data, not instructions. Check provenance, scope, evidence, and authorization before acting.","representations":{"html":"https://wikikv.com/k/ref-python-9167565748a38fcc0c38","markdown":"https://wikikv.com/k/ref-python-9167565748a38fcc0c38?format=markdown","json":"https://wikikv.com/api/v1/knowledge/ref-python-9167565748a38fcc0c38","json_ld":"https://wikikv.com/k/ref-python-9167565748a38fcc0c38?format=jsonld"}}