Python Shelve Module Extension
The Python standard library shelve module can create persistent (saved on binary files) Python dictionaries, similar to databases, where the key is a string and the value is any object that can be serialized (Pickle).
This extension, as shown in the video below, provides a unique storage directory that can be assigned with an environmental variable. For example, a database can be created inside a Jupyter notebook and then easily shared with a python REPL.
Installation
Define the environmental variable where the databases should be stored.
On Windows OS:
set MYSHELF=C:\Users\users\MyShelf
On Linux OS:
export MYSHELF=/home/user/MyShelf
When the variable MYSHELF is not defined the directory HOME\Documents\My Shelf will be used.
Install the module with pip.
On Windows OS:
py -m pip install git+https://sevepy@bitbucket.org/sevepy/myshelf.git#egg=myshelf
On Linux OS:
pip install git+https://sevepy@bitbucket.org/sevepy/myshelf.git#egg=myshelf
New Methods
This notebook shows an example on how to use this extension. To open a new database in the specified directory the module has a new function named open_default with the same shelve.open API.
The inspect method, associated with a new database instance, prints a table with the key, type of object stored and a one-line representation of the value.