GSSNS

Google’s official GCS library is not actually async

The official Google Cloud Storage library for Python google-cloud-storage offers an async interface, but there’s a catch: the underlying HTTP requests are still synchronous. This means you’re not getting true async I/O performance benefits.

Here’s an example using the official library:

from google.cloud import storage_v2

async def upload_with_official_client():
    client = storage_v2.StorageAsyncClient()
    bucket = client.bucket("my-bucket-name")
    blob = bucket.blob("path/to/gcs/folder")

    with open("/path/to/my/file", "r") as f:
        content = f.read()
        # This looks async but uses sync HTTP underneath which is still blocking
        await blob.upload_from_string(content)

For true async I/O, you can use the open source gcloud-aio-storage library, which implements proper async HTTP calls:

Example from their docs:

import aiofiles
import aiohttp
from gcloud.aio.storage import Storage


async with aiohttp.ClientSession() as session:
    client = Storage(session=session)

    async with aiofiles.open("/path/to/my/file", mode="r") as f:
        output = await f.read()
        status = await client.upload(
            "my-bucket-name",
            "path/to/gcs/folder",
            output,
        )
        print(status)

The difference becomes especially noticeable when uploading multiple files concurrently or when integrating with other async operations in your application.