Adapters API Reference¶
Complete API reference for all available adapters.
PydanticAdapter¶
PydanticAdapter
¶
Bases: BasePydanticAdapter[T]
Adapter around a KVStore-compliant Store that allows type-safe persistence of Pydantic models.
_raise_on_validation_error
instance-attribute
¶
__init__
¶
Create a new PydanticAdapter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key_value
|
AsyncKeyValue
|
The KVStore to use. |
required |
pydantic_model
|
type[T]
|
The Pydantic model to use. Can be a single Pydantic model or list[Pydantic model]. |
required |
default_collection
|
str | None
|
The default collection to use. |
None
|
raise_on_validation_error
|
bool
|
Whether to raise a DeserializationError if validation fails during reads. Otherwise, calls will return None if validation fails. |
False
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If pydantic_model is a sequence type other than list (e.g., tuple is not supported). |
RaiseOnMissingAdapter¶
RaiseOnMissingAdapter
¶
Adapter around a KVStore that raises on missing values for get/get_many/ttl/ttl_many.
When raise_on_missing=True, methods raise MissingKeyError instead of returning None.
delete
async
¶
Delete a key-value pair from the specified collection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The key to delete the value from. |
required |
collection
|
str | None
|
The collection to delete the value from. If no collection is provided, it will use the default collection. |
None
|
delete_many
async
¶
Delete multiple key-value pairs from the specified collection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
keys
|
Sequence[str]
|
The keys to delete the values from. |
required |
collection
|
str | None
|
The collection to delete keys from. If no collection is provided, it will use the default collection. |
None
|
Returns:
| Type | Description |
|---|---|
int
|
The number of keys deleted. |
get
async
¶
Retrieve a value by key from the specified collection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The key to retrieve the value from. |
required |
collection
|
str | None
|
The collection to retrieve the value from. If no collection is provided, it will use the default collection. |
None
|
raise_on_missing
|
bool
|
Whether to raise a MissingKeyError if the key is not found. |
False
|
Returns:
| Type | Description |
|---|---|
dict[str, Any] | None
|
The value associated with the key. If the key is not found, None will be returned. |
get_many
async
¶
Retrieve multiple values by key from the specified collection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
keys
|
Sequence[str]
|
The keys to retrieve the values from. |
required |
collection
|
str | None
|
The collection to retrieve keys from. If no collection is provided, it will use the default collection. |
None
|
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]] | list[dict[str, Any] | None]
|
The values for the keys, or [] if the key is not found. |
put
async
¶
Store a key-value pair in the specified collection with optional TTL.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The key to store the value in. |
required |
value
|
Mapping[str, Any]
|
The value to store. |
required |
collection
|
str | None
|
The collection to store the value in. If no collection is provided, it will use the default collection. |
None
|
ttl
|
SupportsFloat | None
|
The optional time-to-live (expiry duration) for the key-value pair. Defaults to no TTL. Note: The backend store will convert the provided format to its own internal format. |
None
|
put_many
async
¶
Store multiple key-value pairs in the specified collection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
keys
|
Sequence[str]
|
The keys to store the values in. |
required |
values
|
Sequence[Mapping[str, Any]]
|
The values to store. |
required |
collection
|
str | None
|
The collection to store keys in. If no collection is provided, it will use the default collection. |
None
|
ttl
|
SupportsFloat | None
|
The optional time-to-live (expiry duration) for all key-value pairs. The same TTL will be applied to all items in the batch. Defaults to no TTL. Note: The backend store will convert the provided format to its own internal format. |
None
|
ttl
async
¶
Retrieve the value and TTL information for a key-value pair from the specified collection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The key to retrieve the TTL information from. |
required |
collection
|
str | None
|
The collection to retrieve the TTL information from. If no collection is provided, it will use the default collection. |
None
|
Returns:
| Type | Description |
|---|---|
tuple[dict[str, Any] | None, float | None]
|
The value and TTL information for the key. If the key is not found, (None, None) will be returned. |
ttl_many
async
¶
Retrieve multiple values and TTL information by key from the specified collection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
keys
|
Sequence[str]
|
The keys to retrieve the values and TTL information from. |
required |
collection
|
str | None
|
The collection to retrieve keys from. If no collection is provided, it will use the default collection. |
None
|