Persistence and Serialization Modules
dbm
Selects an available DBM backend to store byte keys and byte values in a local persistent mapping. Existing files determine the backend when recognizable; newly created databases prefer SQLite in 3.13 when available. The file format and locking rules depend on the backend. The n flag replaces existing contents.
Formal Syntax & Structure
python syntaxpython
import dbmReturn Value
module
Module namespace available through import; import is a statement, not a value-returning expression.
Working Example
Example Snippetpython
import dbmfrom tempfile import TemporaryDirectoryfrom pathlib import Pathwith TemporaryDirectory() as folder: path = str(Path(folder)/"store") with dbm.open(path, "n") as db: db[b"count"] = b"3" with dbm.open(path, "r") as db: print(db[b"count"].decode("ascii"))