Shelve#

The Shelve module provides a shelve-based version of the DBContextStorage class. This class is used to store and retrieve context data in a shelve format. It allows the DFF to easily store and retrieve context data in a format that is efficient for serialization and deserialization and can be easily used in python.

Shelve is a python library that allows to store and retrieve python objects. It is efficient and fast, but it is not recommended to use it to transfer data across different languages or platforms because it’s not cross-language compatible. It stores data in a dbm-style format in the file system, which is not as fast as the other serialization libraries like pickle or JSON.

class ShelveContextStorage(path)[source]#

Bases: DBContextStorage

Implements DBContextStorage with shelve as the driver.

Parameters:

path (str) – Target file URI. Example: shelve://file.db.

async get_item_async(key)[source]#

Asynchronous method for accessing stored Context.

Parameters:

key (Hashable) – Hashable key used to store Context instance.

Return type:

Context

Returns:

The stored context, associated with the given key.

async set_item_async(key, value)[source]#

Asynchronous method for storing Context.

Parameters:
  • key (Hashable) – Hashable key used to store Context instance.

  • value (Context) – Context to store.

async del_item_async(key)[source]#

Asynchronous method for removing stored Context.

Parameters:

key (Hashable) – Hashable key used to identify Context instance for deletion.

async contains_async(key)[source]#

Asynchronous method for finding whether any Context is stored with given key.

Parameters:

key (Hashable) – Hashable key used to check if Context instance is stored.

Return type:

bool

Returns:

True if there is Context accessible by given key, False otherwise.

async len_async()[source]#

Asynchronous method for retrieving number of stored Contexts.

Return type:

int

Returns:

The number of stored Contexts.

async clear_async()[source]#

Asynchronous method for clearing context storage, removing all the stored Contexts.