Google Cloud Common API client library

1.9.0 · active · verified Tue Apr 14

google-cloud-common is a foundational Python library that provides generated Python types and common helpers for other Google Cloud client libraries. It is not typically used as a standalone application client but serves as an internal dependency for service-specific client libraries within the `google-cloud-python` ecosystem. The current version is 1.9.0. It is actively maintained as part of the broader Google Cloud Python client libraries, which have a frequent release cadence.

Warnings

Install

Imports

Quickstart

Since `google-cloud-common` primarily provides foundational types and helpers, it does not have a typical 'hello world' for direct use. This quickstart demonstrates how to set up and use a common Google Cloud client library (Google Cloud Storage) which relies on the common infrastructure provided by `google-cloud-common` for authentication and core functionality. This ensures your environment is correctly configured to use Google Cloud Python client libraries.

import os
from google.cloud import storage

# This example uses google-cloud-storage, which relies on common infrastructure
# like that provided by google-cloud-common for its base functionality and types.
# Ensure GOOGLE_APPLICATION_CREDENTIALS environment variable is set
# or running in a Google Cloud environment with default credentials.
# For local development, set GOOGLE_APPLICATION_CREDENTIALS to the path of your service account key file.
# os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = '/path/to/your/key.json'

try:
    # Initialize a client for Google Cloud Storage
    # This implicitly uses authentication mechanisms supported by google-cloud-common's underlying components.
    client = storage.Client()
    
    # Attempt to list buckets to verify authentication and client setup
    buckets = list(client.list_buckets())
    print(f"Successfully listed {len(buckets)} buckets.")
    if buckets:
        print(f"First bucket: {buckets[0].name}")
except Exception as e:
    print(f"An error occurred: {e}")
    print("Please ensure your Google Cloud environment is set up and authenticated.")
    print("  - Set GOOGLE_APPLICATION_CREDENTIALS to your service account key file path, or")
    print("  - Run in a Google Cloud environment (e.g., Cloud Shell, GCE, Cloud Run).")

view raw JSON →