Package: minio
MinIO Python Client SDK for Amazon S3 Compatible Cloud StorageThe MinIO Python Client SDK provides high level APIs to access any MinIO Object Storage or other Amazon S3 compatible service.This Quickstart Guide covers how to install the MinIO client SDK, connect to the object storage service, and create a sample file uploader.The example below uses:Python version 3.7+TheMinIOmccommand line toolThe MinIOplaytest serverTheplayserver is a public MinIO cluster located athttps://play.min.io.
This cluster runs the latest stable version of MinIO and may be used for testing and development.
The access credentials in the example are open to the public and all data uploaded toplayshould be considered public and world-readable.For a complete list of APIs and examples, see thePython Client API ReferenceInstall the MinIO Python SDKThe Python SDK requires Python version 3.7+.
You can install the SDK withpipor from theminio/minio-pyGitHub repository:Usingpippip3installminioUsing Source From GitHubgitclonehttps://github.com/minio/minio-pycdminio-py
pythonsetup.pyinstallCreate a MinIO ClientTo connect to the target service, create a MinIO client using theMinio()method with the following required parameters:ParameterDescriptionendpointURL of the target service.access_keyAccess key (user ID) of a user account in the service.secret_keySecret key (password) for the user account.For example:fromminioimportMinioclient=Minio("play.min.io",access_key="Q3AM3UQ867SPQQA43P2F",secret_key="zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG",)Example - File UploaderThis example does the following:Connects to the MinIOplayserver using the provided credentials.Creates a bucket namedpython-test-bucketif it does not already exist.Uploads a file namedtest-file.txtfrom/tmp, renaming itmy-test-file.txt.Verifies the file was created usingmc ls.file_uploader.py# file_uploader.py MinIO Python SDK examplefromminioimportMiniofromminio.errorimportS3Errordefmain():# Create a client with the MinIO server playground, its access key# and secret key.client=Minio("play.min.io",access_key="Q3AM3UQ867SPQQA43P2F",secret_key="zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG",)# The file to upload, change this path if neededsource_file="/tmp/test-file.txt"# The destination bucket and filename on the MinIO serverbucket_name="python-test-bucket"destination_file="my-test-file.txt"# Make the bucket if it doesn't exist.found=client.bucket_exists(bucket_name)ifnotfound:client.make_bucket(bucket_name)print("Created bucket",bucket_name)else:print("Bucket",bucket_name,"already exists")# Upload the file, renaming it in the processclient.fput_object(bucket_name,destination_file,source_file,)print(source_file,"successfully uploaded as object",destination_file,"to bucket",bucket_name,)if__name__=="__main__":try:main()exceptS3Errorasexc:print("error occurred.",exc)To run this example:Create a file in/tmpnamedtest-file.txt.
To use a different path or filename, modify the value ofsource_file.Runfile_uploader.pywith the following command:pythonfile_uploader.pyIf the bucket does not exist on the server, the output resembles the following:Createdbucketpython-test-bucket
/tmp/test-file.txtsuccessfullyuploadedasobjectmy-test-file.txttobucketpython-test-bucketVerify the uploaded file withmc ls:mclsplay/python-test-bucket[2023-11-0322:18:54UTC]20KiBSTANDARDmy-test-file.txtMore ReferencesPython Client API ReferenceExamplesExplore FurtherComplete DocumentationContributeContributors GuideLicenseThis SDK is distributed under theApache License, Version 2.0, seeLICENSEandNOTICEfor more information.