Table of Contents
Initializes a new client object.
Parameters
Param |
Type |
Description |
---|---|---|
|
str |
Hostname of a S3 service. |
|
str |
(Optional) Access key (aka user ID) of your account in S3 service. |
|
str |
(Optional) Secret Key (aka password) of your account in S3 service. |
|
str |
(Optional) Session token of your account in S3 service. |
|
bool |
(Optional) Flag to indicate to use secure (TLS) connection to S3 service or not. |
|
str |
(Optional) Region name of buckets in S3 service. |
|
urllib3.poolmanager.PoolManager |
(Optional) Customized HTTP client. |
|
minio.credentials.Provider |
(Optional) Credentials provider of your account in S3 service. |
NOTE on concurrent usage: Minio
object is thread safe when using the Python threading
library. Specifically, it is NOT safe to share it between multiple processes, for example when using multiprocessing.Pool
. The solution is simply to create a new Minio
object in each process, and not share it between processes.
Example
from minio import Minio
# Create client with anonymous access.
client = Minio("play.min.io")
# Create client with access and secret key.
client = Minio("s3.amazonaws.com", "ACCESS-KEY", "SECRET-KEY")
# Create client with access key and secret key with specific region.
client = Minio(
"play.minio.io:9000",
access_key="Q3AM3UQ867SPQQA43P2F",
secret_key="zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG",
region="my-region",
)
# Create client with custom HTTP client using proxy server.
import urllib3
client = Minio(
"SERVER:PORT",
access_key="ACCESS_KEY",
secret_key="SECRET_KEY",
secure=True,
http_client=urllib3.ProxyManager(
"https://PROXYSERVER:PROXYPORT/",
timeout=urllib3.Timeout.DEFAULT_TIMEOUT,
cert_reqs="CERT_REQUIRED",
retries=urllib3.Retry(
total=5,
backoff_factor=0.2,
status_forcelist=[500, 502, 503, 504],
),
),
)
Bucket operations |
Object operations |
---|---|
Create a bucket with region and object lock.
Parameters
Param |
Type |
Description |
---|---|---|
|
str |
Name of the bucket. |
|
str |
Region in which the bucket will be created. |
|
bool |
Flag to set object-lock feature. |
Example
# Create bucket.
client.make_bucket("my-bucket")
# Create bucket on specific region.
client.make_bucket("my-bucket", "us-west-1")
# Create bucket with object-lock feature on specific region.
client.make_bucket("my-bucket", "eu-west-2", object_lock=True)
List information of all accessible buckets.
Parameters
Return |
---|
List of Bucket |
Example
buckets = client.list_buckets()
for bucket in buckets:
print(bucket.name, bucket.creation_date)
Check if a bucket exists.
Parameters
Param |
Type |
Description |
---|---|---|
|
str |
Name of the bucket. |
Example
if client.bucket_exists("my-bucket"):
print("my-bucket exists")
else:
print("my-bucket does not exist")
Remove an empty bucket.
Parameters
Param |
Type |
Description |
---|---|---|
|
str |
Name of the bucket. |
Example
client.remove_bucket("my-bucket")
Lists object information of a bucket.
Parameters
Param |
Type |
Description |
---|---|---|
|
str |
Name of the bucket. |
|
str |
Object name starts with prefix. |
|
bool |
List recursively than directory structure emulation. |
|
str |
List objects after this key name. |
|
bool |
MinIO specific flag to control to include user metadata. |
|
bool |
Flag to control whether include object versions. |
|
bool |
Flag to control to use ListObjectV1 S3 API or not. |
|
bool |
Flag to control whether URL encoding type to be used or not. |
Return Value
Return |
---|
An iterator of Object |
Example
# List objects information.
objects = client.list_objects("my-bucket")
for obj in objects:
print(obj)
# List objects information whose names starts with "my/prefix/".
objects = client.list_objects("my-bucket", prefix="my/prefix/")
for obj in objects:
print(obj)
# List objects information recursively.
objects = client.list_objects("my-bucket", recursive=True)
for obj in objects:
print(obj)
# List objects information recursively whose names starts with
# "my/prefix/".
objects = client.list_objects(
"my-bucket", prefix="my/prefix/", recursive=True,
)
for obj in objects:
print(obj)
# List objects information recursively after object name
# "my/prefix/world/1".
objects = client.list_objects(
"my-bucket", recursive=True, start_after="my/prefix/world/1",
)
for obj in objects:
print(obj)
Get bucket policy configuration of a bucket.
Parameters
Param |
Type |
Description |
---|---|---|
|
str |
Name of the bucket. |
Return Value
Param |
---|
Bucket policy configuration as JSON string. |
Example
policy = client.get_bucket_policy("my-bucket")
Set bucket policy configuration to a bucket.
Parameters
Param |
Type |
Description |
---|---|---|
|
str |
Name of the bucket. |
|
str |
Bucket policy configuration as JSON string. |
Example
# Example anonymous read-only bucket policy.
policy = {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {"AWS": "*"},
"Action": ["s3:GetBucketLocation", "s3:ListBucket"],
"Resource": "arn:aws:s3:::my-bucket",
},
{
"Effect": "Allow",
"Principal": {"AWS": "*"},
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::my-bucket/*",
},
],
}
client.set_bucket_policy("my-bucket", json.dumps(policy))
# Example anonymous read-write bucket policy.
policy = {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {"AWS": "*"},
"Action": [
"s3:GetBucketLocation",
"s3:ListBucket",
"s3:ListBucketMultipartUploads",
],
"Resource": "arn:aws:s3:::my-bucket",
},
{
"Effect": "Allow",
"Principal": {"AWS": "*"},
"Action": [
"s3:GetObject",
"s3:PutObject",
"s3:DeleteObject",
"s3:ListMultipartUploadParts",
"s3:AbortMultipartUpload",
],
"Resource": "arn:aws:s3:::my-bucket/images/*",
},
],
}
client.set_bucket_policy("my-bucket", json.dumps(policy))
Delete bucket policy configuration of a bucket.
Parameters
Param |
Type |
Description |
---|---|---|
|
str |
Name of the bucket. |
Example
client.delete_bucket_policy("my-bucket")
Get notification configuration of a bucket.
Parameters
Param |
Type |
Description |
---|---|---|
|
str |
Name of the bucket. |
Return Value
Param |
---|
NotificationConfig object. |
Example
config = client.get_bucket_notification("my-bucket")
Set notification configuration of a bucket.
Parameters
Param |
Type |
Description |
---|---|---|
|
str |
Name of the bucket. |
|
NotificationConfig |
Notification configuration. |
Example
config = NotificationConfig(
queue_config_list=[
QueueConfig(
"QUEUE-ARN-OF-THIS-BUCKET",
["s3:ObjectCreated:*"],
config_id="1",
prefix_filter_rule=PrefixFilterRule("abc"),
),
],
)
client.set_bucket_notification("my-bucket", config)
Delete notification configuration of a bucket. On success, S3 service stops notification of events previously set of the bucket.
Parameters
Param |
Type |
Description |
---|---|---|
|
str |
Name of the bucket. |
Example
client.delete_bucket_notification("my-bucket")
Listen events of object prefix and suffix of a bucket. Caller should iterate returned iterator to read new events.
Parameters
Param |
Type |
Description |
---|---|---|
|
str |
Name of the bucket. |
|
str |
Listen events of object starts with prefix. |
|
str |
Listen events of object ends with suffix. |
|
list |
Events to listen. |
Return Value
Param |
---|
Iterator of event records as dict |
with client.listen_bucket_notification(
"my-bucket",
prefix="my-prefix/",
events=["s3:ObjectCreated:*", "s3:ObjectRemoved:*"],
) as events:
for event in events:
print(event)
Get encryption configuration of a bucket.
Parameters
Param |
Type |
Description |
---|---|---|
|
str |
Name of the bucket. |
Return Value
Param |
---|
SSEConfig object. |
Example
config = client.get_bucket_encryption("my-bucket")
Set encryption configuration of a bucket.
Parameters
Param |
Type |
Description |
---|---|---|
|
str |
Name of the bucket. |
|
SSEConfig |
Server-side encryption configuration. |
Example
client.set_bucket_encryption(
"my-bucket", SSEConfig(Rule.new_sse_s3_rule()),
)
Delete encryption configuration of a bucket.
Parameters
Param |
Type |
Description |
---|---|---|
|
str |
Name of the bucket. |
Example
client.delete_bucket_encryption("my-bucket")
Get versioning configuration of a bucket.
Parameters
Param |
Type |
Description |
---|---|---|
|
str |
Name of the bucket. |
Example
config = client.get_bucket_versioning("my-bucket")
print(config.status)
Set versioning configuration to a bucket.
Parameters
Param |
Type |
Description |
---|---|---|
|
str |
Name of the bucket. |
|
VersioningConfig |
Versioning configuration. |
Example
client.set_bucket_versioning("my-bucket", VersioningConfig(ENABLED))
Delete replication configuration of a bucket.
Parameters
Param |
Type |
Description |
---|---|---|
|
str |
Name of the bucket. |
Example
client.delete_bucket_replication("my-bucket")
Get replication configuration of a bucket.
Parameters
Param |
Type |
Description |
---|---|---|
|
str |
Name of the bucket. |
Return |
---|
ReplicationConfig object. |
Example
config = client.get_bucket_replication("my-bucket")
Set replication configuration to a bucket.
Parameters
Param |
Type |
Description |
---|---|---|
|
str |
Name of the bucket. |
|
ReplicationConfig |
Replication configuration. |
Example
config = ReplicationConfig(
"REPLACE-WITH-ACTUAL-ROLE",
[
Rule(
Destination(
"REPLACE-WITH-ACTUAL-DESTINATION-BUCKET-ARN",
),
ENABLED,
delete_marker_replication=DeleteMarkerReplication(
DISABLED,
),
rule_filter=Filter(
AndOperator(
"TaxDocs",
{"key1": "value1", "key2": "value2"},
),
),
rule_id="rule1",
priority=1,
),
],
)
client.set_bucket_replication("my-bucket", config)
Delete lifecycle configuration of a bucket.
Parameters
Param |
Type |
Description |
---|---|---|
|
str |
Name of the bucket. |
Example
client.delete_bucket_lifecycle("my-bucket")
Get lifecycle configuration of a bucket.
Parameters
Param |
Type |
Description |
---|---|---|
|
str |
Name of the bucket. |
Return |
---|
LifecycleConfig object. |
Example
config = client.get_bucket_lifecycle("my-bucket")
Set lifecycle configuration to a bucket.
Parameters
Param |
Type |
Description |
---|---|---|
|
str |
Name of the bucket. |
|
LifecycleConfig |
Lifecycle configuration. |
Example
config = LifecycleConfig(
[
Rule(
ENABLED,
rule_filter=Filter(prefix="documents/"),
rule_id="rule1",
transition=Transition(days=30, storage_class="GLACIER"),
),
Rule(
ENABLED,
rule_filter=Filter(prefix="logs/"),
rule_id="rule2",
expiration=Expiration(days=365),
),
],
)
client.set_bucket_lifecycle("my-bucket", config)
Delete tags configuration of a bucket.
Parameters
Param |
Type |
Description |
---|---|---|
|
str |
Name of the bucket. |
Example
client.delete_bucket_tags("my-bucket")
Get tags configuration of a bucket.
Parameters
Param |
Type |
Description |
---|---|---|
|
str |
Name of the bucket. |
Return |
---|
Tags object. |
Example
tags = client.get_bucket_tags("my-bucket")
Set tags configuration to a bucket.
Parameters
Param |
Type |
Description |
---|---|---|
|
str |
Name of the bucket. |
|
Tags |
Tags configuration. |
Example
tags = Tags.new_bucket_tags()
tags["Project"] = "Project One"
tags["User"] = "jsmith"
client.set_bucket_tags("my-bucket", tags)
Delete object-lock configuration of a bucket.
Parameters
Param |
Type |
Description |
---|---|---|
|
str |
Name of the bucket. |
Example
client.delete_object_lock_config("my-bucket")
Get object-lock configuration of a bucket.
Parameters
Param |
Type |
Description |
---|---|---|
|
str |
Name of the bucket. |
Return |
---|
ObjectLockConfig object. |
Example
config = client.get_object_lock_config("my-bucket")
Set object-lock configuration to a bucket.
Parameters
Param |
Type |
Description |
---|---|---|
|
str |
Name of the bucket. |
|
ObjectLockConfig |
Object-Lock configuration. |
Example
config = ObjectLockConfig(GOVERNANCE, 15, DAYS)
client.set_object_lock_config("my-bucket", config)
Gets data from offset to length of an object. Returned response should be closed after use to release network resources. To reuse the connection, it’s required to call response.release_conn()
explicitly.
Parameters
Param |
Type |
Description |
---|---|---|
|
str |
Name of the bucket. |
|
str |
Object name in the bucket. |
|
int |
Start byte position of object data. |
|
int |
Number of bytes of object data from offset. |
|
dict |
Any additional headers to be added with GET request. |
|
SseCustomerKey |
Server-side encryption customer key. |
|
str |
Version-ID of the object. |
|
dict |
Extra query parameters for advanced usage. |
Return Value
Return |
---|
urllib3.response.HTTPResponse object. |
Example
# Get data of an object.
try:
response = client.get_object("my-bucket", "my-object")
# Read data from response.
finally:
response.close()
response.release_conn()
# Get data of an object of version-ID.
try:
response = client.get_object(
"my-bucket", "my-object",
version_id="dfbd25b3-abec-4184-a4e8-5a35a5c1174d",
)
# Read data from response.
finally:
response.close()
response.release_conn()
# Get data of an object from offset and length.
try:
response = client.get_object(
"my-bucket", "my-object", offset=512, length=1024,
)
# Read data from response.
finally:
response.close()
response.release_conn()
# Get data of an SSE-C encrypted object.
try:
response = client.get_object(
"my-bucket", "my-object",
ssec=SseCustomerKey(b"32byteslongsecretkeymustprovided"),
)
# Read data from response.
finally:
response.close()
response.release_conn()
Select content of an object by SQL expression.
Parameters
Param |
Type |
Description |
---|---|---|
|
str |
Name of the bucket. |
|
str |
Object name in the bucket. |
|
SelectRequest |
Select request. |
Return Value
Return |
---|
A reader contains requested records and progress information as SelectObjectReader |
Example
with client.select_object_content(
"my-bucket",
"my-object.csv",
SelectRequest(
"select * from S3Object",
CSVInputSerialization(),
CSVOutputSerialization(),
request_progress=True,
),
) as result:
for data in result.stream():
print(data.decode())
print(result.stats())
Downloads data of an object to file.
Parameters
Param |
Type |
Description |
---|---|---|
|
str |
Name of the bucket. |
|
str |
Object name in the bucket. |
|
str |
Name of file to download. |
|
dict |
Any additional headers to be added with GET request. |
|
SseCustomerKey |
Server-side encryption customer key. |
|
str |
Version-ID of the object. |
|
dict |
Extra query parameters for advanced usage. |
|
str |
Path to a temporary file. |
Return Value
Return |
---|
Object information as Object |
Example
# Download data of an object.
client.fget_object("my-bucket", "my-object", "my-filename")
# Download data of an object of version-ID.
client.fget_object(
"my-bucket", "my-object", "my-filename",
version_id="dfbd25b3-abec-4184-a4e8-5a35a5c1174d",
)
# Download data of an SSE-C encrypted object.
client.fget_object(
"my-bucket", "my-object", "my-filename",
ssec=SseCustomerKey(b"32byteslongsecretkeymustprovided"),
)
Create an object by server-side copying data from another object. In this API maximum supported source object size is 5GiB.
Parameters
Param |
Type |
Description |
---|---|---|
|
str |
Name of the bucket. |
|
str |
Object name in the bucket. |
|
CopySource |
Source object information. |
|
Sse |
Server-side encryption of destination object. |
|
dict |
Any user-defined metadata to be copied along with destination object. |
|
Tags |
Tags for destination object. |
|
Retention |
Retention configuration. |
|
bool |
Flag to set legal hold for destination object. |
|
str |
Directive used to handle user metadata for destination object. |
|
str |
Directive used to handle tags for destination object. |
Return Value
Return |
---|
ObjectWriteResult object. |
Example
from datetime import datetime, timezone
from minio.commonconfig import REPLACE, CopySource
# copy an object from a bucket to another.
result = client.copy_object(
"my-bucket",
"my-object",
CopySource("my-sourcebucket", "my-sourceobject"),
)
print(result.object_name, result.version_id)
# copy an object with condition.
result = client.copy_object(
"my-bucket",
"my-object",
CopySource(
"my-sourcebucket",
"my-sourceobject",
modified_since=datetime(2014, 4, 1, tzinfo=timezone.utc),
),
)
print(result.object_name, result.version_id)
# copy an object from a bucket with replacing metadata.
metadata = {"test_meta_key": "test_meta_value"}
result = client.copy_object(
"my-bucket",
"my-object",
CopySource("my-sourcebucket", "my-sourceobject"),
metadata=metadata,
metadata_directive=REPLACE,
)
print(result.object_name, result.version_id)
Create an object by combining data from different source objects using server-side copy.
Parameters
Param |
Type |
Description |
---|---|---|
|
str |
Name of the bucket. |
|
str |
Object name in the bucket. |
|
list |
List of ComposeSource object. |
|
Sse |
Server-side encryption of destination object. |
|
dict |
Any user-defined metadata to be copied along with destination object. |
|
Tags |
Tags for destination object. |
|
Retention |
Retention configuration. |
|
bool |
Flag to set legal hold for destination object. |
Return Value
Return |
---|
ObjectWriteResult object. |
Example
from minio.commonconfig import ComposeSource
from minio.sse import SseS3
sources = [
ComposeSource("my-job-bucket", "my-object-part-one"),
ComposeSource("my-job-bucket", "my-object-part-two"),
ComposeSource("my-job-bucket", "my-object-part-three"),
]
# Create my-bucket/my-object by combining source object
# list.
result = client.compose_object("my-bucket", "my-object", sources)
print(result.object_name, result.version_id)
# Create my-bucket/my-object with user metadata by combining
# source object list.
result = client.compose_object(
"my-bucket",
"my-object",
sources,
metadata={"test_meta_key": "test_meta_value"},
)
print(result.object_name, result.version_id)
# Create my-bucket/my-object with user metadata and
# server-side encryption by combining source object list.
client.compose_object("my-bucket", "my-object", sources, sse=SseS3())
print(result.object_name, result.version_id)
Uploads data from a stream to an object in a bucket.
Parameters
Param |
Type |
Description |
---|---|---|
|
str |
Name of the bucket. |
|
str |
Object name in the bucket. |
|
object |
An object having callable read() returning bytes object. |
|
int |
Data size; -1 for unknown size and set valid part_size. |
|
str |
Content type of the object. |
|
dict |
Any additional metadata to be uploaded along with your PUT request. |
|
Sse |
Server-side encryption. |
|
threading |
A progress object. |
|
int |
Multipart part size. |
|
Tags |
Tags for the object. |
|
Retention |
Retention configuration. |
|
bool |
Flag to set legal hold for the object. |
Return Value
Return |
---|
ObjectWriteResult object. |
Example
# Upload data.
result = client.put_object(
"my-bucket", "my-object", io.BytesIO(b"hello"), 5,
)
print(
"created {0} object; etag: {1}, version-id: {2}".format(
result.object_name, result.etag, result.version_id,
),
)
# Upload unknown sized data.
data = urlopen(
"https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.4.81.tar.xz",
)
result = client.put_object(
"my-bucket", "my-object", data, length=-1, part_size=10*1024*1024,
)
print(
"created {0} object; etag: {1}, version-id: {2}".format(
result.object_name, result.etag, result.version_id,
),
)
# Upload data with content-type.
result = client.put_object(
"my-bucket", "my-object", io.BytesIO(b"hello"), 5,
content_type="application/csv",
)
print(
"created {0} object; etag: {1}, version-id: {2}".format(
result.object_name, result.etag, result.version_id,
),
)
# Upload data with metadata.
result = client.put_object(
"my-bucket", "my-object", io.BytesIO(b"hello"), 5,
metadata={"My-Project": "one"},
)
print(
"created {0} object; etag: {1}, version-id: {2}".format(
result.object_name, result.etag, result.version_id,
),
)
# Upload data with customer key type of server-side encryption.
result = client.put_object(
"my-bucket", "my-object", io.BytesIO(b"hello"), 5,
sse=SseCustomerKey(b"32byteslongsecretkeymustprovided"),
)
print(
"created {0} object; etag: {1}, version-id: {2}".format(
result.object_name, result.etag, result.version_id,
),
)
# Upload data with KMS type of server-side encryption.
result = client.put_object(
"my-bucket", "my-object", io.BytesIO(b"hello"), 5,
sse=SseKMS("KMS-KEY-ID", {"Key1": "Value1", "Key2": "Value2"}),
)
print(
"created {0} object; etag: {1}, version-id: {2}".format(
result.object_name, result.etag, result.version_id,
),
)
# Upload data with S3 type of server-side encryption.
result = client.put_object(
"my-bucket", "my-object", io.BytesIO(b"hello"), 5,
sse=SseS3(),
)
print(
"created {0} object; etag: {1}, version-id: {2}".format(
result.object_name, result.etag, result.version_id,
),
)
# Upload data with tags, retention and legal-hold.
date = datetime.utcnow().replace(
hour=0, minute=0, second=0, microsecond=0,
) + timedelta(days=30)
tags = Tags(for_object=True)
tags["User"] = "jsmith"
result = client.put_object(
"my-bucket", "my-object", io.BytesIO(b"hello"), 5,
tags=tags,
retention=Retention(GOVERNANCE, date),
legal_hold=True,
)
print(
"created {0} object; etag: {1}, version-id: {2}".format(
result.object_name, result.etag, result.version_id,
),
)
# Upload data with progress bar.
result = client.put_object(
"my-bucket", "my-object", io.BytesIO(b"hello"), 5,
progress=Progress(),
)
print(
"created {0} object; etag: {1}, version-id: {2}".format(
result.object_name, result.etag, result.version_id,
),
)
Uploads data from a file to an object in a bucket.
Param |
Type |
Description |
---|---|---|
|
str |
Name of the bucket. |
|
str |
Object name in the bucket. |
|
str |
Name of file to upload. |
|
str |
Content type of the object. |
|
dict |
Any additional metadata to be uploaded along with your PUT request. |
|
Sse |
Server-side encryption. |
|
threading |
A progress object. |
|
int |
Multipart part size. |
|
Tags |
Tags for the object. |
|
Retention |
Retention configuration. |
|
bool |
Flag to set legal hold for the object. |
Return Value
Return |
---|
ObjectWriteResult object. |
Example
# Upload data.
result = client.fput_object(
"my-bucket", "my-object", "my-filename",
)
print(
"created {0} object; etag: {1}, version-id: {2}".format(
result.object_name, result.etag, result.version_id,
),
)
# Upload data with content-type.
result = client.fput_object(
"my-bucket", "my-object", "my-filename",
content_type="application/csv",
)
print(
"created {0} object; etag: {1}, version-id: {2}".format(
result.object_name, result.etag, result.version_id,
),
)
# Upload data with metadata.
result = client.fput_object(
"my-bucket", "my-object", "my-filename",
metadata={"My-Project": "one"},
)
print(
"created {0} object; etag: {1}, version-id: {2}".format(
result.object_name, result.etag, result.version_id,
),
)
# Upload data with customer key type of server-side encryption.
result = client.fput_object(
"my-bucket", "my-object", "my-filename",
sse=SseCustomerKey(b"32byteslongsecretkeymustprovided"),
)
print(
"created {0} object; etag: {1}, version-id: {2}".format(
result.object_name, result.etag, result.version_id,
),
)
# Upload data with KMS type of server-side encryption.
result = client.fput_object(
"my-bucket", "my-object", "my-filename",
sse=SseKMS("KMS-KEY-ID", {"Key1": "Value1", "Key2": "Value2"}),
)
print(
"created {0} object; etag: {1}, version-id: {2}".format(
result.object_name, result.etag, result.version_id,
),
)
# Upload data with S3 type of server-side encryption.
result = client.fput_object(
"my-bucket", "my-object", "my-filename",
sse=SseS3(),
)
print(
"created {0} object; etag: {1}, version-id: {2}".format(
result.object_name, result.etag, result.version_id,
),
)
# Upload data with tags, retention and legal-hold.
date = datetime.utcnow().replace(
hour=0, minute=0, second=0, microsecond=0,
) + timedelta(days=30)
tags = Tags(for_object=True)
tags["User"] = "jsmith"
result = client.fput_object(
"my-bucket", "my-object", "my-filename",
tags=tags,
retention=Retention(GOVERNANCE, date),
legal_hold=True,
)
print(
"created {0} object; etag: {1}, version-id: {2}".format(
result.object_name, result.etag, result.version_id,
),
)
# Upload data with progress bar.
result = client.fput_object(
"my-bucket", "my-object", "my-filename",
progress=Progress(),
)
print(
"created {0} object; etag: {1}, version-id: {2}".format(
result.object_name, result.etag, result.version_id,
),
)
Get object information and metadata of an object.
Parameters
Param |
Type |
Description |
---|---|---|
|
str |
Name of the bucket. |
|
str |
Object name in the bucket. |
|
SseCustomerKey |
Server-side encryption customer key. |
|
str |
Version ID of the object. |
|
dict |
Extra query parameters for advanced usage. |
Return Value
Return |
---|
Object information as Object |
Example
# Get object information.
result = client.stat_object("my-bucket", "my-object")
print(
"last-modified: {0}, size: {1}".format(
result.last_modified, result.size,
),
)
# Get object information of version-ID.
result = client.stat_object(
"my-bucket", "my-object",
version_id="dfbd25b3-abec-4184-a4e8-5a35a5c1174d",
)
print(
"last-modified: {0}, size: {1}".format(
result.last_modified, result.size,
),
)
# Get SSE-C encrypted object information.
result = client.stat_object(
"my-bucket", "my-object",
ssec=SseCustomerKey(b"32byteslongsecretkeymustprovided"),
)
print(
"last-modified: {0}, size: {1}".format(
result.last_modified, result.size,
),
)
Remove an object.
Parameters
Param |
Type |
Description |
---|---|---|
|
str |
Name of the bucket. |
|
str |
Object name in the bucket. |
|
str |
Version ID of the object. |
Example
# Remove object.
client.remove_object("my-bucket", "my-object")
# Remove version of an object.
client.remove_object(
"my-bucket", "my-object",
version_id="dfbd25b3-abec-4184-a4e8-5a35a5c1174d",
)
Remove multiple objects.
Parameters
Param |
Type |
Description |
---|---|---|
|
str |
Name of the bucket. |
|
iterable |
An iterable containing :class: |
|
bool |
Bypass Governance retention mode. |
Return Value
Return |
---|
An iterator containing :class: |
Example
# Remove list of objects.
errors = client.remove_objects(
"my-bucket",
[
DeleteObject("my-object1"),
DeleteObject("my-object2"),
DeleteObject("my-object3", "13f88b18-8dcd-4c83-88f2-8631fdb6250c"),
],
)
for error in errors:
print("error occured when deleting object", error)
# Remove a prefix recursively.
delete_object_list = map(
lambda x: DeleteObject(x.object_name),
client.list_objects("my-bucket", "my/prefix/", recursive=True),
)
errors = client.remove_objects("my-bucket", delete_object_list)
for error in errors:
print("error occured when deleting object", error)
Delete tags configuration of an object.
Parameters
Param |
Type |
Description |
---|---|---|
|
str |
Name of the bucket. |
|
str |
Object name in the bucket. |
|
str |
Version ID of the object. |
Example
client.delete_object_tags("my-bucket", "my-object")
Get tags configuration of an object.
Parameters
Param |
Type |
Description |
---|---|---|
|
str |
Name of the bucket. |
|
str |
Object name in the bucket. |
|
str |
Version ID of the object. |
Return |
---|
Tags object. |
Example
tags = client.get_object_tags("my-bucket", "my-object")
Set tags configuration to an object.
Parameters
Param |
Type |
Description |
---|---|---|
|
str |
Name of the bucket. |
|
str |
Object name in the bucket. |
|
Tags |
Tags configuration. |
|
str |
Version ID of the object. |
Example
tags = Tags.new_object_tags()
tags["Project"] = "Project One"
tags["User"] = "jsmith"
client.set_object_tags("my-bucket", "my-object", tags)
Enable legal hold on an object.
Parameters
Param |
Type |
Description |
---|---|---|
|
str |
Name of the bucket. |
|
str |
Object name in the bucket. |
|
str |
Version ID of the object. |
Example
client.enable_object_legal_hold("my-bucket", "my-object")
Disable legal hold on an object.
Parameters
Param |
Type |
Description |
---|---|---|
|
str |
Name of the bucket. |
|
str |
Object name in the bucket. |
|
str |
Version ID of the object. |
Example
client.disable_object_legal_hold("my-bucket", "my-object")
Returns true if legal hold is enabled on an object.
Parameters
Param |
Type |
Description |
---|---|---|
|
str |
Name of the bucket. |
|
str |
Object name in the bucket. |
|
str |
Version ID of the object. |
Example
if client.is_object_legal_hold_enabled("my-bucket", "my-object"):
print("legal hold is enabled on my-object")
else:
print("legal hold is not enabled on my-object")
Get retention information of an object.
Parameters
Param |
Type |
Description |
---|---|---|
|
str |
Name of the bucket. |
|
str |
Object name in the bucket. |
|
str |
Version ID of the object. |
Return Value
Return |
---|
Retention object |
Example
config = client.get_object_retention("my-bucket", "my-object")
Set retention information to an object.
Parameters
Param |
Type |
Description |
---|---|---|
|
str |
Name of the bucket. |
|
str |
Object name in the bucket. |
|
Retention |
Retention configuration. |
|
str |
Version ID of the object. |
Example
config = Retention(GOVERNANCE, datetime.utcnow() + timedelta(days=10))
client.set_object_retention("my-bucket", "my-object", config)
Get presigned URL of an object to download its data with expiry time and custom request parameters.
Parameters
Param |
Type |
Description |
---|---|---|
|
str |
Name of the bucket. |
|
str |
Object name in the bucket. |
|
datetime.timedelta |
Expiry in seconds; defaults to 7 days. |
|
dict |
Optional response_headers argument to specify response fields like date, size, type of file, data about server, etc. |
|
datetime.datetime |
Optional request_date argument to specify a different request date. Default is current date. |
|
str |
Version ID of the object. |
|
dict |
Extra query parameters for advanced usage. |
Return Value
Return |
---|
URL string |
Example
# Get presigned URL string to download 'my-object' in
# 'my-bucket' with default expiry (i.e. 7 days).
url = client.presigned_get_object("my-bucket", "my-object")
print(url)
# Get presigned URL string to download 'my-object' in
# 'my-bucket' with two hours expiry.
url = client.presigned_get_object(
"my-bucket", "my-object", expires=timedelta(hours=2),
)
print(url)
Get presigned URL of an object to upload data with expiry time and custom request parameters.
Parameters
Param |
Type |
Description |
---|---|---|
|
str |
Name of the bucket. |
|
str |
Object name in the bucket. |
|
datetime.timedelta |
Expiry in seconds; defaults to 7 days. |
Return Value
Return |
---|
URL string |
Example
# Get presigned URL string to upload data to 'my-object' in
# 'my-bucket' with default expiry (i.e. 7 days).
url = client.presigned_put_object("my-bucket", "my-object")
print(url)
# Get presigned URL string to upload data to 'my-object' in
# 'my-bucket' with two hours expiry.
url = client.presigned_put_object(
"my-bucket", "my-object", expires=timedelta(hours=2),
)
print(url)
Get form-data of PostPolicy of an object to upload its data using POST method.
Parameters
Param |
Type |
Description |
---|---|---|
|
PostPolicy |
Post policy. |
Return Value
Return |
---|
Form-data containing dict |
Example
policy = PostPolicy(
"my-bucket", datetime.utcnow() + timedelta(days=10),
)
policy.add_starts_with_condition("key", "my/object/prefix/")
policy.add_content_length_range_condition(
1*1024*1024, 10*1024*1024,
)
form_data = client.presigned_post_policy(policy)
Get presigned URL of an object for HTTP method, expiry time and custom request parameters.
Parameters
Param |
Type |
Description |
---|---|---|
|
str |
HTTP method. |
|
str |
Name of the bucket. |
|
str |
Object name in the bucket. |
|
datetime.timedelta |
Expiry in seconds; defaults to 7 days. |
|
dict |
Optional response_headers argument to specify response fields like date, size, type of file, data about server, etc. |
|
datetime.datetime |
Optional request_date argument to specify a different request date. Default is current date. |
|
str |
Version ID of the object. |
|
dict |
Extra query parameters for advanced usage. |
Return Value
Return |
---|
URL string |
Example
# Get presigned URL string to delete 'my-object' in
# 'my-bucket' with one day expiry.
url = client.get_presigned_url(
"DELETE",
"my-bucket",
"my-object",
expires=timedelta(days=1),
)
print(url)
# Get presigned URL string to upload 'my-object' in
# 'my-bucket' with response-content-type as application/json
# and one day expiry.
url = client.get_presigned_url(
"PUT",
"my-bucket",
"my-object",
expires=timedelta(days=1),
response_headers={"response-content-type": "application/json"},
)
print(url)
# Get presigned URL string to download 'my-object' in
# 'my-bucket' with two hours expiry.
url = client.get_presigned_url(
"GET",
"my-bucket",
"my-object",
expires=timedelta(hours=2),
)
print(url)
This work is licensed under a Creative Commons Attribution 4.0 International License.
©2020-Present, MinIO, Inc.