Asynchronous MinIO Client SDK

1.23.5 · active · verified Fri Apr 17

miniopy-async provides an asynchronous interface to the MinIO object storage server, building upon the official synchronous `minio` Python client by integrating `aiohttp`. It aims to stay up-to-date with `minio-py`'s features while providing `asyncio` compatibility. The current version is 1.23.5, and it maintains a frequent release cadence, often aligning with updates to the underlying `minio-py` library or addressing async-specific bugs.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the `Minio` client, list existing buckets, and create a new bucket asynchronously. Ensure your MinIO server endpoint and credentials are provided via environment variables or directly in the code for execution.

import os
import asyncio
from miniopy_async import Minio, S3Error

async def main():
    endpoint = os.environ.get("MINIO_ENDPOINT", "localhost:9000")
    access_key = os.environ.get("MINIO_ACCESS_KEY", "minioadmin")
    secret_key = os.environ.get("MINIO_SECRET_KEY", "minioadmin")
    secure = os.environ.get("MINIO_SECURE", "false").lower() == "true"

    client = Minio(
        endpoint=endpoint,
        access_key=access_key,
        secret_key=secret_key,
        secure=secure
    )

    try:
        # Example: List all buckets
        buckets = await client.list_buckets()
        print(f"Successfully connected to MinIO. Found {len(buckets)} buckets:")
        for bucket in buckets:
            print(f"  - {bucket.name} (created at {bucket.creation_date})")

        # Example: Make a bucket if it doesn't exist
        test_bucket = "my-test-bucket"
        found = await client.bucket_exists(test_bucket)
        if not found:
            await client.make_bucket(test_bucket)
            print(f"Bucket '{test_bucket}' created successfully.")
        else:
            print(f"Bucket '{test_bucket}' already exists.")

    except S3Error as e:
        print(f"MinIO S3 Error: {e.code} - {e.message}")
    except Exception as e:
        print(f"An unexpected error occurred: {e}")

if __name__ == "__main__":
    # Ensure MinIO_ENDPOINT, MINIO_ACCESS_KEY, MINIO_SECRET_KEY are set
    # or MinIO is running locally with default credentials (minioadmin:minioadmin)
    asyncio.run(main())

view raw JSON →