Differences Between dbm.gnu, dbm.ndbm, and dbm.dumb

Python's dbm package provides a unified, persistent dictionary-like interface for storing string keys and values, implemented through three distinct underlying modules: dbm.gnu, dbm.ndbm, and dbm.dumb. While they share a common mapping API, they differ significantly in their underlying engine, external dependencies, disk storage structures, record-size limitations, performance profiles, and concurrency mechanisms. Understanding these operational differences is essential for choosing the correct backend or designing cross-platform applications that rely on persistent key-value caching.

Engine and Dependencies

File Formats and Disk Structure

Key and Value Size Limitations

Performance and Memory Handling

Locking and Concurrency

Operational Selection

When using the top-level dbm.open(file, flag='r', mode=0o666), Python inspects the environment and selects the best available backend in order: dbm.gnu, then dbm.ndbm, and finally dbm.dumb. For high-throughput systems with large records, explicit use of dbm.gnu is standard. For environments requiring zero-dependency portability across arbitrary operating systems, dbm.dumb guarantees execution at the cost of performance.