Skip to main content

agora.common.storage

Storage Objects

class Storage(ABC, MutableMapping)

Abstract base class for a key-value storage.

This class extends both the 'ABC' class and the 'MutableMapping' interface.

save_memory

@abstractmethod
def save_memory() -> None

Saves current state to the underlying storage mechanism.

load_memory

@abstractmethod
def load_memory() -> None

Loads state from the underlying storage mechanism.

JSONStorage Objects

class JSONStorage(Storage)

A JSON-based storage implementation.

__init__

def __init__(storage_path: str, autosave: bool = True) -> None

Instantiates JSONStorage.

Arguments:

  • storage_path str - Path to the JSON file.
  • autosave bool - If True, saves automatically after updates.

save_memory

def save_memory() -> None

Saves current state to the JSON file.

load_memory

def load_memory() -> None

Loads the state from the JSON file.

__getitem__

def __getitem__(key: str) -> Any

Retrieves an item by key.

Arguments:

  • key str - Key to retrieve.

Returns:

  • Any - The stored value or None if not found.

__setitem__

def __setitem__(key: str, value: Any) -> None

Sets a value for the specified key.

Arguments:

  • key str - Key to modify.
  • value Any - The data to store.

__delitem__

def __delitem__(key: str) -> None

Deletes the entry associated with the specified key.

Arguments:

  • key str - Key to delete.

__iter__

def __iter__() -> Iterator[str]

Iterates over stored keys.

Returns:

  • Iterator[str] - An iterator over the keys.

__len__

def __len__() -> int

Returns the number of stored items.

Returns:

  • int - The count of items.

__contains__

def __contains__(key: object) -> bool

Checks if a key is contained.

Arguments:

  • key object - Key to check.

Returns:

  • bool - True if the key exists, False otherwise.

__str__

def __str__() -> str

Returns a string representation of this storage.

Returns:

  • str - String describing the JSONStorage path.