{"id":1556,"library":"minio","title":"MinIO Python SDK","description":"The MinIO Python SDK provides idiomatic bindings for interacting with MinIO and Amazon S3 compatible cloud storage services. It offers a comprehensive set of APIs for object storage operations like putting, getting, and listing objects, as well as bucket management. The library is actively maintained with frequent bugfix and feature releases, typically on a weekly or bi-weekly cadence.","status":"active","version":"7.2.20","language":"en","source_language":"en","source_url":"https://github.com/minio/minio-py","tags":["s3","cloud-storage","object-storage","minio","aws-s3-compatible"],"install":[{"cmd":"pip install minio","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Requires Python 3.9 or newer.","package":"python","optional":false}],"imports":[{"symbol":"Minio","correct":"from minio import Minio"},{"note":"S3Error was moved to minio.error in earlier versions, always import from minio.error.","wrong":"from minio.s3_error import S3Error","symbol":"S3Error","correct":"from minio.error import S3Error"},{"note":"For administrative tasks like user management, policies, etc.","symbol":"MinioAdmin","correct":"from minio.admin import MinioAdmin"}],"quickstart":{"code":"import os\nimport io\nfrom minio import Minio\nfrom minio.error import S3Error\n\ntry:\n    # Initialize MinIO client\n    client = Minio(\n        endpoint=os.environ.get(\"MINIO_ENDPOINT\", \"play.min.io:9000\"),\n        access_key=os.environ.get(\"MINIO_ACCESS_KEY\", \"minioadmin\"),\n        secret_key=os.environ.get(\"MINIO_SECRET_KEY\", \"minioadmin\"),\n        secure=os.environ.get(\"MINIO_SECURE\", \"true\").lower() == \"true\"\n    )\n\n    bucket_name = \"my-test-bucket-123\"\n    object_name = \"my-file.txt\"\n    file_content = b\"Hello, MinIO from Python SDK!\"\n\n    # Check if bucket exists, create if not\n    if not client.bucket_exists(bucket_name):\n        client.make_bucket(bucket_name)\n        print(f\"Bucket '{bucket_name}' created.\")\n    else:\n        print(f\"Bucket '{bucket_name}' already exists.\")\n\n    # Upload data to an object\n    client.put_object(\n        bucket_name,\n        object_name,\n        data=io.BytesIO(file_content),\n        length=len(file_content),\n        content_type=\"text/plain\"\n    )\n    print(f\"Object '{object_name}' uploaded to bucket '{bucket_name}'.\")\n\n    # Download data from an object\n    data_stream = client.get_object(bucket_name, object_name)\n    downloaded_content = data_stream.read()\n    print(f\"Downloaded content: {downloaded_content.decode('utf-8')}\")\n\n    assert downloaded_content == file_content\n    print(\"Download successful and content matched.\")\n\nexcept S3Error as e:\n    print(f\"MinIO S3 error occurred: {e}\")\nexcept Exception as e:\n    print(f\"An unexpected error occurred: {e}\")\n","lang":"python","description":"This quickstart initializes a MinIO client, creates a bucket if it doesn't exist, uploads a text file as an object, and then downloads it, printing the content. Ensure `MINIO_ENDPOINT`, `MINIO_ACCESS_KEY`, `MINIO_SECRET_KEY`, and optionally `MINIO_SECURE` environment variables are set for authentication, or provide them directly. The default endpoint `play.min.io` is a public MinIO sandbox."},"warnings":[{"fix":"Upgrade your Python environment to 3.9 or higher.","message":"Python 3.8 support was removed in MinIO SDK version 7.2.11. Users on Python 3.8 or older will need to upgrade their Python interpreter to 3.9+ to use newer SDK versions.","severity":"breaking","affected_versions":">=7.2.11"},{"fix":"Initialize the client with `secure=False`: `client = Minio(..., secure=False)`","message":"The `Minio` client defaults to `secure=True` for HTTPS connections. If connecting to a local or self-signed MinIO instance via HTTP, you must explicitly set `secure=False`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Before calling `make_bucket`, check `if not client.bucket_exists(bucket_name): client.make_bucket(bucket_name)` or wrap `make_bucket` in a `try...except S3Error as e: if e.code == 'BucketAlreadyOwnedByYou': ...` block.","message":"The `Minio.make_bucket()` method will raise a `BucketAlreadyOwnedByYou` error if the bucket already exists. It's often safer to check for existence first or handle the specific exception.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Use `from minio.error import S3Error` and wrap your MinIO operations in a `try...except S3Error as e:` block.","message":"All MinIO-specific errors are derived from `minio.error.S3Error`. For robust error handling, catch this specific exception.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}