minio python library for amazon s3兼容的python云存储
minio的Python项目详细描述
minio python library for amazon s3兼容云存储
minio python客户端sdk提供了简单的api来访问任何与amazon s3兼容的对象存储服务器。
本快速入门指南将向您展示如何安装客户端sdk并执行示例python程序。有关api和示例的完整列表,请查看Python Client API Reference文档。
本文档假设您有一个工作的Python设置。
最低要求
- python 2.7或更高版本
从PIP下载
pip install minio
从PIP3下载
pip3 install minio
从源下载
git clone https://github.com/minio/minio-py
cd minio-py
python setup.py install
初始化minio客户端
您需要四项才能连接到minio对象存储服务器。
Params | Description |
---|---|
endpoint | URL to object storage service. |
access_key | Access key is like user ID that uniquely identifies your account. |
secret_key | Secret key is the password to your account. |
secure | Set this value to 'True' to enable secure (HTTPS) access. |
fromminioimportMiniofromminio.errorimportResponseErrorminioClient=Minio('play.min.io',access_key='Q3AM3UQ867SPQQA43P2F',secret_key='zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG',secure=True)
快速入门示例-文件上载程序
这个示例程序连接到一个minio对象存储服务器,在服务器上创建一个bucket,然后将一个文件上传到bucket。
在本例中,我们将使用运行在https://play.min.io的minio服务器。请随意使用此服务进行测试和开发。此示例中显示的访问凭据对公众开放。
文件上载程序.py
# Import MinIO library.fromminioimportMiniofromminio.errorimport(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")exceptBucketAlreadyOwnedByYouaserr:passexceptBucketAlreadyExistsaserr:passexceptResponseErroraserr:raiseelse:# Put an object 'pumaserver_debug.log' with contents from 'pumaserver_debug.log'.try:minioClient.fput_object('maylogs','pumaserver_debug.log','/tmp/pumaserver_debug.log')exceptResponseErroraserr:print(err)
运行文件上载程序
python file_uploader.py
mc ls play/maylogs/
[2016-05-27 16:41:37 PDT] 12MiB pumaserver_debug.log
API参考
python file_uploader.py mc ls play/maylogs/ [2016-05-27 16:41:37 PDT] 12MiB pumaserver_debug.log
API参考
这里有完整的api引用。