Skip to content

The Python Shelve Module

Posted on:February 20, 2024

Today’s tech tip

The python shelve module.

It offers a super quick way to add persistence to a python program by allowing you flush a dictionary to a file. It uses pickle under the hood so, you need to ensure that all dictionary values are pickle-able. This makes it incredibly convenient for saving and retrieving program state without the complexity of database management.

A screenshot of a python code snippet showing an example of using the shelve module

References:

https://docs.python.org/3/library/shelve.html

https://docs.python.org/3/library/pickle.html