S3
the_data_packet.utils.s3
¶
AWS S3 storage backend.
logger = get_logger(__name__)
module-attribute
¶
S3UploadResult
dataclass
¶
Result of S3 upload operation.
success: bool
instance-attribute
¶
s3_url: Optional[str] = None
class-attribute
instance-attribute
¶
error_message: Optional[str] = None
class-attribute
instance-attribute
¶
file_size_bytes: Optional[int] = None
class-attribute
instance-attribute
¶
__init__(success: bool, s3_url: Optional[str] = None, error_message: Optional[str] = None, file_size_bytes: Optional[int] = None) -> None
¶
S3Storage
¶
AWS S3 storage backend.
bucket_name = bucket_name or config.s3_bucket_name
instance-attribute
¶
region = region or config.aws_region
instance-attribute
¶
s3_client = boto3.client('s3', **session_kwargs)
instance-attribute
¶
__init__(bucket_name: Optional[str] = None, aws_access_key_id: Optional[str] = None, aws_secret_access_key: Optional[str] = None, region: Optional[str] = None)
¶
Initialize S3 storage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bucket_name
|
Optional[str]
|
S3 bucket name (defaults to config) |
None
|
aws_access_key_id
|
Optional[str]
|
AWS access key (defaults to config/env) |
None
|
aws_secret_access_key
|
Optional[str]
|
AWS secret key (defaults to config/env) |
None
|
region
|
Optional[str]
|
AWS region (defaults to config) |
None
|
upload_file(local_path: Path, s3_key: Optional[str] = None, content_type: Optional[str] = None) -> S3UploadResult
¶
Upload a file to S3.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
local_path
|
Path
|
Path to local file |
required |
s3_key
|
Optional[str]
|
S3 object key (defaults to filename) |
None
|
public
|
Whether to make the file publicly readable |
required | |
content_type
|
Optional[str]
|
MIME type for the file |
None
|
Returns:
| Type | Description |
|---|---|
S3UploadResult
|
S3UploadResult with upload details |
bucket_exists() -> bool
¶
Check if the configured bucket exists and is accessible.