pythonpython-3.xpickleshelvedbm

Is "shelve" just a combination of "dbm" and "pickle"?


So everything that is done in shelve can be done separately with dbm and pickle?


Solution

  • Yes and No.

    Yes, it relies on dbm and pickle.

    The difference with “dbm” databases is that the values (not the keys!) in a shelf can be essentially arbitrary Python objects — anything that the pickle module can handle

    the shelve module is backed by pickle

    No, the way those modules are used is platform/system-dependent.

    The choice of which database package will be used (such as dbm.ndbm or dbm.gnu) depends on which interface is available. Therefore it is not safe to open the database directly using dbm. The database is also (unfortunately) subject to the limitations of dbm, if it is used — this means that (the pickled representation of) the objects stored in the database should be fairly small, and in rare cases key collisions may cause the database to refuse updates.


    More in the official documentation.