camel.storages.key_value_storages package#

Submodules#

camel.storages.key_value_storages.base module#

class camel.storages.key_value_storages.base.BaseKeyValueStorage[source]#

Bases: ABC

An abstract base class for key-value storage systems. Provides a consistent interface for saving, loading, and clearing data records without any loss of information.

An abstract base class designed to serve as a foundation for various key-value storage systems. The class primarily interacts through Python dictionaries.

This class is meant to be inherited by multiple types of key-value storage implementations, including, but not limited to, JSON file storage, NoSQL databases like MongoDB and Redis, as well as in-memory Python dictionaries.

abstract clear() None[source]#

Removes all records from the key-value storage system.

abstract load() List[Dict[str, Any]][source]#

Loads all stored records from the key-value storage system.

Returns:

A list of dictionaries, where each dictionary

represents a stored record.

Return type:

List[Dict[str, Any]]

abstract save(records: List[Dict[str, Any]]) None[source]#

Saves a batch of records to the key-value storage system.

Parameters:

records (List[Dict[str, Any]]) – A list of dictionaries, where each dictionary represents a unique record to be stored.

camel.storages.key_value_storages.in_memory module#

class camel.storages.key_value_storages.in_memory.InMemoryKeyValueStorage[source]#

Bases: BaseKeyValueStorage

A concrete implementation of the BaseKeyValueStorage using in-memory list. Ideal for temporary storage purposes, as data will be lost when the program ends.

clear() None[source]#

Removes all records from the key-value storage system.

load() List[Dict[str, Any]][source]#

Loads all stored records from the key-value storage system.

Returns:

A list of dictionaries, where each dictionary

represents a stored record.

Return type:

List[Dict[str, Any]]

save(records: List[Dict[str, Any]]) None[source]#

Saves a batch of records to the key-value storage system.

Parameters:

records (List[Dict[str, Any]]) – A list of dictionaries, where each dictionary represents a unique record to be stored.

camel.storages.key_value_storages.json module#

class camel.storages.key_value_storages.json.JsonStorage(path: Path | None = None)[source]#

Bases: BaseKeyValueStorage

A concrete implementation of the BaseKeyValueStorage using JSON files. Allows for persistent storage of records in a human-readable format.

Parameters:

path (Path, optional) – Path to the desired JSON file. If None, a default path ./chat_history.json will be used. (default: None)

clear() None[source]#

Removes all records from the key-value storage system.

load() List[Dict[str, Any]][source]#

Loads all stored records from the key-value storage system.

Returns:

A list of dictionaries, where each dictionary

represents a stored record.

Return type:

List[Dict[str, Any]]

save(records: List[Dict[str, Any]]) None[source]#

Saves a batch of records to the key-value storage system.

Parameters:

records (List[Dict[str, Any]]) – A list of dictionaries, where each dictionary represents a unique record to be stored.

camel.storages.key_value_storages.redis module#

class camel.storages.key_value_storages.redis.RedisStorage(sid: str, url: str = 'redis://localhost:6379', loop: AbstractEventLoop | None = None, **kwargs)[source]#

Bases: BaseKeyValueStorage

A concrete implementation of the BaseCacheStorage using Redis as the backend. This is suitable for distributed cache systems that require persistence and high availability.

clear() None[source]#

Removes all records from the key-value storage system.

property client: Redis | None#

Returns the Redis client instance.

Returns:

The Redis client instance.

Return type:

redis.asyncio.Redis

async close() None[source]#

Closes the Redis client asynchronously.

load() List[Dict[str, Any]][source]#

Loads all stored records from the key-value storage system.

Returns:

A list of dictionaries, where each dictionary

represents a stored record.

Return type:

List[Dict[str, Any]]

save(records: List[Dict[str, Any]], expire: int | None = None) None[source]#

Saves a batch of records to the key-value storage system.

Module contents#

class camel.storages.key_value_storages.BaseKeyValueStorage[source]#

Bases: ABC

An abstract base class for key-value storage systems. Provides a consistent interface for saving, loading, and clearing data records without any loss of information.

An abstract base class designed to serve as a foundation for various key-value storage systems. The class primarily interacts through Python dictionaries.

This class is meant to be inherited by multiple types of key-value storage implementations, including, but not limited to, JSON file storage, NoSQL databases like MongoDB and Redis, as well as in-memory Python dictionaries.

abstract clear() None[source]#

Removes all records from the key-value storage system.

abstract load() List[Dict[str, Any]][source]#

Loads all stored records from the key-value storage system.

Returns:

A list of dictionaries, where each dictionary

represents a stored record.

Return type:

List[Dict[str, Any]]

abstract save(records: List[Dict[str, Any]]) None[source]#

Saves a batch of records to the key-value storage system.

Parameters:

records (List[Dict[str, Any]]) – A list of dictionaries, where each dictionary represents a unique record to be stored.

class camel.storages.key_value_storages.InMemoryKeyValueStorage[source]#

Bases: BaseKeyValueStorage

A concrete implementation of the BaseKeyValueStorage using in-memory list. Ideal for temporary storage purposes, as data will be lost when the program ends.

clear() None[source]#

Removes all records from the key-value storage system.

load() List[Dict[str, Any]][source]#

Loads all stored records from the key-value storage system.

Returns:

A list of dictionaries, where each dictionary

represents a stored record.

Return type:

List[Dict[str, Any]]

save(records: List[Dict[str, Any]]) None[source]#

Saves a batch of records to the key-value storage system.

Parameters:

records (List[Dict[str, Any]]) – A list of dictionaries, where each dictionary represents a unique record to be stored.

class camel.storages.key_value_storages.JsonStorage(path: Path | None = None)[source]#

Bases: BaseKeyValueStorage

A concrete implementation of the BaseKeyValueStorage using JSON files. Allows for persistent storage of records in a human-readable format.

Parameters:

path (Path, optional) – Path to the desired JSON file. If None, a default path ./chat_history.json will be used. (default: None)

clear() None[source]#

Removes all records from the key-value storage system.

load() List[Dict[str, Any]][source]#

Loads all stored records from the key-value storage system.

Returns:

A list of dictionaries, where each dictionary

represents a stored record.

Return type:

List[Dict[str, Any]]

save(records: List[Dict[str, Any]]) None[source]#

Saves a batch of records to the key-value storage system.

Parameters:

records (List[Dict[str, Any]]) – A list of dictionaries, where each dictionary represents a unique record to be stored.

class camel.storages.key_value_storages.RedisStorage(sid: str, url: str = 'redis://localhost:6379', loop: AbstractEventLoop | None = None, **kwargs)[source]#

Bases: BaseKeyValueStorage

A concrete implementation of the BaseCacheStorage using Redis as the backend. This is suitable for distributed cache systems that require persistence and high availability.

clear() None[source]#

Removes all records from the key-value storage system.

property client: Redis | None#

Returns the Redis client instance.

Returns:

The Redis client instance.

Return type:

redis.asyncio.Redis

async close() None[source]#

Closes the Redis client asynchronously.

load() List[Dict[str, Any]][source]#

Loads all stored records from the key-value storage system.

Returns:

A list of dictionaries, where each dictionary

represents a stored record.

Return type:

List[Dict[str, Any]]

save(records: List[Dict[str, Any]], expire: int | None = None) None[source]#

Saves a batch of records to the key-value storage system.