Store Module¶
store ¶
Classes¶
KeyBuilder ¶
Utility class for building store keys with a consistent format.
Attributes:
| Name | Type | Description |
|---|---|---|
split_char | Character used to split parts of the key. | |
prefix | Prefix to prepend to all keys. |
Source code in audex/lib/store/__init__.py
Functions¶
build ¶
Build a store key by joining the prefix and parts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*parts | str | Parts to include in the key. | () |
Returns:
| Type | Description |
|---|---|
str | The constructed store key. |
validate ¶
Validate if a given key starts with the defined prefix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key | str | The store key to validate. | required |
Returns:
| Type | Description |
|---|---|
bool | True if the key starts with the prefix, False otherwise. |
Source code in audex/lib/store/__init__.py
Store ¶
Bases: LoggingMixin, ABC
Abstract base class for storage operations.
This class defines the interface for storage backends, providing methods for uploading, downloading, deleting, and managing stored objects.
Source code in audex/helper/mixin.py
Attributes¶
key_builder abstractmethod property ¶
key_builder: KeyBuilder
Get a KeyBuilder instance for constructing store keys.
Returns:
| Type | Description |
|---|---|
KeyBuilder | An instance of KeyBuilder. |
Functions¶
upload abstractmethod async ¶
upload(data: bytes | IO[bytes], key: str, metadata: Mapping[str, Any] | None = None, **kwargs: Any) -> str
Upload data to storage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data | bytes | IO[bytes] | The data to upload, either as bytes or a file-like object. | required |
key | str | The unique identifier for the stored object. | required |
metadata | Mapping[str, Any] | None | Optional metadata to associate with the object. | None |
**kwargs | Any | Additional storage-specific parameters. | {} |
Returns:
| Type | Description |
|---|---|
str | The key of the uploaded object. |
Raises:
| Type | Description |
|---|---|
Exception | If the upload fails. |
Source code in audex/lib/store/__init__.py
upload_multipart abstractmethod async ¶
upload_multipart(parts: AsyncIterable[bytes], key: str, metadata: Mapping[str, Any] | None = None, **kwargs: Any) -> str
Upload data in multiple parts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parts | AsyncIterable[bytes] | An async iterable of byte chunks to upload. | required |
key | str | The unique identifier for the stored object. | required |
metadata | Mapping[str, Any] | None | Optional metadata to associate with the object. | None |
**kwargs | Any | Additional storage-specific parameters. | {} |
Returns:
| Type | Description |
|---|---|
str | The key of the uploaded object. |
Raises:
| Type | Description |
|---|---|
Exception | If the multipart upload fails. |
Source code in audex/lib/store/__init__.py
get_metadata abstractmethod async ¶
Retrieve metadata for a stored object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key | str | The unique identifier of the object. | required |
Returns:
| Type | Description |
|---|---|
dict[str, Any] | A dictionary containing the object's metadata. |
Raises:
| Type | Description |
|---|---|
Exception | If the object doesn't exist or metadata retrieval fails. |
Source code in audex/lib/store/__init__.py
download abstractmethod async ¶
download(key: str, *, stream: bool = False, chunk_size: int = 8192, **kwargs: Any) -> bytes | AsyncIterable[bytes]
Download data from storage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key | str | The unique identifier of the object to download. | required |
stream | bool | If True, return an async iterable of chunks; otherwise return all bytes. | False |
chunk_size | int | Size of each chunk when streaming (in bytes). | 8192 |
**kwargs | Any | Additional storage-specific parameters. | {} |
Returns:
| Type | Description |
|---|---|
bytes | AsyncIterable[bytes] | The object's data as bytes, or an async iterable of byte chunks if streaming. |
Raises:
| Type | Description |
|---|---|
Exception | If the download fails or object doesn't exist. |
Source code in audex/lib/store/__init__.py
delete abstractmethod async ¶
Delete an object from storage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key | str | The unique identifier of the object to delete. | required |
Raises:
| Type | Description |
|---|---|
Exception | If the deletion fails. |
list abstractmethod ¶
List objects in storage with the given prefix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prefix | str | Optional prefix to filter objects. | '' |
page_size | int | Number of object keys to return per iteration. | 10 |
**kwargs | Any | Additional storage-specific parameters. | {} |
Yields:
| Type | Description |
|---|---|
AsyncIterable[list[str]] | Lists of object keys matching the prefix. |
Raises:
| Type | Description |
|---|---|
Exception | If listing fails. |
Source code in audex/lib/store/__init__.py
exists abstractmethod async ¶
Check if an object exists in storage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key | str | The unique identifier of the object. | required |
Returns:
| Type | Description |
|---|---|
bool | True if the object exists, False otherwise. |
Raises:
| Type | Description |
|---|---|
Exception | If the existence check fails. |
Source code in audex/lib/store/__init__.py
clear abstractmethod async ¶
Delete all objects with the given prefix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prefix | str | Optional prefix to filter objects for deletion. | '' |
Raises:
| Type | Description |
|---|---|
Exception | If the clear operation fails. |
Source code in audex/lib/store/__init__.py
copy abstractmethod async ¶
Copy an object to a new location.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source_key | str | The unique identifier of the source object. | required |
dest_key | str | The unique identifier for the destination object. | required |
**kwargs | Any | Additional storage-specific parameters. | {} |
Returns:
| Type | Description |
|---|---|
str | The key of the copied object. |
Raises:
| Type | Description |
|---|---|
Exception | If the copy operation fails. |
Source code in audex/lib/store/__init__.py
options: show_root_heading: true show_source: true heading_level: 2 members_order: source show_signature_annotations: true separate_signature: true