Python dbm: a generic interface to Unix database formats
Answer: dbm is a generic interface to variants of the DBM database.
Opening a file
Available backends include sqlite3, gnu, and ndbm.
If none of those modules are installed, the slow-but-simple implementation in dbm.dumb is used.
whichdb attempts to guess which of the several simple database modules created a file.
The default open flag is r, which opens an existing database for reading only.
How values are stored
Keys and values are always stored as bytes.
There is a third party interface to the Oracle Berkeley DB.
sqlite3, gnu, and dumb provide a reorganize method that can reclaim unused disk space.
These objects also support being used in a with statement.
See also
Claims
- id: C1 claim: dbm is a generic interface to variants of the DBM database. source: S1 evidence: "generic interface to variants of the DBM database"
- id: C2 claim: whichdb attempts to guess which simple database module created a file. source: S1 evidence: "guess which of the several simple database modules"
- id: C3 claim: Keys and values are always stored as bytes. source: S1 evidence: "Key and values are always stored as"
- id: C4 claim: A third-party binding exists for Oracle Berkeley DB. source: S2 evidence: "to the Oracle Berkeley DB"
Sources
- [S1] dbm — Interfaces to Unix databases. Python Software Foundation. https://docs.python.org/3/library/dbm.html . License: PSF License Version 2. Accessed 2026-11-24.
- [S2] dbm documentation (source). CPython. https://raw.githubusercontent.com/python/cpython/main/Doc/library/dbm.rst . License: PSF License Version 2. Accessed 2026-11-24.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Python Software Foundation, dbm — Interfaces to Unix databases; CPython, dbm documentation (source). PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Python Software Foundation, dbm — Interfaces to Unix databases; CPython, dbm documentation (source). PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation.
Cite this
iinventedlight. 2026. "Python dbm: a generic interface to Unix database formats." iinventedlight Library, iil:note:0924b565, version of 2026-11-24. https://iinventedlight.com/library/notes/python-dbm/. License: CC-BY-4.0.
@misc{iil_note_0924b565,
author = {{iinventedlight}},
title = {{Python dbm: a generic interface to Unix database formats}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-24},
url = {https://iinventedlight.com/library/notes/python-dbm/},
note = {Permanent ID iil:note:0924b565. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- python-dbm.schema.json (schema; CC-BY-4.0)
- python-dbm.table.json (table; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/python-dbm.md.