File size: 9,478 Bytes
d439dc1 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 | # MinIO Python Library for Amazon S3 Compatible Cloud Storage [](https://slack.min.io)
The MinIO Python Client SDK provides simple APIs to access any Amazon S3 compatible object storage server.
This quickstart guide will show you how to install the client SDK and execute an example python program. For a complete list of APIs and examples, please take a look at the [Python Client API Reference](https://docs.min.io/docs/python-client-api-reference) documentation.
This document assumes that you have a working [Python](https://www.python.org/downloads/) setup in place.
## Minimum Requirements
- Python 3.6 or higher
## Download from pip
```sh
pip install minio
```
## Download from pip3
```sh
pip3 install minio
```
## Download from source
```sh
git clone https://github.com/minio/minio-py
cd minio-py
python setup.py install
```
## Initialize MinIO Client
You need four items in order to connect to MinIO object storage server.
| 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.|
```py
from minio import Minio
from minio.error import ResponseError
minioClient = Minio('play.min.io',
access_key='Q3AM3UQ867SPQQA43P2F',
secret_key='zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG',
secure=True)
```
**NOTE on concurrent usage:** The `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.
## Quick Start Example - File Uploader
This example program connects to a MinIO object storage server, makes a bucket on the server and then uploads a file to the bucket.
We will use the MinIO server running at [https://play.min.io](https://play.min.io) in this example. Feel free to use this service for testing and development. Access credentials shown in this example are open to the public.
#### file-uploader.py
```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)
```
#### Run file-uploader
```bash
python file_uploader.py
mc ls play/maylogs/
[2016-05-27 16:41:37 PDT] 12MiB pumaserver_debug.log
```
## API Reference
The full API Reference is available here.
* [Complete API Reference](https://docs.min.io/docs/python-client-api-reference)
### API Reference : Bucket Operations
* [`make_bucket`](https://docs.min.io/docs/python-client-api-reference#make_bucket)
* [`list_buckets`](https://docs.min.io/docs/python-client-api-reference#list_buckets)
* [`bucket_exists`](https://docs.min.io/docs/python-client-api-reference#bucket_exists)
* [`remove_bucket`](https://docs.min.io/docs/python-client-api-reference#remove_bucket)
* [`list_objects`](https://docs.min.io/docs/python-client-api-reference#list_objects)
### API Reference : Bucket policy Operations
* [`get_bucket_policy`](https://docs.min.io/docs/python-client-api-reference#get_bucket_policy)
* [`set_bucket_policy`](https://docs.min.io/docs/python-client-api-reference#set_bucket_policy)
### API Reference : Bucket notification Operations
* [`set_bucket_notification`](https://docs.min.io/docs/python-client-api-reference#set_bucket_notification)
* [`get_bucket_notification`](https://docs.min.io/docs/python-client-api-reference#get_bucket_notification)
* [`remove_all_bucket_notification`](https://docs.min.io/docs/python-client-api-reference#remove_all_bucket_notification)
* [`listen_bucket_notification`](https://docs.min.io/docs/python-client-api-reference#listen_bucket_notification)
### API Reference : Default bucket encryption configuration Operations
* [`put_bucket_encryption`](https://docs.min.io/docs/python-client-api-reference#put_bucket_encryption)
* [`get_bucket_encryption`](https://docs.min.io/docs/python-client-api-reference#get_bucket_encryption)
* [`delete_bucket_encryption`](https://docs.min.io/docs/python-client-api-reference#delete_bucket_encryption)
### API Reference : File Object Operations
* [`fput_object`](https://docs.min.io/docs/python-client-api-reference#fput_object)
* [`fget_object`](https://docs.min.io/docs/python-client-api-reference#fget_object)
### API Reference : Object Operations
* [`get_object`](https://docs.min.io/docs/python-client-api-reference#get_object)
* [`put_object`](https://docs.min.io/docs/python-client-api-reference#put_object)
* [`stat_object`](https://docs.min.io/docs/python-client-api-reference#stat_object)
* [`copy_object`](https://docs.min.io/docs/python-client-api-reference#copy_object)
* [`remove_object`](https://docs.min.io/docs/python-client-api-reference#remove_object)
* [`remove_objects`](https://docs.min.io/docs/python-client-api-reference#remove_objects)
### API Reference : Presigned Operations
* [`presigned_get_object`](https://docs.min.io/docs/python-client-api-reference#presigned_get_object)
* [`presigned_put_object`](https://docs.min.io/docs/python-client-api-reference#presigned_put_object)
* [`presigned_post_policy`](https://docs.min.io/docs/python-client-api-reference#presigned_post_policy)
## Full Examples
#### Full Examples : Bucket Operations
* [make_bucket.py](https://github.com/minio/minio-py/blob/master/examples/make_bucket.py)
* [list_buckets.py](https://github.com/minio/minio-py/blob/master/examples/list_buckets.py)
* [bucket_exists.py](https://github.com/minio/minio-py/blob/master/examples/bucket_exists.py)
* [list_objects.py](https://github.com/minio/minio-py/blob/master/examples/list_objects.py)
* [remove_bucket.py](https://github.com/minio/minio-py/blob/master/examples/remove_bucket.py)
#### Full Examples : Bucket policy Operations
* [set_bucket_policy.py](https://github.com/minio/minio-py/blob/master/examples/set_bucket_policy.py)
* [get_bucket_policy.py](https://github.com/minio/minio-py/blob/master/examples/get_bucket_policy.py)
#### Full Examples: Bucket notification Operations
* [set_bucket_notification.py](https://github.com/minio/minio-py/blob/master/examples/set_bucket_notification.py)
* [get_bucket_notification.py](https://github.com/minio/minio-py/blob/master/examples/get_bucket_notification.py)
* [remove_all_bucket_notification.py](https://github.com/minio/minio-py/blob/master/examples/remove_all_bucket_notification.py)
* [listen_bucket_notification.py](https://github.com/minio/minio-py/blob/master/examples/listen_notification.py)
#### Full Examples: Default bucket encryption configuration Operations
* [put_bucket_encryption.py](https://github.com/minio/minio-py/blob/master/examples/put_bucket_encryption.py)
* [get_bucket_encryption.py](https://github.com/minio/minio-py/blob/master/examples/get_bucket_encryption.py)
* [delete_bucket_encryption.py](https://github.com/minio/minio-py/blob/master/examples/delete_bucket_encryption.py)
#### Full Examples : File Object Operations
* [fput_object.py](https://github.com/minio/minio-py/blob/master/examples/fput_object.py)
* [fget_object.py](https://github.com/minio/minio-py/blob/master/examples/fget_object.py)
#### Full Examples : Object Operations
* [get_object.py](https://github.com/minio/minio-py/blob/master/examples/get_object.py)
* [put_object.py](https://github.com/minio/minio-py/blob/master/examples/put_object.py)
* [stat_object.py](https://github.com/minio/minio-py/blob/master/examples/stat_object.py)
* [copy_object.py](https://github.com/minio/minio-py/blob/master/examples/copy_object.py)
* [remove_object.py](https://github.com/minio/minio-py/blob/master/examples/remove_object.py)
* [remove_objects.py](https://github.com/minio/minio-py/blob/master/examples/remove_objects.py)
#### Full Examples : Presigned Operations
* [presigned_get_object.py](https://github.com/minio/minio-py/blob/master/examples/presigned_get_object.py)
* [presigned_put_object.py](https://github.com/minio/minio-py/blob/master/examples/presigned_put_object.py)
* [presigned_post_policy.py](https://github.com/minio/minio-py/blob/master/examples/presigned_post_policy.py)
## Explore Further
* [Complete Documentation](https://docs.min.io)
* [MinIO Python SDK API Reference](https://docs.min.io/docs/python-client-api-reference)
## Contribute
[Contributors Guide](https://github.com/minio/minio-py/blob/master/CONTRIBUTING.md)
[](https://pypi.python.org/pypi/minio)
|