minio/minio-py
Fork: 329 Star: 862 (更新于 2024-12-14 20:19:15)
license: Apache-2.0
Language: Python .
MinIO Client SDK for Python
最后发布版本: 7.2.8 ( 2024-08-17 21:18:41)
MinIO Python Client SDK for Amazon S3 Compatible Cloud Storage
The 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+
- The MinIO
mc
command line tool - The MinIO
play
test server
The play
server is a public MinIO cluster located at https://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 to play
should be considered public and world-readable.
For a complete list of APIs and examples, see the Python Client API Reference
Install the MinIO Python SDK
The Python SDK requires Python version 3.7+.
You can install the SDK with pip
or from the minio/minio-py
GitHub repository:
Using pip
pip3 install minio
Using Source From GitHub
git clone https://github.com/minio/minio-py
cd minio-py
python setup.py install
Create a MinIO Client
To connect to the target service, create a MinIO client using the Minio()
method with the following required parameters:
Parameter | Description |
---|---|
endpoint |
URL of the target service. |
access_key |
Access key (user ID) of a user account in the service. |
secret_key |
Secret key (password) for the user account. |
For example:
from minio import Minio
client = Minio("play.min.io",
access_key="Q3AM3UQ867SPQQA43P2F",
secret_key="zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG",
)
Example - File Uploader
This example does the following:
- Connects to the MinIO
play
server using the provided credentials. - Creates a bucket named
python-test-bucket
if it does not already exist. - Uploads a file named
test-file.txt
from/tmp
, renaming itmy-test-file.txt
. - Verifies the file was created using
mc ls
.
file_uploader.py
# file_uploader.py MinIO Python SDK example
from minio import Minio
from minio.error import S3Error
def main():
# 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 needed
source_file = "/tmp/test-file.txt"
# The destination bucket and filename on the MinIO server
bucket_name = "python-test-bucket"
destination_file = "my-test-file.txt"
# Make the bucket if it doesn't exist.
found = client.bucket_exists(bucket_name)
if not found:
client.make_bucket(bucket_name)
print("Created bucket", bucket_name)
else:
print("Bucket", bucket_name, "already exists")
# Upload the file, renaming it in the process
client.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()
except S3Error as exc:
print("error occurred.", exc)
To run this example:
-
Create a file in
/tmp
namedtest-file.txt
. To use a different path or filename, modify the value ofsource_file
. -
Run
file_uploader.py
with the following command:
python file_uploader.py
If the bucket does not exist on the server, the output resembles the following:
Created bucket python-test-bucket
/tmp/test-file.txt successfully uploaded as object my-test-file.txt to bucket python-test-bucket
- Verify the uploaded file with
mc ls
:
mc ls play/python-test-bucket
[2023-11-03 22:18:54 UTC] 20KiB STANDARD my-test-file.txt
More References
Explore Further
Contribute
License
This SDK is distributed under the Apache License, Version 2.0, see LICENSE and NOTICE for more information.
最近版本更新:(数据更新于 2024-09-03 01:46:57)
2024-08-17 21:18:41 7.2.8
2024-05-01 05:21:13 7.2.7
2024-04-26 04:47:38 7.2.6
2024-03-03 07:49:53 7.2.5
2024-02-11 08:42:22 7.2.4
2024-01-03 17:38:29 7.2.3
2023-12-28 06:09:14 7.2.2
2023-12-26 16:20:38 7.2.1
2023-11-10 16:24:20 7.2.0
2023-09-25 13:58:39 7.1.17
主题(topics):
aws-s3, minio, minio-client, s3-bucket, sdk
minio/minio-py同语言 Python最近更新仓库
2024-12-22 09:03:32 ultralytics/ultralytics
2024-12-21 13:26:40 notepad-plus-plus/nppPluginList
2024-12-21 11:42:53 XiaoMi/ha_xiaomi_home
2024-12-21 04:33:22 comfyanonymous/ComfyUI
2024-12-20 18:47:56 home-assistant/core
2024-12-20 15:41:40 jxxghp/MoviePilot