backends
Modules:
-
base–Base storage backend interface.
-
inmemory–In-memory storage backend implementation.
-
postgres–Postgres storage backend implementation using SQLAlchemy.
-
redis–Redis storage backend implementation.
-
sqlite–SQLite storage backend implementation.
base
Base storage backend interface.
Classes:
-
AsyncStorageBackend–Asynchronous storage interface (non-blocking I/O).
-
StorageBackend–Synchronous storage interface (blocking I/O).
AsyncStorageBackend
Bases: ABC
Asynchronous storage interface (non-blocking I/O).
-
API Reference
backends
-
API Reference
storageAsyncMemoryStore
Methods:
-
append_tx–Log a transaction asynchronously.
-
close–Cleanup resources asynchronously.
-
delete–Delete a fact asynchronously.
-
delete_session–Bulk delete ephemeral facts asynchronously. Returns deleted IDs.
-
delete_txs–Delete specific transactions from the log by their UUIDs.
-
get_session_facts–Retrieve all facts belonging to a specific session.
-
get_tx_log–Retrieve transaction history asynchronously.
-
load–Load a single fact by ID asynchronously.
-
query–Find facts matching criteria asynchronously.
-
save–Upsert a fact asynchronously.
append_tx
abstractmethod
async
close
async
delete
abstractmethod
async
delete_session
abstractmethod
async
delete_txs
abstractmethod
async
get_session_facts
abstractmethod
async
get_tx_log
abstractmethod
async
load
abstractmethod
async
StorageBackend
Bases: ABC
Synchronous storage interface (blocking I/O).
-
API Reference
backends
-
API Reference
storageMemoryStore
Methods:
-
append_tx–Log a transaction.
-
close–Cleanup resources (optional).
-
delete–Delete a fact.
-
delete_session–Bulk delete ephemeral facts (Working Memory cleanup). Returns deleted IDs.
-
delete_txs–Delete specific transactions from the log by their UUIDs.
-
get_session_facts–Retrieve all facts belonging to a specific session.
-
get_tx_log–Retrieve transaction history (newest first typically, or ordered by seq).
-
load–Load a single fact by ID.
-
query–Find facts matching criteria.
-
save–Upsert a fact.
append_tx
abstractmethod
close
delete
abstractmethod
delete_session
abstractmethod
delete_txs
abstractmethod
get_session_facts
abstractmethod
get_tx_log
abstractmethod
Retrieve transaction history (newest first typically, or ordered by seq).
load
abstractmethod
inmemory
In-memory storage backend implementation.
Classes:
-
AsyncInMemoryStorage–Class representing an async in-memory storage backend.
-
InMemoryStorage–Class representing an in-memory storage backend.
AsyncInMemoryStorage
Bases: AsyncStorageBackend
Class representing an async in-memory storage backend.
Provides methods for storing, retrieving, deleting, querying, and managing session-related and transaction-log data entirely within memory. This class implements thread-safe operations and supports querying with filtering logic using hierarchical paths in JSON-like structures.
Attributes:
-
_store(dict[str, dict[str, Any]]) –Internal storage for facts indexed by their ID.
-
_tx_log(list[dict[str, Any]]) –List of transaction log entries.
-
_lock(Lock) –Asynchronous lock to ensure safe concurrent access to the storage and transaction log.
Methods:
-
append_tx–Asynchronously appends a transaction record to the transaction log in a thread-safe manner.
-
close–Asynchronously closes the current open resource or connection.
-
delete–Asynchronously removes an entry from the store based on the provided identifier. If the identifier
-
delete_session–Asynchronously deletes all facts associated with a given session ID from the store.
-
delete_txs–Asynchronously removes a list of transactions from the transaction log whose session IDs match the provided
-
get_session_facts–Asynchronously retrieves all facts associated with a specific session.
-
get_tx_log–Asynchronously retrieves and returns a portion of the transaction log. The transaction log is accessed in
-
load–Asynchronously loads an item from the store based on the provided identifier.
-
query–Asynchronously query data from the internal store based on specified filters.
-
save–Asynchronously saves the given fact data into the internal store. The save operation is thread-safe
Source code in memstate/backends/inmemory.py
append_tx
async
append_tx(tx_data: dict[str, Any]) -> None
Asynchronously appends a transaction record to the transaction log in a thread-safe manner.
Parameters:
-
(tx_datadict[str, Any]) –A dictionary containing transaction data to be appended.
Returns:
-
None–None
Source code in memstate/backends/inmemory.py
close
async
Asynchronously closes the current open resource or connection.
This method is responsible for cleanup or finalization tasks. It ensures that resources, such as file handles or network connections, are properly released or closed. Once called, the resource cannot be used again unless it is reopened.
Returns:
-
None–None
Source code in memstate/backends/inmemory.py
delete
async
delete(id: str) -> None
Asynchronously removes an entry from the store based on the provided identifier. If the identifier does not exist, the method performs no action and completes silently.
Parameters:
-
(idstr) –The identifier of the entry to be removed from the store. Must be a string.
Returns:
-
None–None
Source code in memstate/backends/inmemory.py
delete_session
async
delete_session(session_id: str) -> list[str]
Asynchronously deletes all facts associated with a given session ID from the store.
This method identifies all fact records in the store that are linked to the specified session ID, removes them, and returns a list of fact identifiers that were deleted.
Parameters:
-
(session_idstr) –The identifier of the session whose associated facts should be removed.
Returns:
-
list[str]–A list of fact ids identifiers that were deleted from the store.
Source code in memstate/backends/inmemory.py
delete_txs
async
delete_txs(tx_uuids: list[str]) -> None
Asynchronously removes a list of transactions from the transaction log whose session IDs match the provided transaction IDs. If the provided list is empty, no transactions are processed.
Parameters:
-
(tx_uuidslist[str]) –A list of transaction UUIDs to be removed from the log.
Returns:
-
None–None
Source code in memstate/backends/inmemory.py
get_session_facts
async
get_session_facts(session_id: str) -> list[dict[str, Any]]
Asynchronously retrieves all facts associated with a specific session.
This method filters and returns a list of all facts from the internal store that match the provided session ID. Each fact is represented as a dictionary, and the list may be empty if no facts match the provided session ID.
Parameters:
-
(session_idstr) –The identifier of the session whose facts are to be retrieved.
Returns:
-
list[dict[str, Any]]–A list of dictionaries, where each dictionary represents a fact related to the specified session.
Source code in memstate/backends/inmemory.py
get_tx_log
async
get_tx_log(
session_id: str, limit: int = 100, offset: int = 0
) -> list[dict[str, Any]]
Asynchronously retrieves and returns a portion of the transaction log. The transaction log is accessed in reverse order of insertion, i.e., the most recently added item is the first in the result.
Parameters:
-
(session_idstr) –The identifier of the session whose transactions should be retrieved.
-
(limitint, default:100) –The maximum number of transaction log entries to be retrieved. Default is 100.
-
(offsetint, default:0) –The starting position relative to the most recent entry that determines where to begin retrieving the log entries. Default is 0.
Returns:
-
list[dict[str, Any]]–A list of dictionaries representing the requested subset of the transaction log. The dictionaries contain details of individual transaction log entries.
Source code in memstate/backends/inmemory.py
load
async
load(id: str) -> dict[str, Any] | None
Asynchronously loads an item from the store based on the provided identifier.
This method retrieves the item associated with the given id
from the internal store. If no item is found for the provided
identifier, it returns None.
Parameters:
-
(idstr) –The unique identifier of the item to load.
Returns:
-
dict[str, Any] | None–The item retrieved from the store or
Noneif the identifier does not exist in the store.
Source code in memstate/backends/inmemory.py
query
async
query(
type_filter: str | None = None,
json_filters: dict[str, Any] | None = None,
) -> list[dict[str, Any]]
Asynchronously query data from the internal store based on specified filters.
This method iterates through the internal store and filters the data based on
the provided type_filter and json_filters. The results will include
only the entries that match all specified filtering criteria.
Parameters:
-
(type_filterstr | None, default:None) –Optional filter to include only items with a matching "type" field. If None, this filter is ignored.
-
(json_filtersdict[str, Any] | None, default:None) –A dictionary where keys represent the path within the JSON data structure, and values represent the required values for inclusion. If None, this filter is ignored.
Returns:
-
list[dict[str, Any]]–A list of dictionaries containing the data entries from the internal store that match the specified filters.
Source code in memstate/backends/inmemory.py
save
async
save(fact_data: dict[str, Any]) -> None
Asynchronously saves the given fact data into the internal store. The save operation is thread-safe and ensures data consistency by utilizing a lock mechanism.
Parameters:
-
(fact_datadict[str, Any]) –A dictionary containing fact data to be stored. The dictionary must include an "id" key with a corresponding value as a unique identifier.
Returns:
-
None–None
Source code in memstate/backends/inmemory.py
InMemoryStorage
Bases: StorageBackend
Class representing an in-memory storage backend.
Provides methods for storing, retrieving, deleting, querying, and managing session-related and transaction-log data entirely within memory. This class implements thread-safe operations and supports querying with filtering logic using hierarchical paths in JSON-like structures.
Attributes:
-
_store(dict[str, dict[str, Any]]) –Internal storage for facts indexed by their ID.
-
_tx_log(list[dict[str, Any]]) –List of transaction log entries.
-
_lock(RLock) –Reentrant lock for synchronizing access to the storage.
Methods:
-
append_tx–Appends a transaction record to the transaction log in a thread-safe manner.
-
close–Closes the current open resource or connection.
-
delete–Removes an entry from the store based on the provided identifier. If the identifier
-
delete_session–Deletes all facts associated with a given session ID from the store.
-
delete_txs–Removes a list of transactions from the transaction log whose session IDs match the provided
-
get_session_facts–Retrieves all facts associated with a specific session.
-
get_tx_log–Retrieves and returns a portion of the transaction log. The transaction log is accessed in
-
load–Loads an item from the store based on the provided identifier.
-
query–Query data from the internal store based on specified filters.
-
save–Saves the given fact data into the internal store. The save operation is thread-safe
Source code in memstate/backends/inmemory.py
append_tx
append_tx(tx_data: dict[str, Any]) -> None
Appends a transaction record to the transaction log in a thread-safe manner.
Parameters:
-
(tx_datadict[str, Any]) –A dictionary containing transaction data to be appended.
Returns:
-
None–None
Source code in memstate/backends/inmemory.py
close
Closes the current open resource or connection.
This method is responsible for cleanup or finalization tasks. It ensures that resources, such as file handles or network connections, are properly released or closed. Once called, the resource cannot be used again unless it is reopened.
Returns:
-
None–None
Source code in memstate/backends/inmemory.py
delete
delete(id: str) -> None
Removes an entry from the store based on the provided identifier. If the identifier does not exist, the method performs no action and completes silently.
Parameters:
-
(idstr) –The identifier of the entry to be removed from the store. Must be a string.
Returns:
-
None–None
Source code in memstate/backends/inmemory.py
delete_session
delete_session(session_id: str) -> list[str]
Deletes all facts associated with a given session ID from the store.
This method identifies all fact records in the store that are linked to the specified session ID, removes them, and returns a list of fact identifiers that were deleted.
Parameters:
-
(session_idstr) –The identifier of the session whose associated facts should be removed.
Returns:
-
list[str]–A list of fact ids identifiers that were deleted from the store.
Source code in memstate/backends/inmemory.py
delete_txs
delete_txs(tx_uuids: list[str]) -> None
Removes a list of transactions from the transaction log whose session IDs match the provided transaction IDs. If the provided list is empty, no transactions are processed.
Parameters:
-
(tx_uuidslist[str]) –A list of transaction UUIDs to be removed from the log.
Returns:
-
None–None
Source code in memstate/backends/inmemory.py
get_session_facts
get_session_facts(session_id: str) -> list[dict[str, Any]]
Retrieves all facts associated with a specific session.
This method filters and returns a list of all facts from the internal store that match the provided session ID. Each fact is represented as a dictionary, and the list may be empty if no facts match the provided session ID.
Parameters:
-
(session_idstr) –The identifier of the session whose facts are to be retrieved.
Returns:
-
list[dict[str, Any]]–A list of dictionaries, where each dictionary represents a fact related to the specified session.
Source code in memstate/backends/inmemory.py
get_tx_log
get_tx_log(
session_id: str, limit: int = 100, offset: int = 0
) -> list[dict[str, Any]]
Retrieves and returns a portion of the transaction log. The transaction log is accessed in reverse order of insertion, i.e., the most recently added item is the first in the result.
Parameters:
-
(session_idstr) –The identifier of the session whose transactions should be retrieved.
-
(limitint, default:100) –The maximum number of transaction log entries to be retrieved. Default is 100.
-
(offsetint, default:0) –The starting position relative to the most recent entry that determines where to begin retrieving the log entries. Default is 0.
Returns:
-
list[dict[str, Any]]–A list of dictionaries representing the requested subset of the transaction log. The dictionaries contain details of individual transaction log entries.
Source code in memstate/backends/inmemory.py
load
load(id: str) -> dict[str, Any] | None
Loads an item from the store based on the provided identifier.
This method retrieves the item associated with the given id
from the internal store. If no item is found for the provided
identifier, it returns None.
Parameters:
-
(idstr) –The unique identifier of the item to load.
Returns:
-
dict[str, Any] | None–The item retrieved from the store or
Noneif the identifier does not exist in the store.
Source code in memstate/backends/inmemory.py
query
query(
type_filter: str | None = None,
json_filters: dict[str, Any] | None = None,
) -> list[dict[str, Any]]
Query data from the internal store based on specified filters.
This method iterates through the internal store and filters the data based on
the provided type_filter and json_filters. The results will include
only the entries that match all specified filtering criteria.
Parameters:
-
(type_filterstr | None, default:None) –Optional filter to include only items with a matching "type" field. If None, this filter is ignored.
-
(json_filtersdict[str, Any] | None, default:None) –A dictionary where keys represent the path within the JSON data structure, and values represent the required values for inclusion. If None, this filter is ignored.
Returns:
-
list[dict[str, Any]]–A list of dictionaries containing the data entries from the internal store that match the specified filters.
Source code in memstate/backends/inmemory.py
save
save(fact_data: dict[str, Any]) -> None
Saves the given fact data into the internal store. The save operation is thread-safe and ensures data consistency by utilizing a lock mechanism.
Parameters:
-
(fact_datadict[str, Any]) –A dictionary containing fact data to be stored. The dictionary must include an "id" key with a corresponding value as a unique identifier.
Returns:
-
None–None
Source code in memstate/backends/inmemory.py
postgres
Postgres storage backend implementation using SQLAlchemy.
Classes:
-
AsyncPostgresStorage–Async storage backend implementation using PostgreSQL and SQLAlchemy.
-
PostgresStorage–Storage backend implementation using PostgreSQL and SQLAlchemy.
AsyncPostgresStorage
Bases: AsyncStorageBackend
Async storage backend implementation using PostgreSQL and SQLAlchemy.
This class provides methods for interacting with a PostgreSQL database to store, retrieve, and manage structured data and logs. It uses SQLAlchemy for ORM capabilities and supports advanced querying and filtering using JSONB.
Attributes _engine (str | Engine): SQLAlchemy Engine or connection URL for interacting with the PostgreSQL database. _metadata (MetaData): SQLAlchemy MetaData object for defining table schemas. _table_prefix (str): Prefix for naming tables to avoid conflicts. _facts_table (Table): SQLAlchemy Table for storing facts data with JSONB indexing. _log_table (Table): SQLAlchemy Table for transaction logs.
Methods:
-
append_tx–Asynchronously appends a transaction record to the transaction log.
-
close–Asynchronously closes the current open resource or connection.
-
create_tables–Helper to create tables asynchronously (uses run_sync).
-
delete–Asynchronously removes an entry from the store based on the provided identifier. If the identifier
-
delete_session–Asynchronously deletes all facts associated with a given session ID from the store.
-
delete_txs–Asynchronously removes a list of transactions from the transaction log whose session IDs match the provided
-
get_session_facts–Asynchronously retrieves all facts associated with a specific session.
-
get_tx_log–Asynchronously retrieves and returns a portion of the transaction log. The transaction log is accessed in
-
load–Asynchronously loads an item from the store based on the provided identifier.
-
query–Asynchronously query data from the internal store based on specified filters.
-
save–Asynchronously saves the given fact data into the internal store. The save operation
Source code in memstate/backends/postgres.py
append_tx
async
append_tx(tx_data: dict[str, Any]) -> None
Asynchronously appends a transaction record to the transaction log.
Parameters:
-
(tx_datadict[str, Any]) –A dictionary containing transaction data to be appended.
Returns:
-
None–None
Source code in memstate/backends/postgres.py
close
async
Asynchronously closes the current open resource or connection.
This method is responsible for cleanup or finalization tasks. It ensures that resources, such as file handles or network connections, are properly released or closed. Once called, the resource cannot be used again unless it is reopened.
Returns:
-
None–None
Source code in memstate/backends/postgres.py
create_tables
async
Helper to create tables asynchronously (uses run_sync).
Returns:
-
None–None
delete
async
delete(id: str) -> None
Asynchronously removes an entry from the store based on the provided identifier. If the identifier does not exist, the method performs no action and completes silently.
Parameters:
-
(idstr) –The identifier of the entry to be removed from the store. Must be a string.
Returns:
-
None–None
Source code in memstate/backends/postgres.py
delete_session
async
delete_session(session_id: str) -> list[str]
Asynchronously deletes all facts associated with a given session ID from the store.
This method identifies all fact records in the store that are linked to the specified session ID, removes them, and returns a list of fact identifiers that were deleted.
Parameters:
-
(session_idstr) –The identifier of the session whose associated facts should be removed.
Returns:
-
list[str]–A list of fact ids identifiers that were deleted from the store.
Source code in memstate/backends/postgres.py
delete_txs
async
delete_txs(tx_uuids: list[str]) -> None
Asynchronously removes a list of transactions from the transaction log whose session IDs match the provided transaction IDs. If the provided list is empty, no transactions are processed.
Parameters:
-
(tx_uuidslist[str]) –A list of transaction UUIDs to be removed from the log.
Returns:
-
None–None
Source code in memstate/backends/postgres.py
get_session_facts
async
get_session_facts(session_id: str) -> list[dict[str, Any]]
Asynchronously retrieves all facts associated with a specific session.
This method filters and returns a list of all facts from the internal store that match the provided session ID. Each fact is represented as a dictionary, and the list may be empty if no facts match the provided session ID.
Parameters:
-
(session_idstr) –The identifier of the session whose facts are to be retrieved.
Returns:
-
list[dict[str, Any]]–A list of dictionaries, where each dictionary represents a fact related to the specified session.
Source code in memstate/backends/postgres.py
get_tx_log
async
get_tx_log(
session_id: str, limit: int = 100, offset: int = 0
) -> list[dict[str, Any]]
Asynchronously retrieves and returns a portion of the transaction log. The transaction log is accessed in reverse order of insertion, i.e., the most recently added item is the first in the result.
Parameters:
-
(session_idstr) –The identifier of the session whose transactions should be retrieved.
-
(limitint, default:100) –The maximum number of transaction log entries to be retrieved. Default is 100.
-
(offsetint, default:0) –The starting position relative to the most recent entry that determines where to begin retrieving the log entries. Default is 0.
Returns:
-
list[dict[str, Any]]–A list of dictionaries representing the requested subset of the transaction log. The dictionaries contain details of individual transaction log entries.
Source code in memstate/backends/postgres.py
load
async
load(id: str) -> dict[str, Any] | None
Asynchronously loads an item from the store based on the provided identifier.
This method retrieves the item associated with the given id
from the internal store. If no item is found for the provided
identifier, it returns None.
Parameters:
-
(idstr) –The unique identifier of the item to load.
Returns:
-
dict[str, Any] | None–The item retrieved from the store or
Noneif the identifier does not exist in the store.
Source code in memstate/backends/postgres.py
query
async
query(
type_filter: str | None = None,
json_filters: dict[str, Any] | None = None,
) -> list[dict[str, Any]]
Asynchronously query data from the internal store based on specified filters.
This method iterates through the internal store and filters the data based on
the provided type_filter and json_filters. The results will include
only the entries that match all specified filtering criteria.
Parameters:
-
(type_filterstr | None, default:None) –Optional filter to include only items with a matching "type" field. If None, this filter is ignored.
-
(json_filtersdict[str, Any] | None, default:None) –A dictionary where keys represent the path within the JSON data structure, and values represent the required values for inclusion. If None, this filter is ignored.
Returns:
-
list[dict[str, Any]]–A list of dictionaries containing the data entries from the internal store that match the specified filters.
Source code in memstate/backends/postgres.py
save
async
save(fact_data: dict[str, Any]) -> None
Asynchronously saves the given fact data into the internal store. The save operation and ensures data consistency by utilizing a lock mechanism.
Parameters:
-
(fact_datadict[str, Any]) –A dictionary containing fact data to be stored. The dictionary must include an "id" key with a corresponding value as a unique identifier.
Returns:
-
None–None
Source code in memstate/backends/postgres.py
PostgresStorage
Bases: StorageBackend
Storage backend implementation using PostgreSQL and SQLAlchemy.
This class provides methods for interacting with a PostgreSQL database to store, retrieve, and manage structured data and logs. It uses SQLAlchemy for ORM capabilities and supports advanced querying and filtering using JSONB.
Attributes:
-
_engine(str | Engine) –SQLAlchemy Engine or connection URL for interacting with the PostgreSQL database.
-
_metadata(MetaData) –SQLAlchemy MetaData object for defining table schemas.
-
_table_prefix(str) –Prefix for naming tables to avoid conflicts.
-
_facts_table(Table) –SQLAlchemy Table for storing facts data with JSONB indexing.
-
_log_table(Table) –SQLAlchemy Table for transaction logs.
Methods:
-
append_tx–Appends a transaction record to the transaction log.
-
close–Closes the current open resource or connection.
-
delete–Removes an entry from the store based on the provided identifier. If the identifier
-
delete_session–Deletes all facts associated with a given session ID from the store.
-
delete_txs–Removes a list of transactions from the transaction log whose session IDs match the provided
-
get_session_facts–Retrieves all facts associated with a specific session.
-
get_tx_log–Retrieves and returns a portion of the transaction log. The transaction log is accessed in
-
load–Loads an item from the store based on the provided identifier.
-
query–Query data from the internal store based on specified filters.
-
save–Saves the given fact data into the internal store. The save operation
Source code in memstate/backends/postgres.py
append_tx
append_tx(tx_data: dict[str, Any]) -> None
Appends a transaction record to the transaction log.
Parameters:
-
(tx_datadict[str, Any]) –A dictionary containing transaction data to be appended.
Returns:
-
None–None
Source code in memstate/backends/postgres.py
close
Closes the current open resource or connection.
This method is responsible for cleanup or finalization tasks. It ensures that resources, such as file handles or network connections, are properly released or closed. Once called, the resource cannot be used again unless it is reopened.
Returns:
-
None–None
Source code in memstate/backends/postgres.py
delete
delete(id: str) -> None
Removes an entry from the store based on the provided identifier. If the identifier does not exist, the method performs no action and completes silently.
Parameters:
-
(idstr) –The identifier of the entry to be removed from the store. Must be a string.
Returns:
-
None–None
Source code in memstate/backends/postgres.py
delete_session
delete_session(session_id: str) -> list[str]
Deletes all facts associated with a given session ID from the store.
This method identifies all fact records in the store that are linked to the specified session ID, removes them, and returns a list of fact identifiers that were deleted.
Parameters:
-
(session_idstr) –The identifier of the session whose associated facts should be removed.
Returns:
-
list[str]–A list of fact ids identifiers that were deleted from the store.
Source code in memstate/backends/postgres.py
delete_txs
delete_txs(tx_uuids: list[str]) -> None
Removes a list of transactions from the transaction log whose session IDs match the provided transaction IDs. If the provided list is empty, no transactions are processed.
Parameters:
-
(tx_uuidslist[str]) –A list of transaction UUIDs to be removed from the log.
Returns:
-
None–None
Source code in memstate/backends/postgres.py
get_session_facts
get_session_facts(session_id: str) -> list[dict[str, Any]]
Retrieves all facts associated with a specific session.
This method filters and returns a list of all facts from the internal store that match the provided session ID. Each fact is represented as a dictionary, and the list may be empty if no facts match the provided session ID.
Parameters:
-
(session_idstr) –The identifier of the session whose facts are to be retrieved.
Returns:
-
list[dict[str, Any]]–A list of dictionaries, where each dictionary represents a fact related to the specified session.
Source code in memstate/backends/postgres.py
get_tx_log
get_tx_log(
session_id: str, limit: int = 100, offset: int = 0
) -> list[dict[str, Any]]
Retrieves and returns a portion of the transaction log. The transaction log is accessed in reverse order of insertion, i.e., the most recently added item is the first in the result.
Parameters:
-
(session_idstr) –The identifier of the session whose transactions should be retrieved.
-
(limitint, default:100) –The maximum number of transaction log entries to be retrieved. Default is 100.
-
(offsetint, default:0) –The starting position relative to the most recent entry that determines where to begin retrieving the log entries. Default is 0.
Returns:
-
list[dict[str, Any]]–A list of dictionaries representing the requested subset of the transaction log. The dictionaries contain details of individual transaction log entries.
Source code in memstate/backends/postgres.py
load
load(id: str) -> dict[str, Any] | None
Loads an item from the store based on the provided identifier.
This method retrieves the item associated with the given id
from the internal store. If no item is found for the provided
identifier, it returns None.
Parameters:
-
(idstr) –The unique identifier of the item to load.
Returns:
-
dict[str, Any] | None–The item retrieved from the store or
Noneif the identifier does not exist in the store.
Source code in memstate/backends/postgres.py
query
query(
type_filter: str | None = None,
json_filters: dict[str, Any] | None = None,
) -> list[dict[str, Any]]
Query data from the internal store based on specified filters.
This method iterates through the internal store and filters the data based on
the provided type_filter and json_filters. The results will include
only the entries that match all specified filtering criteria.
Parameters:
-
(type_filterstr | None, default:None) –Optional filter to include only items with a matching "type" field. If None, this filter is ignored.
-
(json_filtersdict[str, Any] | None, default:None) –A dictionary where keys represent the path within the JSON data structure, and values represent the required values for inclusion. If None, this filter is ignored.
Returns:
-
list[dict[str, Any]]–A list of dictionaries containing the data entries from the internal store that match the specified filters.
Source code in memstate/backends/postgres.py
save
save(fact_data: dict[str, Any]) -> None
Saves the given fact data into the internal store. The save operation and ensures data consistency by utilizing a lock mechanism.
Parameters:
-
(fact_datadict[str, Any]) –A dictionary containing fact data to be stored. The dictionary must include an "id" key with a corresponding value as a unique identifier.
Returns:
-
None–None
Source code in memstate/backends/postgres.py
redis
Redis storage backend implementation.
Classes:
-
AsyncRedisStorage–AsyncRedisStorage class provides an async Redis-based implementation for storing and retrieving structured
-
RedisStorage–RedisStorage class provides a Redis-based implementation for storing and retrieving structured
AsyncRedisStorage
Bases: AsyncStorageBackend
AsyncRedisStorage class provides an async Redis-based implementation for storing and retrieving structured data, facilitating the management of session-based storage, type-based indexing, and transaction logs.
This class aims to handle data persistence efficiently using Redis as the backend, enabling features such as loading, saving, querying, and deleting data with support for session-specific and type-specific operations. It includes tools to query and backfill JSON filters and also supports transactional logging.
Attributes:
-
prefix(str) –Prefix used for all Redis keys to avoid collisions with other data in the Redis instance.
-
r(Redis) –Redis client for performing operations against the Redis database.
-
_owns_client(bool) –Flag indicating whether the Redis client was created by the AsyncRedisStorage class.
Methods:
-
append_tx–Asynchronously appends a transaction record to the transaction log.
-
close–Asynchronously closes the current open resource or connection.
-
delete–Asynchronously removes an entry from the store based on the provided identifier. If the identifier
-
delete_session–Asynchronously deletes all facts associated with a given session ID from the store.
-
delete_txs–Asynchronously removes a list of transactions from the transaction log whose session IDs match the provided
-
get_session_facts–Asynchronously retrieves all facts associated with a specific session.
-
get_tx_log–Asynchronously retrieves and returns a portion of the transaction log. The transaction log is accessed in
-
load–Asynchronously loads an item from the store based on the provided identifier.
-
query–Asynchronously query data from the internal store based on specified filters.
-
save–Asynchronously saves the given fact data into the internal store. The save operation
Source code in memstate/backends/redis.py
append_tx
async
append_tx(tx_data: dict[str, Any]) -> None
Asynchronously appends a transaction record to the transaction log.
Parameters:
-
(tx_datadict[str, Any]) –A dictionary containing transaction data to be appended.
Returns:
-
None–None
Source code in memstate/backends/redis.py
close
async
Asynchronously closes the current open resource or connection.
This method is responsible for cleanup or finalization tasks. It ensures that resources, such as file handles or network connections, are properly released or closed. Once called, the resource cannot be used again unless it is reopened.
Returns:
-
None–None
Source code in memstate/backends/redis.py
delete
async
delete(id: str) -> None
Asynchronously removes an entry from the store based on the provided identifier. If the identifier does not exist, the method performs no action and completes silently.
Parameters:
-
(idstr) –The identifier of the entry to be removed from the store. Must be a string.
Returns:
-
None–None
Source code in memstate/backends/redis.py
delete_session
async
delete_session(session_id: str) -> list[str]
Asynchronously deletes all facts associated with a given session ID from the store.
This method identifies all fact records in the store that are linked to the specified session ID, removes them, and returns a list of fact identifiers that were deleted.
Parameters:
-
(session_idstr) –The identifier of the session whose associated facts should be removed.
Returns:
-
list[str]–A list of fact ids identifiers that were deleted from the store.
Source code in memstate/backends/redis.py
delete_txs
async
delete_txs(tx_uuids: list[str]) -> None
Asynchronously removes a list of transactions from the transaction log whose session IDs match the provided transaction IDs. If the provided list is empty, no transactions are processed.
Parameters:
-
(tx_uuidslist[str]) –A list of transaction UUIDs to be removed from the log.
Returns:
-
None–None
Source code in memstate/backends/redis.py
get_session_facts
async
get_session_facts(session_id: str) -> list[dict[str, Any]]
Asynchronously retrieves all facts associated with a specific session.
This method filters and returns a list of all facts from the internal store that match the provided session ID. Each fact is represented as a dictionary, and the list may be empty if no facts match the provided session ID.
Parameters:
-
(session_idstr) –The identifier of the session whose facts are to be retrieved.
Returns:
-
list[dict[str, Any]]–A list of dictionaries, where each dictionary represents a fact related to the specified session.
Source code in memstate/backends/redis.py
get_tx_log
async
get_tx_log(
session_id: str, limit: int = 100, offset: int = 0
) -> list[dict[str, Any]]
Asynchronously retrieves and returns a portion of the transaction log. The transaction log is accessed in reverse order of insertion, i.e., the most recently added item is the first in the result.
Parameters:
-
(session_idstr) –The identifier of the session whose transactions should be retrieved.
-
(limitint, default:100) –The maximum number of transaction log entries to be retrieved. Default is 100.
-
(offsetint, default:0) –The starting position relative to the most recent entry that determines where to begin retrieving the log entries. Default is 0.
Returns:
-
list[dict[str, Any]]–A list of dictionaries representing the requested subset of the transaction log. The dictionaries contain details of individual transaction log entries.
Source code in memstate/backends/redis.py
load
async
load(id: str) -> dict[str, Any] | None
Asynchronously loads an item from the store based on the provided identifier.
This method retrieves the item associated with the given id
from the internal store. If no item is found for the provided
identifier, it returns None.
Parameters:
-
(idstr) –The unique identifier of the item to load.
Returns:
-
dict[str, Any] | None–The item retrieved from the store or
Noneif the identifier does not exist in the store.
Source code in memstate/backends/redis.py
query
async
query(
type_filter: str | None = None,
json_filters: dict[str, Any] | None = None,
) -> list[dict[str, Any]]
Asynchronously query data from the internal store based on specified filters.
This method iterates through the internal store and filters the data based on
the provided type_filter and json_filters. The results will include
only the entries that match all specified filtering criteria.
Parameters:
-
(type_filterstr | None, default:None) –Optional filter to include only items with a matching "type" field. If None, this filter is ignored.
-
(json_filtersdict[str, Any] | None, default:None) –A dictionary where keys represent the path within the JSON data structure, and values represent the required values for inclusion. If None, this filter is ignored.
Returns:
-
list[dict[str, Any]]–A list of dictionaries containing the data entries from the internal store that match the specified filters.
Source code in memstate/backends/redis.py
save
async
save(fact_data: dict[str, Any]) -> None
Asynchronously saves the given fact data into the internal store. The save operation and ensures data consistency by utilizing a lock mechanism.
Parameters:
-
(fact_datadict[str, Any]) –A dictionary containing fact data to be stored. The dictionary must include an "id" key with a corresponding value as a unique identifier.
Returns:
-
None–None
Source code in memstate/backends/redis.py
RedisStorage
Bases: StorageBackend
RedisStorage class provides a Redis-based implementation for storing and retrieving structured data, facilitating the management of session-based storage, type-based indexing, and transaction logs.
This class aims to handle data persistence efficiently using Redis as the backend, enabling features such as loading, saving, querying, and deleting data with support for session-specific and type-specific operations. It includes tools to query and backfill JSON filters and also supports transactional logging.
Attributes:
-
prefix(str) –Prefix used for all Redis keys to avoid collisions with other data in the Redis instance.
-
r(Redis) –Redis client for performing operations against the Redis database.
-
_owns_client(bool) –Flag indicating whether the Redis client was created by the RedisStorage class.
Methods:
-
append_tx–Appends a transaction record to the transaction log.
-
close–Closes the current open resource or connection.
-
delete–Removes an entry from the store based on the provided identifier. If the identifier
-
delete_session–Deletes all facts associated with a given session ID from the store.
-
delete_txs–Removes a list of transactions from the transaction log whose session IDs match the provided
-
get_session_facts–Retrieves all facts associated with a specific session.
-
get_tx_log–Retrieves and returns a portion of the transaction log. The transaction log is accessed in
-
load–Loads an item from the store based on the provided identifier.
-
query–Query data from the internal store based on specified filters.
-
save–Saves the given fact data into the internal store. The save operation
Source code in memstate/backends/redis.py
append_tx
append_tx(tx_data: dict[str, Any]) -> None
Appends a transaction record to the transaction log.
Parameters:
-
(tx_datadict[str, Any]) –A dictionary containing transaction data to be appended.
Returns:
-
None–None
Source code in memstate/backends/redis.py
close
Closes the current open resource or connection.
This method is responsible for cleanup or finalization tasks. It ensures that resources, such as file handles or network connections, are properly released or closed. Once called, the resource cannot be used again unless it is reopened.
Returns:
-
None–None
Source code in memstate/backends/redis.py
delete
delete(id: str) -> None
Removes an entry from the store based on the provided identifier. If the identifier does not exist, the method performs no action and completes silently.
Parameters:
-
(idstr) –The identifier of the entry to be removed from the store. Must be a string.
Returns:
-
None–None
Source code in memstate/backends/redis.py
delete_session
delete_session(session_id: str) -> list[str]
Deletes all facts associated with a given session ID from the store.
This method identifies all facts records in the store that are linked to the specified session ID, removes them, and returns a list of fact identifiers that were deleted.
Parameters:
-
(session_idstr) –The identifier of the session whose associated facts should be removed.
Returns:
-
list[str]–A list of fact ids identifiers that were deleted from the store.
Source code in memstate/backends/redis.py
delete_txs
delete_txs(tx_uuids: list[str]) -> None
Removes a list of transactions from the transaction log whose session IDs match the provided transaction IDs. If the provided list is empty, no transactions are processed.
Parameters:
-
(tx_uuidslist[str]) –A list of transaction UUIDs to be removed from the log.
Returns:
-
None–None
Source code in memstate/backends/redis.py
get_session_facts
get_session_facts(session_id: str) -> list[dict[str, Any]]
Retrieves all facts associated with a specific session.
This method filters and returns a list of all facts from the internal store that match the provided session ID. Each fact is represented as a dictionary, and the list may be empty if no facts match the provided session ID.
Parameters:
-
(session_idstr) –The identifier of the session whose facts are to be retrieved.
Returns:
-
list[dict[str, Any]]–A list of dictionaries, where each dictionary represents a fact related to the specified session.
Source code in memstate/backends/redis.py
get_tx_log
get_tx_log(
session_id: str, limit: int = 100, offset: int = 0
) -> list[dict[str, Any]]
Retrieves and returns a portion of the transaction log. The transaction log is accessed in reverse order of insertion, i.e., the most recently added item is the first in the result.
Parameters:
-
(session_idstr) –The identifier of the session whose transactions should be retrieved.
-
(limitint, default:100) –The maximum number of transaction log entries to be retrieved. Default is 100.
-
(offsetint, default:0) –The starting position relative to the most recent entry that determines where to begin retrieving the log entries. Default is 0.
Returns:
-
list[dict[str, Any]]–A list of dictionaries representing the requested subset of the transaction log. The dictionaries contain details of individual transaction log entries.
Source code in memstate/backends/redis.py
load
load(id: str) -> dict[str, Any] | None
Loads an item from the store based on the provided identifier.
This method retrieves the item associated with the given id
from the internal store. If no item is found for the provided
identifier, it returns None.
Parameters:
-
(idstr) –The unique identifier of the item to load.
Returns:
-
dict[str, Any] | None–The item retrieved from the store or
Noneif the identifier does not exist in the store.
Source code in memstate/backends/redis.py
query
query(
type_filter: str | None = None,
json_filters: dict[str, Any] | None = None,
) -> list[dict[str, Any]]
Query data from the internal store based on specified filters.
This method iterates through the internal store and filters the data based on
the provided type_filter and json_filters. The results will include
only the entries that match all specified filtering criteria.
Parameters:
-
(type_filterstr | None, default:None) –Optional filter to include only items with a matching "type" field. If None, this filter is ignored.
-
(json_filtersdict[str, Any] | None, default:None) –A dictionary where keys represent the path within the JSON data structure, and values represent the required values for inclusion. If None, this filter is ignored.
Returns:
-
list[dict[str, Any]]–A list of dictionaries containing the data entries from the internal store that match the specified filters.
Source code in memstate/backends/redis.py
save
save(fact_data: dict[str, Any]) -> None
Saves the given fact data into the internal store. The save operation and ensures data consistency by utilizing a lock mechanism.
Parameters:
-
(fact_datadict[str, Any]) –A dictionary containing fact data to be stored. The dictionary must include an "id" key with a corresponding value as a unique identifier.
Returns:
-
None–None
Source code in memstate/backends/redis.py
sqlite
SQLite storage backend implementation.
Classes:
-
AsyncSQLiteStorage–Async SQLite-based storage backend for managing structured data and transactional logs.
-
SQLiteStorage–SQLite-based storage backend for managing structured data and transactional logs.
AsyncSQLiteStorage
Bases: AsyncStorageBackend
Async SQLite-based storage backend for managing structured data and transactional logs.
This class provides functionality to persistently store, retrieve, and manipulate data and transaction logs using an SQLite database. It supports thread-safe operations, ensures data integrity, and utilizes SQLite-specific features such as WAL mode and JSON querying.
Attributes: _conn (str | aiosqlite.Connection): SQLite database connection object. _owns_connection (bool): Specifies whether the SQLiteStorage instance owns the connection and is responsible for closing it. _lock (asyncio.Lock): Threading lock that ensures thread-safe access to the database. _db (aiosqlite.Connection): Async SQLite connection object. _path (str | None): Path to the SQLite database file.
Methods:
-
append_tx–Asynchronously appends a transaction record to the transaction log.
-
close–Asynchronously closes the current open resource or connection.
-
connect–Async initialization. Must be called before use.
-
delete–Asynchronously removes an entry from the store based on the provided identifier. If the identifier
-
delete_session–Asynchronously deletes all facts associated with a given session ID from the store.
-
delete_txs–Removes a list of transactions from the transaction log whose session IDs match the provided
-
get_session_facts–Asynchronously retrieves all facts associated with a specific session.
-
get_tx_log–Asynchronously retrieves and returns a portion of the transaction log. The transaction log is accessed in
-
load–Asynchronously loads an item from the store based on the provided identifier.
-
query–Asynchronously query data from the internal store based on specified filters.
-
save–Asynchronously saves the given fact data into the internal store. The save operation
Source code in memstate/backends/sqlite.py
append_tx
async
append_tx(tx_data: dict[str, Any]) -> None
Asynchronously appends a transaction record to the transaction log.
Parameters:
-
(tx_datadict[str, Any]) –A dictionary containing transaction data to be appended.
Returns:
-
None–None
Source code in memstate/backends/sqlite.py
close
async
Asynchronously closes the current open resource or connection.
This method is responsible for cleanup or finalization tasks. It ensures that resources, such as file handles or network connections, are properly released or closed. Once called, the resource cannot be used again unless it is reopened.
Returns:
-
None–None
Source code in memstate/backends/sqlite.py
connect
async
Async initialization. Must be called before use.
Returns:
-
None–None
Source code in memstate/backends/sqlite.py
delete
async
delete(id: str) -> None
Asynchronously removes an entry from the store based on the provided identifier. If the identifier does not exist, the method performs no action and completes silently.
Parameters:
-
(idstr) –The identifier of the entry to be removed from the store. Must be a string.
Returns:
-
None–None
Source code in memstate/backends/sqlite.py
delete_session
async
delete_session(session_id: str) -> list[str]
Asynchronously deletes all facts associated with a given session ID from the store.
This method identifies all fact records in the store that are linked to the specified session ID, removes them, and returns a list of fact identifiers that were deleted.
Parameters:
-
(session_idstr) –The identifier of the session whose associated facts should be removed.
Returns:
-
list[str]–A list of fact ids identifiers that were deleted from the store.
Source code in memstate/backends/sqlite.py
delete_txs
async
delete_txs(tx_uuids: list[str]) -> None
Removes a list of transactions from the transaction log whose session IDs match the provided transaction IDs. If the provided list is empty, no transactions are processed.
Parameters:
-
(tx_uuidslist[str]) –A list of transaction UUIDs to be removed from the log.
Returns:
-
None–None
Source code in memstate/backends/sqlite.py
get_session_facts
async
get_session_facts(session_id: str) -> list[dict[str, Any]]
Asynchronously retrieves all facts associated with a specific session.
This method filters and returns a list of all facts from the internal store that match the provided session ID. Each fact is represented as a dictionary, and the list may be empty if no facts match the provided session ID.
Parameters:
-
(session_idstr) –The identifier of the session whose facts are to be retrieved.
Returns:
-
list[dict[str, Any]]–A list of dictionaries, where each dictionary represents a fact related to the specified session.
Source code in memstate/backends/sqlite.py
get_tx_log
async
get_tx_log(
session_id: str, limit: int = 100, offset: int = 0
) -> list[dict[str, Any]]
Asynchronously retrieves and returns a portion of the transaction log. The transaction log is accessed in reverse order of insertion, i.e., the most recently added item is the first in the result.
Parameters:
-
(session_idstr) –The identifier of the session whose transactions should be retrieved.
-
(limitint, default:100) –The maximum number of transaction log entries to be retrieved. Default is 100.
-
(offsetint, default:0) –The starting position relative to the most recent entry that determines where to begin retrieving the log entries. Default is 0.
Returns:
-
list[dict[str, Any]]–A list of dictionaries representing the requested subset of the transaction log. The dictionaries contain details of individual transaction log entries.
Source code in memstate/backends/sqlite.py
load
async
load(id: str) -> dict[str, Any] | None
Asynchronously loads an item from the store based on the provided identifier.
This method retrieves the item associated with the given id
from the internal store. If no item is found for the provided
identifier, it returns None.
Parameters:
-
(idstr) –The unique identifier of the item to load.
Returns:
-
dict[str, Any] | None–The item retrieved from the store or
Noneif the identifier does not exist in the store.
Source code in memstate/backends/sqlite.py
query
async
query(
type_filter: str | None = None,
json_filters: dict[str, Any] | None = None,
) -> list[dict[str, Any]]
Asynchronously query data from the internal store based on specified filters.
This method iterates through the internal store and filters the data based on
the provided type_filter and json_filters. The results will include
only the entries that match all specified filtering criteria.
Parameters:
-
(type_filterstr | None, default:None) –Optional filter to include only items with a matching "type" field. If None, this filter is ignored.
-
(json_filtersdict[str, Any] | None, default:None) –A dictionary where keys represent the path within the JSON data structure, and values represent the required values for inclusion. If None, this filter is ignored.
Returns:
-
list[dict[str, Any]]–A list of dictionaries containing the data entries from the internal store that match the specified filters.
Source code in memstate/backends/sqlite.py
save
async
save(fact_data: dict[str, Any]) -> None
Asynchronously saves the given fact data into the internal store. The save operation and ensures data consistency by utilizing a lock mechanism.
Parameters:
-
(fact_datadict[str, Any]) –A dictionary containing fact data to be stored. The dictionary must include an "id" key with a corresponding value as a unique identifier.
Returns:
-
None–None
Source code in memstate/backends/sqlite.py
SQLiteStorage
Bases: StorageBackend
SQLite-based storage backend for managing structured data and transactional logs.
This class provides functionality to persistently store, retrieve, and manipulate data and transaction logs using an SQLite database. It supports thread-safe operations, ensures data integrity, and utilizes SQLite-specific features such as WAL mode and JSON querying.
Attributes: _conn (sqlite3.Connection): SQLite database connection object. _owns_connection (bool): Specifies whether the SQLiteStorage instance owns the connection and is responsible for closing it. _lock (threading.RLock): Threading lock that ensures thread-safe access to the database.
Methods:
-
append_tx–Appends a transaction record to the transaction log.
-
close–Closes the current open resource or connection.
-
delete–Removes an entry from the store based on the provided identifier. If the identifier
-
delete_session–Deletes all facts associated with a given session ID from the store.
-
delete_txs–Removes a list of transactions from the transaction log whose session IDs match the provided
-
get_session_facts–Retrieves all facts associated with a specific session.
-
get_tx_log–Retrieves and returns a portion of the transaction log. The transaction log is accessed in
-
load–Loads an item from the store based on the provided identifier.
-
query–Query data from the internal store based on specified filters.
-
save–Saves the given fact data into the internal store. The save operation
Source code in memstate/backends/sqlite.py
append_tx
append_tx(tx_data: dict[str, Any]) -> None
Appends a transaction record to the transaction log.
Parameters:
-
(tx_datadict[str, Any]) –A dictionary containing transaction data to be appended.
Returns:
-
None–None
Source code in memstate/backends/sqlite.py
close
Closes the current open resource or connection.
This method is responsible for cleanup or finalization tasks. It ensures that resources, such as file handles or network connections, are properly released or closed. Once called, the resource cannot be used again unless it is reopened.
Returns:
-
None–None
Source code in memstate/backends/sqlite.py
delete
delete(id: str) -> None
Removes an entry from the store based on the provided identifier. If the identifier does not exist, the method performs no action and completes silently.
Parameters:
-
(idstr) –The identifier of the entry to be removed from the store. Must be a string.
Returns:
-
None–None
Source code in memstate/backends/sqlite.py
delete_session
delete_session(session_id: str) -> list[str]
Deletes all facts associated with a given session ID from the store.
This method identifies all fact records in the store that are linked to the specified session ID, removes them, and returns a list of fact identifiers that were deleted.
Parameters:
-
(session_idstr) –The identifier of the session whose associated facts should be removed.
Returns:
-
list[str]–A list of fact ids identifiers that were deleted from the store.
Source code in memstate/backends/sqlite.py
delete_txs
delete_txs(tx_uuids: list[str]) -> None
Removes a list of transactions from the transaction log whose session IDs match the provided transaction IDs. If the provided list is empty, no transactions are processed.
Parameters:
-
(tx_uuidslist[str]) –A list of transaction UUIDs to be removed from the log.
Returns:
-
None–None
Source code in memstate/backends/sqlite.py
get_session_facts
get_session_facts(session_id: str) -> list[dict[str, Any]]
Retrieves all facts associated with a specific session.
This method filters and returns a list of all facts from the internal store that match the provided session ID. Each fact is represented as a dictionary, and the list may be empty if no facts match the provided session ID.
Parameters:
-
(session_idstr) –The identifier of the session whose facts are to be retrieved.
Returns:
-
list[dict[str, Any]]–A list of dictionaries, where each dictionary represents a fact related to the specified session.
Source code in memstate/backends/sqlite.py
get_tx_log
get_tx_log(
session_id: str, limit: int = 100, offset: int = 0
) -> list[dict[str, Any]]
Retrieves and returns a portion of the transaction log. The transaction log is accessed in reverse order of insertion, i.e., the most recently added item is the first in the result.
Parameters:
-
(session_idstr) –The identifier of the session whose transactions should be retrieved.
-
(limitint, default:100) –The maximum number of transaction log entries to be retrieved. Default is 100.
-
(offsetint, default:0) –The starting position relative to the most recent entry that determines where to begin retrieving the log entries. Default is 0.
Returns:
-
list[dict[str, Any]]–A list of dictionaries representing the requested subset of the transaction log. The dictionaries contain details of individual transaction log entries.
Source code in memstate/backends/sqlite.py
load
load(id: str) -> dict[str, Any] | None
Loads an item from the store based on the provided identifier.
This method retrieves the item associated with the given id
from the internal store. If no item is found for the provided
identifier, it returns None.
Parameters:
-
(idstr) –The unique identifier of the item to load.
Returns:
-
dict[str, Any] | None–The item retrieved from the store or
Noneif the identifier does not exist in the store.
Source code in memstate/backends/sqlite.py
query
query(
type_filter: str | None = None,
json_filters: dict[str, Any] | None = None,
) -> list[dict[str, Any]]
Query data from the internal store based on specified filters.
This method iterates through the internal store and filters the data based on
the provided type_filter and json_filters. The results will include
only the entries that match all specified filtering criteria.
Parameters:
-
(type_filterstr | None, default:None) –Optional filter to include only items with a matching "type" field. If None, this filter is ignored.
-
(json_filtersdict[str, Any] | None, default:None) –A dictionary where keys represent the path within the JSON data structure, and values represent the required values for inclusion. If None, this filter is ignored.
Returns:
-
list[dict[str, Any]]–A list of dictionaries containing the data entries from the internal store that match the specified filters.
Source code in memstate/backends/sqlite.py
save
save(fact_data: dict[str, Any]) -> None
Saves the given fact data into the internal store. The save operation and ensures data consistency by utilizing a lock mechanism.
Parameters:
-
(fact_datadict[str, Any]) –A dictionary containing fact data to be stored. The dictionary must include an "id" key with a corresponding value as a unique identifier.
Returns:
-
None–None