s3bucket
messageflux.iodevices.objectstorage.s3api.s3bucket
S3Bucket
this class represents a single S3 Bucket
this class represents a single S3 Bucket
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bucket_name |
str
|
the name of the bucket to work with |
required |
s3_resource |
S3ServiceResource
|
the s3 resource to use |
required |
auto_create |
bool
|
should we create the bucket if it doesn't exist? |
False
|
compute_url
computes the item url, by key
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key |
the key to item |
required |
Returns:
| Type | Description |
|---|---|
|
the url to item |
create_bucket
staticmethod
creates and returns a bucket
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
s3_resource |
S3ServiceResource
|
the s3 resource to use |
required |
bucket_name |
str
|
the bucket name to create and get |
required |
lifetime_in_days |
Optional[int]
|
the lifetime of objects in the bucket to set (None for no change) |
None
|
allow_public_access |
should we make the bucket publicly accessible from web |
False
|
Returns:
| Type | Description |
|---|---|
S3Bucket
|
the bucket |
delete_bucket
deletes all items in bucket, and then deletes bucket
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
force |
True will delete all objects on bucket, before deleting the bucket |
False
|
delete_object
deletes a binary from the bucket
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key |
str
|
the key of the binary |
required |
download_object
downloads an object from the bucket into a writable stream
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key |
str
|
the key of the object to download |
required |
writable_stream |
IO[Any]
|
the writable stream to write into |
required |
Returns:
| Type | Description |
|---|---|
|
|
find_objects
find objects ih the bucket.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
delimiter |
Optional[str]
|
A Delimiter is a character you use to group keys |
None
|
prefix |
Optional[str]
|
Limits the response to keys that begin with the specified prefix |
None
|
max_keys |
int
|
Sets the maximum number of keys returned in the response |
1000
|
**kwargs |
additional filters to s3 |
{}
|
Returns:
| Type | Description |
|---|---|
Iterator[S3Object]
|
dict from object key to last modified |
get_object
gets a binary from the bucket
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key |
str
|
the key of the binary |
required |
Returns:
| Type | Description |
|---|---|
S3Object
|
the buffer of the object, and the metadata dict |
list_buckets
staticmethod
returns a list of all the buckets in this client
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
s3_resource |
S3ServiceResource
|
the s3 resource to use |
required |
Returns:
| Type | Description |
|---|---|
Iterator[S3Bucket]
|
iterator of bucket objects |
list_objects
lists all the objects in this bucket
Returns:
| Type | Description |
|---|---|
Iterator[S3Object]
|
a generator of S3Objects |
put_object
puts a binary object in the bucket
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key |
str
|
the key of the object to put |
required |
buf |
Union[str, bytes, IO[Any]]
|
the buffer to put in the bucket |
required |
metadata |
Dict[str, str]
|
extra metadata |
required |
set_lifetime_in_days
sets the lifetime of all objects in bucket to 'days' days (or <=0 to cancel expiration)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
days |
int
|
the number of days for an item to live |
required |
S3BucketException
Bases: Exception
represents errors thrown from S3 bucket
S3NoSuchBucket
Bases: S3BucketException
represents no such bucket
S3NoSuchItem
Bases: S3BucketException
represents no such item in bucket
S3Object
represents an s3 object with lazy content get
last_modified
property
the object's last modified time (might incur a request to the server)