Persistence and Serialization Modules
dbm.gnu
Wraps the optional GNU database manager library for persistent byte-key mappings. It has backend-specific methods and storage format; files are not interchangeable with NDBM databases. Availability depends on how Python was built. The following example requires a Python installation with the GNU DBM extension.
Formal Syntax & Structure
python syntaxpython
import dbm.gnuReturn Value
module
Module namespace available through import; import is a statement, not a value-returning expression.
Working Example
Example Snippetpython
import dbm.gnufrom tempfile import TemporaryDirectoryfrom pathlib import Pathwith TemporaryDirectory() as folder: path = str(Path(folder)/"store") with dbm.gnu.open(path, "n") as db: db[b"count"] = b"3" with dbm.gnu.open(path, "r") as db: print(db[b"count"].decode("ascii"))