### Quick Start with asyncio Source: https://github.com/hlf20010508/miniopy-async/blob/master/README.md Use the async context manager to create a Minio client and generate a presigned GET URL for an object. ```py from miniopy_async import Minio import asyncio async def main(): async with Minio( "play.min.io", access_key="Q3AM3UQ867SPQQA43P2F", secret_key="zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG", secure=True, # http for False, https for True ) as client: url = await client.presigned_get_object("my-bucket", "my-object") print("url:", url) asyncio.run(main()) ``` -------------------------------- ### Sanic Web Server Example Source: https://github.com/hlf20010508/miniopy-async/blob/master/README.md Create a Sanic web server that redirects to a presigned GET URL for a specified bucket and file. The client is closed after the server stops. ```py from sanic import Sanic, response from miniopy_async import Minio from urllib import parse app = Sanic(__name__) client = Minio( "play.min.io", access_key="Q3AM3UQ867SPQQA43P2F", secret_key="zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG", secure=True, # http for False, https for True ) # http://127.0.0.1:8000/download?bucket=my-bucket&fileName=testfile @app.route("/download", methods=["GET"]) async def download(request): print("downloading ...") bucket = request.args.get("bucket") fileName = request.args.get("fileName") # decodeURI, for those which has other language in fileName, such as Chinese, Japanese, Korean fileName = parse.unquote(fileName) url = await client.presigned_get_object(bucket_name=bucket, object_name=fileName) return response.redirect(url) @app.after_server_stop async def close_minio_client(*_): await client.close_session() ``` -------------------------------- ### Install from PyPI Source: https://github.com/hlf20010508/miniopy-async/blob/master/README.md Install the package from PyPI using pip. ```sh pip install miniopy-async ``` -------------------------------- ### Install from GitHub Repository Source: https://github.com/hlf20010508/miniopy-async/blob/master/README.md Install the package directly from the GitHub repository using pip. ```sh pip install git+https://github.com/hlf20010508/miniopy-async.git ``` -------------------------------- ### Install with pipenv from GitHub Source: https://github.com/hlf20010508/miniopy-async/wiki/Readme Install the package from the GitHub repository using pipenv. ```sh pipenv install git+https://github.com/hlf20010508/miniopy-async.git#egg=miniopy-async ``` -------------------------------- ### Install with pipenv from PyPI Source: https://github.com/hlf20010508/miniopy-async/wiki/Readme Install the package from PyPI using pipenv. ```sh pipenv install miniopy-async ``` -------------------------------- ### stat_object example with Minio client Source: https://github.com/hlf20010508/miniopy-async/wiki/API Shows how to use stat_object to get object information, including version ID and SSE-C encryption. Requires a Minio client and an async main function. ```python from miniopy_async import Minio from miniopy_async.sse import SseCustomerKey import asyncio client = Minio( "play.min.io", access_key="Q3AM3UQ867SPQQA43P2F", secret_key="zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG", secure=True # http for False, https for True ) async def main(): # Get object information. print('example one') result = await client.stat_object("my-bucket", "my-object") print( "status: last-modified: {0}, size: {1}".format( result.last_modified, result.size, ), ) # Get object information of version-ID. print('example two') result = await client.stat_object( "my-bucket", "my-object", version_id="dfbd25b3-abec-4184-a4e8-5a35a5c1174d", ) print( "status: last-modified: {0}, size: {1}".format( result.last_modified, result.size, ), ) # Get SSE-C encrypted object information. print('example three') result = await client.stat_object( "my-bucket", "my-object", ssec=SseCustomerKey(b"32byteslongsecretkeymustprovided"), ) print( "status: last-modified: {0}, size: {1}".format( result.last_modified, result.size, ), ) loop = asyncio.get_event_loop() loop.run_until_complete(main()) loop.close() ``` -------------------------------- ### Build from source Source: https://github.com/hlf20010508/miniopy-async/wiki/Readme Clone the repository and install the package using setup.py. ```sh git clone https://github.com/hlf20010508/miniopy-async.git cd miniopy-async python setup.py install ``` -------------------------------- ### delete_bucket_lifecycle example Source: https://github.com/hlf20010508/miniopy-async/wiki/API Deletes the lifecycle configuration of a bucket. Requires an async main function and event loop setup. ```python from miniopy_async import Minio import asyncio client = Minio( "play.min.io", access_key="Q3AM3UQ867SPQQA43P2F", secret_key="zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG", secure=True # http for False, https for True ) async def main(): await client.delete_bucket_lifecycle("my-bucket") loop = asyncio.get_event_loop() loop.run_until_complete(main()) loop.close() ``` -------------------------------- ### presigned_get_object usage example Source: https://github.com/hlf20010508/miniopy-async/blob/master/_autodocs/api-reference/minio.md Thin wrapper for get_presigned_url("GET", ...) with the same signature minus method; default expiry 7 days. This example generates a presigned GET URL with a 2-hour expiry. ```python url = await client.presigned_get_object( "my-bucket", "my-object", expires=timedelta(hours=2) ) ``` -------------------------------- ### Build from Source Source: https://github.com/hlf20010508/miniopy-async/blob/master/README.md Clone the repository and install dependencies with Poetry, then build the package. ```sh git clone https://github.com/hlf20010508/miniopy-async.git cd miniopy-async poetry install poetry build ``` -------------------------------- ### fput_object upload example with all options Source: https://github.com/hlf20010508/miniopy-async/wiki/API Complete async example for uploading a file with miniopy_async Minio client. Shows basic upload, content-type, metadata, SSE (SseCustomerKey, SseKMS, SseS3), tags with retention and legal hold, and progress. Requires a running MinIO server and valid credentials. ```python from datetime import datetime, timedelta from miniopy_async import Minio from miniopy_async.commonconfig import GOVERNANCE, Tags from miniopy_async.retention import Retention from miniopy_async.sse import SseCustomerKey, SseKMS, SseS3 import asyncio client = Minio( "play.min.io", access_key="Q3AM3UQ867SPQQA43P2F", secret_key="zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG", secure=True # http for False, https for True ) async def main(): # Upload data. print("example one") result = await client.fput_object( "my-bucket", "my-object1", "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. print("example two") result = await client.fput_object( "my-bucket", "my-object2", "my-filename", content_type="application/octet-stream", ) print( "created {0} object; etag: {1}, version-id: {2}".format( result.object_name, result.etag, result.version_id, ), ) # Upload data with metadata. print("example three") result = await client.fput_object( "my-bucket", "my-object3", "my-filename", metadata={"Content-Type": "application/octet-stream"}, ) 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. print("example four") result = await client.fput_object( "my-bucket", "my-object4", "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. print("example five") result = await client.fput_object( "my-bucket", "my-object5", "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. print("example six") result = await client.fput_object( "my-bucket", "my-object6", "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. print("example seven") date = datetime.utcnow().replace( hour=0, minute=0, second=0, microsecond=0, ) + timedelta(days=30) tags = Tags(for_object=True) tags["User"] = "jsmith" result = await client.fput_object( "my-bucket", "my-object7", "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 showing progress status. print("example eight") result = await client.fput_object( "my-bucket", "my-object8", "my-filename", progress=True ) print( "created {0} object; etag: {1}, version-id: {2}".format( result.object_name, result.etag, result.version_id, ), ) loop = asyncio.get_event_loop() loop.run_until_complete(main()) loop.close() ``` -------------------------------- ### presigned_post_policy example Source: https://github.com/hlf20010508/miniopy-async/wiki/API Shows how to generate form-data for a POST policy using the presigned_post_policy method. The example creates a PostPolicy with a start-with condition and a content-length range, then builds a curl command from the returned form-data. ```python from datetime import datetime, timedelta from miniopy_async import Minio from miniopy_async.datatypes import PostPolicy import asyncio client = Minio( "play.min.io", access_key="Q3AM3UQ867SPQQA43P2F", secret_key="zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG", secure=True # http for False, https for True ) 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) async def main(): form_data = await client.presigned_post_policy(policy) curl_cmd = ( "curl -X POST " "https://play.min.io/my-bucket " "{0} -F file=@" ).format( " ".join(["-F {0}={1}".format(k, v) for k, v in form_data.items()]), ) print('curl_cmd:',curl_cmd) loop = asyncio.get_event_loop() loop.run_until_complete(main()) loop.close() ``` -------------------------------- ### Get bucket encryption configuration with get_bucket_encryption Source: https://github.com/hlf20010508/miniopy-async/wiki/API Retrieves the SSEConfig object for a bucket. The example prints the configuration for 'my-bucket'. Requires an asyncio event loop to run the async main function. ```python from miniopy_async import Minio import asyncio client = Minio( "play.min.io", access_key="Q3AM3UQ867SPQQA43P2F", secret_key="zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG", secure=True # http for False, https for True ) async def main(): config = await client.get_bucket_encryption("my-bucket") print(config) loop = asyncio.get_event_loop() loop.run_until_complete(main()) loop.close() ``` -------------------------------- ### Get bucket replication with get_bucket_replication Source: https://github.com/hlf20010508/miniopy-async/wiki/API Retrieves the replication configuration for a bucket and returns a ReplicationConfig object. The example prints the returned configuration. Requires a bucket name as a string and uses the async Minio client with an asyncio event loop. ```python from miniopy_async import Minio import asyncio client = Minio( "play.min.io", access_key="Q3AM3UQ867SPQQA43P2F", secret_key="zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG", secure=True # http for False, https for True ) async def main(): config = await client.get_bucket_replication("my-bucket") print(config) loop = asyncio.get_event_loop() loop.run_until_complete(main()) loop.close() ``` -------------------------------- ### SseKMS usage example Source: https://github.com/hlf20010508/miniopy-async/blob/master/_autodocs/api-reference/sse.md Example of creating an SseKMS instance with a key ID and context. ```python sse = SseKMS("my-kms-key", {"Key1": "Value1"}) ``` -------------------------------- ### set_bucket_tags example Source: https://github.com/hlf20010508/miniopy-async/wiki/API Sets tags configuration to a bucket. Requires a bucket name and a Tags object created with Tags.new_bucket_tags(). The example sets two tags before calling the method. ```python from miniopy_async import Minio from miniopy_async.commonconfig import Tags import asyncio client = Minio( "play.min.io", access_key="Q3AM3UQ867SPQQA43P2F", secret_key="zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG", secure=True # http for False, https for True ) tags = Tags.new_bucket_tags() tags["Project"] = "Project One" tags["User"] = "jsmith" async def main(): await client.set_bucket_tags("my-bucket", tags) loop = asyncio.get_event_loop() loop.run_until_complete(main()) loop.close() ``` -------------------------------- ### list_buckets example Source: https://github.com/hlf20010508/miniopy-async/wiki/API Lists all accessible buckets and prints their name and creation date. Uses the default MinIO play server credentials. ```python from miniopy_async import Minio import asyncio client = Minio( "play.min.io", access_key="Q3AM3UQ867SPQQA43P2F", secret_key="zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG", secure=True # http for False, https for True ) async def main(): buckets = await client.list_buckets() for bucket in buckets: print(bucket.name, bucket.creation_date) loop = asyncio.get_event_loop() loop.run_until_complete(main()) loop.close() ``` -------------------------------- ### fget_object example Source: https://github.com/hlf20010508/miniopy-async/wiki/API Downloads an object to a file using the miniopy-async client. The example shows basic download, version-ID download, and SSE-C encrypted download. Requires asyncio and a Minio client instance. ```python from miniopy_async import Minio from miniopy_async.sse import SseCustomerKey import asyncio client = Minio( "play.min.io", access_key="Q3AM3UQ867SPQQA43P2F", secret_key="zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG", secure=True # http for False, https for True ) async def main(): # Download data of an object. print("example one") await client.fget_object("my-bucket", "my-object", "my-filename") # Download data of an object of version-ID. print("example two") await client.fget_object( "my-bucket", "my-object", "my-filename", version_id="dfbd25b3-abec-4184-a4e8-5a35a5c1174d", ) # Download data of an SSE-C encrypted object. print("example three") await client.fget_object( "my-bucket", "my-object", "my-filename", ssec=SseCustomerKey(b"32byteslongsecretkeymustprovided"), ) loop = asyncio.get_event_loop() loop.run_until_complete(main()) loop.close() ``` -------------------------------- ### copy_object example Source: https://github.com/hlf20010508/miniopy-async/wiki/API Demonstrates server-side copying of an object using the copy_object method. Includes three examples: basic copy, copy with a condition (modified_since), and copy with metadata replacement using REPLACE directive. Requires an asyncio event loop to run the async main function. ```python from datetime import datetime, timezone from miniopy_async import Minio from miniopy_async.commonconfig import REPLACE, CopySource import asyncio client = Minio( "play.min.io", access_key="Q3AM3UQ867SPQQA43P2F", secret_key="zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG", secure=True # http for False, https for True ) async def main(): # copy an object from a bucket to another. print("example one") result = await client.copy_object( "my-job-bucket", "my-copied-object1", CopySource("my-bucket", "my-object"), ) print(result.object_name, result.version_id) # copy an object with condition. print("example two") result = await client.copy_object( "my-job-bucket", "my-copied-object2", CopySource( "my-bucket", "my-object", 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. print("example three") metadata = {"Content-Type": "application/octet-stream"} result = await client.copy_object( "my-job-bucket", "my-copied-object3", CopySource("my-bucket", "my-object"), metadata=metadata, metadata_directive=REPLACE, ) print(result.object_name, result.version_id) loop = asyncio.get_event_loop() loop.run_until_complete(main()) loop.close() ``` -------------------------------- ### Full example with all three target types Source: https://github.com/hlf20010508/miniopy-async/blob/master/_autodocs/api-reference/notificationconfig.md Complete example creating a NotificationConfig with queue, topic, and cloud function configurations, then setting it on a bucket. Requires importing the necessary classes. ```python from miniopy_async.notificationconfig import ( CloudFuncConfig, NotificationConfig, PrefixFilterRule, QueueConfig, SuffixFilterRule, TopicConfig, ) config = NotificationConfig( queue_config_list=[ QueueConfig("arn:minio:sqs::1:redis", ["s3:ObjectCreated:*"], config_id="q1", prefix_filter_rule=PrefixFilterRule("in/")), ], topic_config_list=[ TopicConfig("arn:minio:sns::1:webhook", ["s3:ObjectRemoved:*"], config_id="t1", suffix_filter_rule=SuffixFilterRule(".jpg")), ], cloud_func_config_list=[ CloudFuncConfig("arn:aws:lambda:us-east-1:1:function:fn", ["s3:ObjectCreated:*"], config_id="c1"), ], ) await client.set_bucket_notification("my-bucket", config) ``` -------------------------------- ### SSEConfig usage example Source: https://github.com/hlf20010508/miniopy-async/blob/master/_autodocs/api-reference/sse.md Example of creating an SSEConfig with a KMS rule and setting bucket encryption. ```python from miniopy_async.sseconfig import Rule, SSEConfig config = SSEConfig(Rule.new_sse_kms_rule("kms-key-id")) await client.set_bucket_encryption("my-bucket", config) ``` -------------------------------- ### get_bucket_tags example Source: https://github.com/hlf20010508/miniopy-async/wiki/API Retrieves the tags configuration of a bucket and prints the returned Tags object. Requires the bucket name as a string. ```python from miniopy_async import Minio import asyncio client = Minio( "play.min.io", access_key="Q3AM3UQ867SPQQA43P2F", secret_key="zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG", secure=True # http for False, https for True ) async def main(): tags = await client.get_bucket_tags("my-bucket") print(tags) loop = asyncio.get_event_loop() loop.run_until_complete(main()) loop.close() ``` -------------------------------- ### Get presigned URL for DELETE, PUT, GET, and with change_host Source: https://github.com/hlf20010508/miniopy-async/wiki/API Demonstrates generating presigned URLs for various HTTP methods (DELETE, PUT, GET) with different expiry times and response headers, plus a case using change_host to replace a private IP base URL with a public host. Requires an async Minio client and asyncio event loop. ```python from datetime import timedelta from miniopy_async import Minio import asyncio async def main(): client = Minio( "play.min.io", access_key="Q3AM3UQ867SPQQA43P2F", secret_key="zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG", secure=True # http for False, https for True ) # Get presigned URL string to delete 'my-object' in # 'my-bucket' with one day expiry. print('example one') url = await client.get_presigned_url( "DELETE", "my-bucket", "my-object", expires=timedelta(days=1), ) print('url:', url) # Get presigned URL string to upload 'my-object' in # 'my-bucket' with response-content-type as application/json # and one day expiry. print('example two') url = await client.get_presigned_url( "PUT", "my-bucket", "my-object", expires=timedelta(days=1), response_headers={"response-content-type": "application/json"}, ) print('url:', url) # Get presigned URL string to download 'my-object' in # 'my-bucket' with two hours expiry. print('example three') url = await client.get_presigned_url( "GET", "my-bucket", "my-object", expires=timedelta(hours=2), ) print('url:', url) # Get presigned URL string to download 'my-object' in # 'my-bucket' with public IP address when using private IP address. client = Minio( "127.0.0.1:9000", access_key="your access key", secret_key="you secret key", secure=False # http for False, https for True ) print('example four') url = await client.get_presigned_url( "GET", "my-bucket", "my-object", change_host='https://YOURHOST:YOURPORT', ) print('url:', url) loop = asyncio.get_event_loop() loop.run_until_complete(main()) loop.close() ``` -------------------------------- ### get_object example Source: https://github.com/hlf20010508/miniopy-async/wiki/API Retrieves object data from a MinIO bucket using the miniopy_async client. The example shows four usage patterns: reading an entire object, reading a byte range with offset and length, reading a specific version by version_id, and reading an SSE-C encrypted object with SseCustomerKey. The response must be closed and released to free network resources. ```python from miniopy_async import Minio from miniopy_async.sse import SseCustomerKey import asyncio client = Minio( "play.min.io", access_key="Q3AM3UQ867SPQQA43P2F", secret_key="zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG", secure=True # http for False, https for True ) async def main(): try: # Get data of an object. print('example one') response = await client.get_object("my-bucket", "my-object") # Read data from response. # Get data of an object from offset and length. print('example two') response = await client.get_object( "my-bucket", "my-object", offset=512, length=1024, ) # Read data from response. # Get data of an object of version-ID. print('example three') response = await client.get_object( "my-bucket", "my-object", version_id="dfbd25b3-abec-4184-a4e8-5a35a5c1174d", ) # Read data from response. # Get data of an SSE-C encrypted object. print('example four') response = await client.get_object( "my-bucket", "my-object", ssec=SseCustomerKey(b"32byteslongsecretkeymustprovided"), ) # Read data from response. finally: response.close() await response.release() loop = asyncio.get_event_loop() loop.run_until_complete(main()) loop.close() ``` -------------------------------- ### select_object_content example Source: https://github.com/hlf20010508/miniopy-async/wiki/API Selects content from an object using a SQL expression. The example creates a Minio client, defines an async main function that calls select_object_content with a SelectRequest, and prints the streamed data and status. Requires the miniopy_async and aiostream libraries. ```python from miniopy_async import Minio from miniopy_async.select import (CSVInputSerialization, CSVOutputSerialization, SelectRequest) from aiostream.stream import list as alist import asyncio client = Minio( "play.min.io", access_key="Q3AM3UQ867SPQQA43P2F", secret_key="zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG", secure=True # http for False, https for True ) async def main(): result = await client.select_object_content( "my-bucket", "my-object.csv", SelectRequest( "select * from s3object", CSVInputSerialization(), CSVOutputSerialization(), request_progress=True, ), ) print('data:') for data in await alist(result.stream()): print(data.decode()) print('status:',result.stats()) loop = asyncio.get_event_loop() loop.run_until_complete(main()) loop.close() ``` -------------------------------- ### get_bucket_lifecycle example Source: https://github.com/hlf20010508/miniopy-async/wiki/API Retrieves the lifecycle configuration of a bucket and prints it. Returns a LifecycleConfig object. ```python from miniopy_async import Minio import asyncio client = Minio( "play.min.io", access_key="Q3AM3UQ867SPQQA43P2F", secret_key="zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG", secure=True # http for False, https for True ) async def main(): config = await client.get_bucket_lifecycle("my-bucket") print(config) loop = asyncio.get_event_loop() loop.run_until_complete(main()) loop.close() ``` -------------------------------- ### set_object_retention example Source: https://github.com/hlf20010508/miniopy-async/wiki/API Sets retention information on an object using a Retention configuration. The example creates a Retention with GOVERNANCE mode and a 10-day duration, then applies it asynchronously. ```python from datetime import datetime, timedelta from miniopy_async import Minio from miniopy_async.commonconfig import GOVERNANCE from miniopy_async.retention import Retention import asyncio client = Minio( "play.min.io", access_key="Q3AM3UQ867SPQQA43P2F", secret_key="zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG", secure=True # http for False, https for True ) config = Retention(GOVERNANCE, datetime.utcnow() + timedelta(days=10)) async def main(): await client.set_object_retention("my-bucket", "my-object", config) loop = asyncio.get_event_loop() loop.run_until_complete(main()) loop.close() ``` -------------------------------- ### compose_object usage example Source: https://github.com/hlf20010508/miniopy-async/wiki/API Creates an object by combining data from multiple source objects using server-side copy. Requires each source part to be larger than 5MB. The example shows three variations: basic composition, adding user metadata, and adding server-side encryption with SseS3. ```python from miniopy_async import Minio from miniopy_async.commonconfig import ComposeSource from miniopy_async.sse import SseS3 import asyncio client = Minio( "play.min.io", access_key="Q3AM3UQ867SPQQA43P2F", secret_key="zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG", secure=True # http for False, https for True ) # Each part must larger than 5MB 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"), ] async def main(): # Create my-bucket/my-object by combining source object # list. print('example one') result = await 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. print('example two') result = await client.compose_object( "my-bucket", "my-object", sources, metadata={"Content-Type": "application/octet-stream"}, ) print(result.object_name, result.version_id) # Create my-bucket/my-object with user metadata and # server-side encryption by combining source object list. print('example three') result = await client.compose_object( "my-bucket", "my-object", sources, sse=SseS3() ) print(result.object_name, result.version_id) loop = asyncio.get_event_loop() loop.run_until_complete(main()) loop.close() ``` -------------------------------- ### Usage example with Destination, Metrics, ReplicationTime Source: https://github.com/hlf20010508/miniopy-async/blob/master/_autodocs/api-reference/replicationconfig.md Example of constructing a Destination with metrics and replication time using the miniopy_async replicationconfig classes. Requires importing ENABLED from miniopy_async.commonconfig. ```python from miniopy_async.commonconfig import ENABLED from miniopy_async.replicationconfig import ( EventThreshold, Metrics, ReplicationTime, Time, ) dest = Destination( "arn:aws:s3:::dest", metrics=Metrics(EventThreshold(15), ENABLED), replication_time=ReplicationTime(Time(15), ENABLED), storage_class="STANDARD", ) ``` -------------------------------- ### SseCustomerKey usage example Source: https://github.com/hlf20010508/miniopy-async/blob/master/_autodocs/api-reference/sse.md Example of using SseCustomerKey with put_object and get_object. The same key must be provided via ssec= for download. ```python from miniopy_async.sse import SseCustomerKey sse = SseCustomerKey(b"32byteslongsecretkeymustprovided") await client.put_object("my-bucket", "my-object", data, length, sse=sse) # download requires the same key via ssec= response = await client.get_object("my-bucket", "my-object", ssec=sse) ``` -------------------------------- ### LifecycleConfig Combined Example Source: https://github.com/hlf20010508/miniopy-async/blob/master/_autodocs/api-reference/lifecycleconfig.md Demonstrates how to construct a LifecycleConfig with multiple rules and apply it to a bucket using the set_bucket_lifecycle method. This example shows the usage of Rule, Filter, Expiration, NoncurrentVersionExpiration, and AbortIncompleteMultipartUpload. ```APIDOC ## LifecycleConfig Combined Example ### Description Demonstrates how to construct a LifecycleConfig with multiple rules and apply it to a bucket using the set_bucket_lifecycle method. ### Usage Example ```python from miniopy_async.commonconfig import DISABLED, ENABLED, Filter from miniopy_async.lifecycleconfig import ( AbortIncompleteMultipartUpload, Expiration, LifecycleConfig, NoncurrentVersionExpiration, Rule, ) config = LifecycleConfig([ Rule( ENABLED, rule_filter=Filter(prefix="tmp/"), rule_id="abort-incomplete", abort_incomplete_multipart_upload=AbortIncompleteMultipartUpload(7), ), Rule( DISABLED, rule_filter=Filter(prefix="archive/"), rule_id="noncurrent", noncurrent_version_expiration=NoncurrentVersionExpiration( noncurrent_days=30, newer_noncurrent_versions=3 ), expiration=Expiration(expired_object_delete_marker=True), ), ]) await client.set_bucket_lifecycle("my-bucket", config) ``` ``` -------------------------------- ### get_presigned_url usage example Source: https://github.com/hlf20010508/miniopy-async/blob/master/_autodocs/api-reference/minio.md Example of generating a presigned PUT URL with custom expiry and response headers. The response_headers parameter adds query params like response-content-type. The returned URL is printed. ```python from datetime import timedelta url = await client.get_presigned_url( "PUT", "my-bucket", "my-object", expires=timedelta(days=1), response_headers={"response-content-type": "application/json"}, ) print(url) ``` -------------------------------- ### set_bucket_lifecycle example Source: https://github.com/hlf20010508/miniopy-async/wiki/API Sets a lifecycle configuration on a bucket. The config includes rules for transition and expiration with filters. ```python from miniopy_async import Minio from miniopy_async.commonconfig import ENABLED, Filter from miniopy_async.lifecycleconfig import Expiration, LifecycleConfig, Rule, Transition import asyncio client = Minio( "play.min.io", access_key="Q3AM3UQ867SPQQA43P2F", secret_key="zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG", secure=True # http for False, https for True ) 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), ), ], ) async def main(): await client.set_bucket_lifecycle("my-bucket", config) loop = asyncio.get_event_loop() loop.run_until_complete(main()) loop.close() ``` -------------------------------- ### get_object_lock_config: Retrieve bucket object-lock configuration Source: https://github.com/hlf20010508/miniopy-async/wiki/API Gets the object-lock configuration for a bucket and returns an ObjectLockConfig object. The example prints the returned configuration. ```Python from miniopy_async import Minio import asyncio client = Minio( "play.min.io", access_key="Q3AM3UQ867SPQQA43P2F", secret_key="zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG", secure=True # http for False, https for True ) async def main(): config = await client.get_object_lock_config("my-bucket") print(config) loop = asyncio.get_event_loop() loop.run_until_complete(main()) loop.close() ``` -------------------------------- ### stat_object usage Source: https://github.com/hlf20010508/miniopy-async/blob/master/_autodocs/api-reference/minio-objects.md Example of using stat_object to get metadata for a single object. It performs a HEAD request and builds an Object from response headers. The result is awaited and prints last_modified and size. ```python result = await client.stat_object("my-bucket", "my-object") print(result.last_modified, result.size) ``` -------------------------------- ### Using StaticProvider with Minio client Source: https://github.com/hlf20010508/miniopy-async/blob/master/_autodocs/api-reference/credentials.md Example of creating a Minio client with a StaticProvider, which always returns the fixed credentials. ```python from miniopy_async import Minio from miniopy_async.credentials import StaticProvider client = Minio("play.min.io", credentials=StaticProvider("AK", "SK")) ``` -------------------------------- ### Check if object legal hold is enabled with is_object_legal_hold_enabled Source: https://github.com/hlf20010508/miniopy-async/wiki/API Asynchronously checks whether legal hold is enabled on an object and prints the result. Uses the same Minio client setup and asyncio pattern as the disable example. ```python from miniopy_async import Minio import asyncio client = Minio( "play.min.io", access_key="Q3AM3UQ867SPQQA43P2F", secret_key="zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG", secure=True # http for False, https for True ) async def main(): if await 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") loop = asyncio.get_event_loop() loop.run_until_complete(main()) loop.close() ``` -------------------------------- ### Get bucket notification with get_bucket_notification Source: https://github.com/hlf20010508/miniopy-async/wiki/API Asynchronous example that retrieves the notification configuration of a bucket and prints the returned NotificationConfig object. Requires a Minio client with valid credentials; the secure flag controls HTTPS (True) or HTTP (False). ```py from miniopy_async import Minio import asyncio client = Minio( "play.min.io", access_key="Q3AM3UQ867SPQQA43P2F", secret_key="zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG", secure=True # http for False, https for True ) async def main(): config = await client.get_bucket_notification("my-bucket") print(config) loop = asyncio.get_event_loop() loop.run_until_complete(main()) loop.close() ``` -------------------------------- ### Minio client initialization examples Source: https://github.com/hlf20010508/miniopy-async/wiki/API Shows several ways to create a Minio client: anonymous access, with access and secret keys, with a specific region, and with HTTP (secure=False). The constructor accepts endpoint, access_key, secret_key, session_token, secure, region, and credentials parameters. ```python from miniopy_async 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 access key and secret key with http. client = Minio( "play.minio.io:9000", access_key="Q3AM3UQ867SPQQA43P2F", secret_key="zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG", secure=False, ) ``` -------------------------------- ### presigned_get_object example Source: https://github.com/hlf20010508/miniopy-async/wiki/API Demonstrates generating presigned URLs for downloading objects with default, custom expiry, and custom host. Uses miniopy_async Minio client and asyncio. Shows three use cases: default 7-day expiry, two-hour expiry, and changing host to public IP when base URL is private. ```python from datetime import timedelta from miniopy_async import Minio import asyncio async def main(): client = Minio( "play.min.io", access_key="Q3AM3UQ867SPQQA43P2F", secret_key="zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG", secure=True # http for False, https for True ) # Get presigned URL string to download 'my-object' in # 'my-bucket' with default expiry (i.e. 7 days). print('example one') url = await client.presigned_get_object("my-bucket", "my-object") print('url:', url) # Get presigned URL string to download 'my-object' in # 'my-bucket' with two hours expiry. print('example two') url = await client.presigned_get_object( "my-bucket", "my-object", expires=timedelta(hours=2), ) print('url:', url) # Get presigned URL string to download 'my-object' in # 'my-bucket' with public IP address when using private IP address. client = Minio( "127.0.0.1:9000", access_key="your access key", secret_key="you secret key", secure=False # http for False, https for True ) print('example three') url = await client.presigned_get_object( "my-bucket", "my-object", change_host='https://YOURHOST:YOURPORT', ) print('url:', url) loop = asyncio.get_event_loop() loop.run_until_complete(main()) loop.close() ``` -------------------------------- ### Import Credentials and Providers Source: https://github.com/hlf20010508/miniopy-async/blob/master/_autodocs/api-reference/credentials.md Import all credential classes and providers from miniopy_async.credentials. ```python from miniopy_async.credentials import ( Credentials, Provider, StaticProvider, EnvAWSProvider, EnvMinioProvider, AWSConfigProvider, MinioClientConfigProvider, ChainedProvider, AssumeRoleProvider, IamAwsProvider, LdapIdentityProvider, ClientGrantsProvider, WebIdentityProvider, CertificateIdentityProvider, ) ``` -------------------------------- ### Basic Minio client usage with async context manager Source: https://github.com/hlf20010508/miniopy-async/blob/master/_autodocs/api-reference/minio.md Shows basic client initialization and listing buckets. Uses an async context manager to automatically close the session. The example uses the public play.min.io endpoint with provided credentials. ```python import asyncio from miniopy_async import Minio async def main(): async with Minio( "play.min.io", access_key="Q3AM3UQ867SPQQA43P2F", secret_key="zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG", secure=True, ) as client: buckets = await client.list_buckets() for bucket in buckets: print(bucket.name, bucket.creation_date) asyncio.run(main()) ``` -------------------------------- ### GET /{bucket}?tagging (GetBucketTagging) Source: https://github.com/hlf20010508/miniopy-async/blob/master/_autodocs/endpoints.md Gets the bucket tags. This is called by the client method get_bucket_tags(). ```APIDOC ## GET /{bucket}?tagging ### Description Gets the bucket tags. This is called by the client method get_bucket_tags(). ### Method GET ### Endpoint /{bucket} ### Parameters #### Path Parameters - **bucket** (string) - Required - The name of the bucket. #### Query Parameters - **tagging** (string) - Required - The tagging query parameter. ### Response #### Success Response (200) - **Tagging** (XML) - The bucket tags. #### Response Example ```xml project my-project ``` ``` -------------------------------- ### GET /{bucket}?policy (GetBucketPolicy) Source: https://github.com/hlf20010508/miniopy-async/blob/master/_autodocs/endpoints.md Gets the bucket policy. This is called by the client method get_bucket_policy(). ```APIDOC ## GET /{bucket}?policy ### Description Gets the bucket policy. This is called by the client method get_bucket_policy(). ### Method GET ### Endpoint /{bucket} ### Parameters #### Path Parameters - **bucket** (string) - Required - The name of the bucket. #### Query Parameters - **policy** (string) - Required - The policy query parameter. ### Response #### Success Response (200) - **policy** (JSON) - The bucket policy as raw JSON text. #### Response Example ```json { "Version": "2012-10-17", "Statement": [] } ``` ``` -------------------------------- ### Using EnvAWSProvider with Minio client Source: https://github.com/hlf20010508/miniopy-async/blob/master/_autodocs/api-reference/credentials.md Example of creating a Minio client with EnvAWSProvider, which reads credentials from AWS environment variables. Raises ValueError when the keys are empty. ```python from miniopy_async.credentials import EnvAWSProvider client = Minio("s3.amazonaws.com", credentials=EnvAWSProvider()) ```