MinIO Python SDK是简单存储服务(aka S3)客户端,用于对任何与Amazon S3兼容的对象存储服务执行存储桶和对象操作。
最低要求
Python 3.6或更高版本。
使用pip下载
pip3 install minio
下载源
git clone https://github.com/minio/minio-py
cd minio-py
python setup.py install
快速入门示例-文件上传器
此示例程序连接到兼容S3的对象存储服务器,在该服务器上创建存储桶,然后将文件上传到存储桶。
您需要以下各项才能连接到S3兼容的对象存储服务器:
参数说明 | 描述 |
---|---|
端点 | S3服务的URL。 |
访问密钥 | S3服务中帐户的访问密钥(也称为用户ID)。 |
秘钥 | S3服务中帐户的秘密密钥(也称为密码)。 |
本示例使用MinIO 测试站点[https://play.min.io](https://play.min.io)。随意使用此服务进行测试和开发。
file_uploader.py
# Import MinIO library.
from minio import Minio
from minio.error import (ResponseError, BucketAlreadyOwnedByYou,
BucketAlreadyExists)
# Initialize minioClient with an endpoint and access/secret keys.
minioClient = Minio('play.min.io',
access_key='Q3AM3UQ867SPQQA43P2F',
secret_key='zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG',
secure=True)
# Make a bucket with the make_bucket API call.
try:
minioClient.make_bucket("maylogs", location="us-east-1")
except BucketAlreadyOwnedByYou as err:
pass
except BucketAlreadyExists as err:
pass
except ResponseError as err:
raise
# Put an object 'pumaserver_debug.log' with contents from 'pumaserver_debug.log'.
try:
minioClient.fput_object('maylogs', 'pumaserver_debug.log', '/tmp/pumaserver_debug.log')
except ResponseError as err:
print(err)
运行文件上传器
$ python file_uploader.py
'/home/user/Photos/asiaphotos.zip' is successfully uploaded as object 'asiaphotos-2015.zip' to bucket 'asiatrip'.
$ mc ls play/asiatrip/
[2016-06-02 18:10:29 PDT] 82KiB asiaphotos-2015.zip
本文原创翻译 内容来源于[MinIO国际官网] (http://min.io) 和 MinIO中国官网
本文原创,转载请注明来源:Python李文凯