Google Cloud Python (google-cloud-storage / google-cloud-aiplatform)
Google Cloud's Python client libraries are split into per-service packages — there is no single 'google-cloud-python' package. Install only what you need: google-cloud-storage, google-cloud-bigquery, google-cloud-aiplatform, etc. Auth uses Application Default Credentials (ADC). Service account JSON is the most common auth method outside GCP. All packages share google-auth as the credential layer.
Warnings
- gotcha There is no single 'google-cloud-python' package on PyPI. It must be installed per-service. 'pip install google-cloud-python' installs nothing useful — it's a meta-package stub that does not bring in any service clients.
- gotcha DefaultCredentialsError is raised when no ADC credentials are found. Common in CI/CD when GOOGLE_APPLICATION_CREDENTIALS is not set and gcloud is not authenticated. On GCP services (Cloud Run, GKE, etc.) the metadata server provides credentials automatically.
- gotcha Service account JSON key files contain private keys — committing them to source control is a critical security issue. Google's Secret Manager or Workload Identity Federation are the recommended alternatives for production.
- gotcha Vertex AI (google-cloud-aiplatform) requires vertexai.init(project=..., location=...) before any model calls. Missing location= silently defaults to us-central1 — models not available in that region return 404 or permission errors.
- gotcha google-cloud-aiplatform ships weekly. The Vertex AI generative models API (GenerativeModel, generate_content) was added around v1.38 — older pinned versions don't have it and raise ImportError.
- gotcha google-auth, google-api-core, and protobuf version conflicts are extremely common when multiple google-cloud packages are installed. pip may silently downgrade shared dependencies, breaking other packages.
Install
-
pip install google-cloud-storage -
pip install google-cloud-bigquery -
pip install google-cloud-aiplatform
Imports
- google.cloud.storage (ADC)
from google.cloud import storage # ADC: reads GOOGLE_APPLICATION_CREDENTIALS env var or gcloud auth client = storage.Client() # Explicit service account from google.oauth2 import service_account credentials = service_account.Credentials.from_service_account_file('key.json') client = storage.Client(credentials=credentials, project='my-project') - google.cloud.aiplatform (Vertex AI)
import vertexai from vertexai.generative_models import GenerativeModel vertexai.init(project='my-project', location='us-central1') model = GenerativeModel('gemini-2.0-flash') response = model.generate_content('Hello')
Quickstart
import os
from google.cloud import storage
# Auth via GOOGLE_APPLICATION_CREDENTIALS env var pointing to service account JSON
# Or run 'gcloud auth application-default login' locally
client = storage.Client(project=os.environ['GOOGLE_CLOUD_PROJECT'])
# List buckets
buckets = list(client.list_buckets())
for bucket in buckets:
print(bucket.name)
# Upload a file
bucket = client.bucket('my-bucket')
blob = bucket.blob('hello.txt')
blob.upload_from_string('Hello, GCS!')
print(f'Uploaded to gs://my-bucket/hello.txt')