Memory implementation of the key-value store client.
This client stores data in memory as Python dictionaries. No data is persisted between process runs, meaning all stored data is lost when the program terminates. This implementation is primarily useful for testing, development, and short-lived crawler operations where persistence is not required.
The memory implementation provides fast access to data but is limited by available memory and does not support data sharing across different processes.
Hierarchy
- KeyValueStoreClient
- MemoryKeyValueStoreClient
Index
Methods
__init__
- __init__(*, metadata): None
Initialize a new instance.
Preferably use the
MemoryKeyValueStoreClient.openclass method to create a new instance.Parameters
keyword-onlymetadata: KeyValueStoreMetadata
Returns None
delete_value
- async delete_value(*, key): None
Delete a value from the key-value store by its key.
The backend method for the
KeyValueStore.delete_valuecall.Parameters
keyword-onlykey: str
Returns None
drop
- async drop(): None
Drop the whole key-value store and remove all its values.
The backend method for the
KeyValueStore.dropcall.Returns None
get_metadata
- async get_metadata(): KeyValueStoreMetadata
Get the metadata of the key-value store.
Returns KeyValueStoreMetadata
get_public_url
- async get_public_url(*, key): str
Get the public URL for the given key.
The backend method for the
KeyValueStore.get_public_urlcall.Parameters
keyword-onlykey: str
Returns str
get_value
- async get_value(*, key): KeyValueStoreRecord | None
Retrieve the given record from the key-value store.
The backend method for the
KeyValueStore.get_valuecall.Parameters
keyword-onlykey: str
Returns KeyValueStoreRecord | None
iterate_entries
- async iterate_entries(*, exclusive_start_key, limit): AsyncIterator[KeyValueStoreRecord]
Iterate over all the existing records in the key-value store, including their values.
The backend method for the
KeyValueStore.iterate_entriesandKeyValueStore.iterate_valuescalls.The default implementation lists the keys with
iterate_keysand reads each value separately withget_valueas the iteration advances, so only a single value is held in memory at a time. Whether a record deleted while the iteration is in progress is yielded depends on the implementation. Backends that can read the keys together with their values more efficiently should override this method; such an implementation must still keep the memory usage bounded, e.g. by streaming or by batching on the known record sizes.Parameters
optionalkeyword-onlyexclusive_start_key: str | None = None
optionalkeyword-onlylimit: int | None = None
Returns AsyncIterator[KeyValueStoreRecord]
iterate_keys
- async iterate_keys(*, exclusive_start_key, limit): AsyncIterator[KeyValueStoreRecordMetadata]
Iterate over all the existing keys in the key-value store.
The backend method for the
KeyValueStore.iterate_keyscall.Parameters
optionalkeyword-onlyexclusive_start_key: str | None = None
optionalkeyword-onlylimit: int | None = None
Returns AsyncIterator[KeyValueStoreRecordMetadata]
open
- async open(*, id, name, alias): Self
Open or create a new memory key-value store client.
This method creates a new in-memory key-value store instance. Unlike persistent storage implementations, memory KVS don't check for existing stores with the same name or ID since all data exists only in memory and is lost when the process terminates.
Alias does not have any effect on the memory storage client implementation, because unnamed storages are supported by default, since data are not persisted.
Parameters
keyword-onlyid: str | None
The ID of the key-value store. If not provided, a random ID will be generated.
keyword-onlyname: str | None
The name of the key-value store for named (global scope) storages.
keyword-onlyalias: str | None
The alias of the key-value store for unnamed (run scope) storages.
Returns Self
An instance for the opened or created storage client.
purge
- async purge(): None
Purge all items from the key-value store.
The backend method for the
KeyValueStore.purgecall.Returns None
record_exists
- async record_exists(*, key): bool
Check if a record with the given key exists in the key-value store.
The backend method for the
KeyValueStore.record_existscall.Parameters
keyword-onlykey: str
The key to check for existence.
Returns bool
True if a record with the given key exists, False otherwise.
set_value
- async set_value(*, key, value, content_type): None
Set a value in the key-value store by its key.
The backend method for the
KeyValueStore.set_valuecall.Parameters
keyword-onlykey: str
keyword-onlyvalue: Any
optionalkeyword-onlycontent_type: str | None = None
Returns None