Object Persistence Modules
Three modules comprise the object persistence interface.
dbm(anydbmin Python 2.X)Key-based string-only storage files.
pickle(andcPicklein Python 2.X)Serializes an in-memory object to/from file streams.
shelveKey-based persistent object stores: pickles objects to/from
dbmfiles.
The shelve module implements
persistent object stores. shelve in
turn uses the pickle module to
convert (serialize) in-memory Python objects to byte-stream strings and
the dbm module to store serialized
byte-stream strings in access-by-key files.
Note
In Python 2.X, dbm is named
anydbm, and the cPickle module is an optimized version of
pickle that may be imported
directly and is used automatically by shelve, if present. In Python 3.0, cPickle is renamed _pickle and is automatically used by
pickle if present—it need not be
imported directly and is acquired by shelve.
Also note that in Python 3.0 the Berkeley DB (a.k.a. bsddb) interface for dbm is no longer shipped with Python itself,
but is a third-party open source extension which must be installed
separately (see the Python 3.0 Library Reference for
resources).
dbm and shelve Modules
dbm is an access-by-key filesystem: strings are stored and fetched by their string keys. The
dbm module selects the keyed-access
file implementation in your Python interpreter and presents a
dictionary-like API for scripts. A persistent object shelve is used like a simple dbm file, except that the dbm module is replaced by shelve, and the stored value ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access