{"library":"storage3","code":"import os\nfrom storage3 import AsyncStorageClient\nimport asyncio\n\n# Replace with your Supabase project URL and API Key\nSUPABASE_URL = os.environ.get('SUPABASE_URL', 'https://your-project-id.supabase.co/storage/v1')\nSUPABASE_KEY = os.environ.get('SUPABASE_KEY', 'your_anon_public_key')\n\n# Headers are required for authentication\nHEADERS = {\"apiKey\": SUPABASE_KEY, \"Authorization\": f\"Bearer {SUPABASE_KEY}\"}\n\nasync def main():\n    storage_client = AsyncStorageClient(SUPABASE_URL, HEADERS)\n    \n    print(\"Listing buckets...\")\n    try:\n        buckets = await storage_client.list_buckets()\n        if buckets:\n            print(f\"Found {len(buckets)} bucket(s): {[b['name'] for b in buckets]}\")\n        else:\n            print(\"No buckets found. Attempting to create one...\")\n            new_bucket = await storage_client.create_bucket('my-test-bucket-py', {'public': True})\n            print(f\"Created bucket: {new_bucket['name']}\")\n            buckets = [new_bucket]\n\n        if buckets:\n            bucket_name = buckets[0]['name']\n            print(f\"Using bucket: {bucket_name}\")\n\n            # Example: Uploading a dummy file (requires a file_object, e.g., from an open file)\n            # For a real scenario, replace `b'Hello, Supabase Storage!'` with actual file data\n            file_content = b'Hello, Supabase Storage from Python!'\n            file_name = 'hello_world.txt'\n            \n            print(f\"Uploading file '{file_name}' to bucket '{bucket_name}'...\")\n            upload_response = await storage_client.from_(bucket_name).upload(\n                f'public/{file_name}', \n                file_content,\n                {'content-type': 'text/plain'}\n            )\n            print(f\"Upload successful: {upload_response}\")\n            \n            # Example: Listing files in the bucket\n            print(f\"Listing files in bucket '{bucket_name}'...\")\n            files = await storage_client.from_(bucket_name).list(path='public/')\n            print(f\"Files in bucket '{bucket_name}': {[f['name'] for f in files]}\")\n\n            # Example: Downloading the file\n            print(f\"Downloading file '{file_name}' from bucket '{bucket_name}'...\")\n            downloaded_data = await storage_client.from_(bucket_name).download(f'public/{file_name}')\n            print(f\"Downloaded content: {downloaded_data.decode()}\")\n\n            # Example: Deleting the file\n            print(f\"Deleting file '{file_name}' from bucket '{bucket_name}'...\")\n            delete_response = await storage_client.from_(bucket_name).remove([f'public/{file_name}'])\n            print(f\"Delete successful: {delete_response}\")\n\n    except Exception as e:\n        print(f\"An error occurred: {e}\")\n\nif __name__ == \"__main__\":\n    asyncio.run(main())\n","lang":"python","description":"This quickstart demonstrates how to initialize the `AsyncStorageClient`, list existing buckets (and optionally create one), upload a file, list files within a bucket, download a file, and finally delete the uploaded file. Ensure you have your Supabase project URL and API key set as environment variables (SUPABASE_URL and SUPABASE_KEY) for authentication.","tag":null,"tag_description":null,"last_tested":"2026-04-24","results":[{"runtime":"python:3.10-alpine","exit_code":0},{"runtime":"python:3.10-slim","exit_code":0},{"runtime":"python:3.11-alpine","exit_code":0},{"runtime":"python:3.11-slim","exit_code":0},{"runtime":"python:3.12-alpine","exit_code":0},{"runtime":"python:3.12-slim","exit_code":0},{"runtime":"python:3.13-alpine","exit_code":0},{"runtime":"python:3.13-slim","exit_code":0},{"runtime":"python:3.9-alpine","exit_code":0},{"runtime":"python:3.9-slim","exit_code":0}]}