strands.storage.in_memory_storage
In-memory storage implementation.
InMemoryStorage
Section titled “InMemoryStorage”class InMemoryStorage()Defined in: src/strands/storage/in_memory_storage.py:11
Map-backed storage for testing and short-lived processes.
Content does not survive process restarts. The store is unbounded — consumers manage eviction themselves.
Example:
from strands.storage import InMemoryStorage
storage = InMemoryStorage()await storage.write("sessions/abc/state.json", b'\{"messages": []}')data = await storage.read("sessions/abc/state.json")__init__
Section titled “__init__”def __init__() -> NoneDefined in: src/strands/storage/in_memory_storage.py:27
Initialize an empty in-memory store.
async def write(key: str, data: bytes) -> NoneDefined in: src/strands/storage/in_memory_storage.py:32
Store data under key, overwriting any existing value.
Arguments:
key- Opaque, ’/‘-separated key identifying the value.data- Raw bytes to persist.
Raises:
StorageError- If the key is invalid.
async def read(key: str) -> bytes | NoneDefined in: src/strands/storage/in_memory_storage.py:46
Retrieve the bytes previously stored under key.
Arguments:
key- The key to read.
Returns:
The stored bytes, or None if no value exists for key.
Raises:
StorageError- If the key is invalid.
delete
Section titled “delete”async def delete(key: str) -> NoneDefined in: src/strands/storage/in_memory_storage.py:63
Delete the value stored under key. A no-op if the key does not exist.
Arguments:
key- The key to delete.
Raises:
StorageError- If the key is invalid.
async def list(query: str = "") -> builtins.list[str]Defined in: src/strands/storage/in_memory_storage.py:76
List keys matching the given prefix.
Arguments:
query- A prefix string to filter keys. Empty string matches all.
Returns:
Matching keys sorted ascending.
Raises:
StorageError- If the prefix is invalid.
namespace
Section titled “namespace”def namespace(prefix: str) -> _NamespacedStorageDefined in: src/strands/storage/in_memory_storage.py:93
Return a view of this storage with all keys prefixed.
Arguments:
prefix- Prefix to prepend to all keys.
Returns:
A namespaced storage view.
def clear() -> NoneDefined in: src/strands/storage/in_memory_storage.py:104
Remove all stored entries.