Google Cloud Rest Auth

5.4.4 · active · verified Tue Apr 14

gcloud-rest-auth (part of the gcloud-aio project) provides asynchronous Python clients for Google Cloud Platform authentication. It leverages aiohttp for non-blocking I/O, offering an efficient way to interact with Google Cloud services in async applications. The current version is 5.4.4, with releases occurring as needed across its various sub-packages.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the `AioAuth` client and retrieve an access token. It automatically handles credential discovery. Remember to have your Google Cloud credentials configured (e.g., via `GOOGLE_APPLICATION_CREDENTIALS` environment variable or `gcloud` CLI).

import asyncio
import os
from gcloud_aio.auth import AioAuth

async def main():
    # AioAuth will automatically find credentials (e.g., from GOOGLE_APPLICATION_CREDENTIALS, gcloud CLI, metadata server)
    # For local development, ensure GOOGLE_APPLICATION_CREDENTIALS or gcloud is configured.
    # Example: export GOOGLE_APPLICATION_CREDENTIALS='/path/to/your/key.json'
    async with AioAuth() as client:
        try:
            token = await client.get_access_token()
            print(f"Successfully obtained access token: {token[:20]}...")
            # You can now use this token for authenticated requests to Google Cloud APIs
        except Exception as e:
            print(f"Failed to obtain access token: {e}")
            print("Please ensure your Google Cloud credentials are set up correctly.")

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

view raw JSON →