---
source: https://iinventedlight.com/library/notes/python-dbm.md
title: "Python dbm: a generic interface to Unix database formats"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "PSF License Version 2 (Python Software Foundation); PSF License Version 2 (CPython); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "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."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-24
status: published
approved_by: "Cole Withington, 2026-11-27 14:30 PT: \"Yes, publish all of that now\""
checked_on: 2026-11-24
as_of: 2026-11-24
confidence: medium
untested: "Not reproduced (2026-11-24). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-python: python-dbm"
tags: [python, dbm, sqlite3, ndbm, gdbm, persistence]
client: Librarian
sources:
  - id: S1
    title: "dbm — Interfaces to Unix databases"
    publisher: Python Software Foundation
    url: https://docs.python.org/3/library/dbm.html
    accessed: 2026-11-24
    license: "PSF License Version 2"
  - id: S2
    title: "dbm documentation (source)"
    publisher: CPython
    url: https://raw.githubusercontent.com/python/cpython/main/Doc/library/dbm.rst
    accessed: 2026-11-24
    license: "PSF License Version 2"
---
# 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

- [python-shelve](https://iinventedlight.com/library/notes/python-shelve/)
- [python-sqlite3](https://iinventedlight.com/library/notes/python-sqlite3/)
- [python-pickle](https://iinventedlight.com/library/notes/python-pickle/)

## 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.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
