Minio client
Minio object storage implementation.
MinioConfig(endpoint, access_key, secret_key, bucket, secure=True)
dataclass
Configuration for MinIO object storage client.
Attributes:
| Name | Type | Description |
|---|---|---|
endpoint |
str
|
MinIO server endpoint URL |
access_key |
str
|
Access key for authentication |
secret_key |
str
|
Secret key for authentication |
bucket |
str
|
Bucket name to use for storage |
secure |
bool
|
Whether to use HTTPS (defaults to True) |
from_env()
classmethod
Create MinioConfig from environment variables.
Expected environment variables: - OBJECT_STORAGE_URL - OBJECT_STORAGE_USER - OBJECT_STORAGE_PASSWORD - OBJECT_STORAGE_BUCKET - OBJECT_STORAGE_SECURE (optional, defaults to True)
Returns:
| Type | Description |
|---|---|
MinioConfig
|
MinioConfig instance |
Raises:
| Type | Description |
|---|---|
ValueError
|
If required environment variables are not set |
MinioObjectStorage(config=None, ensure_bucket=True)
Bases: BaseObjectStorageClient
Implementation of ObjectStorageInterface using Minio.
Initialize MinioObjectStorage with configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config |
MinioConfig | None
|
MinioConfig instance. If None, will attempt to load from environment variables. |
None
|
ensure_bucket |
bool
|
Whether to ensure bucket exists during initialization (optional). Defaults to True. |
True
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If configuration is invalid or incomplete |
delete(object_key)
Delete data from Minio object storage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
object_key |
str
|
The key of the object to delete |
required |
Raises:
| Type | Description |
|---|---|
ConnectionError
|
If there's a network or connection issue |
generate_presigned_url(object_key, expires=24, response_headers=None)
Generate a presigned URL for accessing the object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
object_key |
str
|
The key of the object |
required |
expires |
int
|
Expiration time in hours (defaults to 24) |
24
|
response_headers |
dict[str, str] | None
|
Additional response headers (optional) |
None
|
Returns:
| Type | Description |
|---|---|
str
|
A presigned URL |
Raises:
| Type | Description |
|---|---|
ValueError
|
If expiration time is not positive |
ConnectionError
|
If there's an issue generating the URL |
get(object_key)
Get data from Minio object storage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
object_key |
str
|
The key of the object to retrieve |
required |
Returns:
| Type | Description |
|---|---|
bytes
|
The object data as bytes |
Raises:
| Type | Description |
|---|---|
KeyError
|
If the object is not found |
ConnectionError
|
If there's a network or connection issue |
list_objects(prefix='')
List objects in the bucket with optional prefix filter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prefix |
str
|
Optional prefix to filter objects |
''
|
Returns:
| Type | Description |
|---|---|
list[str]
|
List of object keys |
Raises:
| Type | Description |
|---|---|
ConnectionError
|
If there's an issue listing objects |
object_exists(object_key)
Check if an object exists in the MinIO bucket.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
object_key |
str
|
The key of the object to check. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the object exists, False otherwise. |
Raises:
| Type | Description |
|---|---|
ConnectionError
|
If there's a network or connection issue (excluding not found errors) |
upload(object_key, file_stream, filename=None, content_type=None, metadata=None)
Upload data to Minio object storage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
object_key |
str
|
The key to store the object under |
required |
file_stream |
bytes | BinaryIO
|
The data to upload (bytes or file-like object) |
required |
filename |
str | None
|
The filename of the data (optional) |
None
|
content_type |
str | None
|
The content type of the data (optional) |
None
|
metadata |
dict[str, str] | None
|
Additional metadata to store with the object (optional) |
None
|
Returns:
| Type | Description |
|---|---|
str
|
The object key of the uploaded data |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the file stream is empty or invalid |
ConnectionError
|
If there's an issue connecting to Minio |
Exception
|
For other unexpected errors during upload |