gcloud-aio-storage

9.6.4 · active · verified Sun Mar 29

gcloud-aio-storage is an asyncio-compatible Python client library for Google Cloud Storage. It provides full CRUD operations for buckets and blobs, including streaming support for large files, parallel upload capabilities, and built-in session management. Designed for high-performance cloud storage operations with modern async/await patterns, it is currently at version 9.6.4 and follows an active release cadence.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the Storage client, upload a byte string, download it, and then delete the object. Ensure that Google Cloud authentication (e.g., via `GOOGLE_APPLICATION_CREDENTIALS` environment variable) and the `GCLOUD_PROJECT` environment variable are set, or provide them as arguments to the `Storage` client.

import asyncio
import os

from gcloud.aio.storage import Storage

async def main():
    # GCLOUD_PROJECT, GOOGLE_APPLICATION_CREDENTIALS, or similar env vars
    # should be set for authentication.
    project_id = os.environ.get('GCLOUD_PROJECT', 'your-gcp-project-id')
    bucket_name = 'your-gcs-bucket-name'
    file_name = 'hello_gcloud_aio.txt'
    content = b'Hello, gcloud-aio-storage!'

    async with Storage(project=project_id) as storage:
        print(f"Uploading '{file_name}' to bucket '{bucket_name}'...")
        await storage.upload(bucket_name, file_name, content, content_type='text/plain')
        print(f"'{file_name}' uploaded successfully.")

        print(f"Downloading '{file_name}' from bucket '{bucket_name}'...")
        downloaded_content = await storage.download(bucket_name, file_name)
        print(f"Downloaded content: {downloaded_content.decode()}")

        print(f"Deleting '{file_name}' from bucket '{bucket_name}'...")
        await storage.delete(bucket_name, file_name)
        print(f"'{file_name}' deleted successfully.")

if __name__ == '__main__':
    asyncio.run(main())

view raw JSON →