Google Cloud Meta-Package for Python
The `google-cloud` Python package was historically a meta-package designed to install all client libraries for Google Cloud services. However, it was deprecated in June 2018 and marked as inactive/archived. Users are strongly advised to install individual, product-specific client libraries (e.g., `google-cloud-storage`) rather than this meta-package. Its last released version is 0.34.0, from July 2018.
Warnings
- breaking The `google-cloud` PyPI package is deprecated and marked as inactive since June 2018. It no longer bundles individual client libraries. Installing it will not provide the expected functionality for modern Google Cloud interactions.
- gotcha Google Cloud client libraries use Application Default Credentials (ADC) for authentication. Failing to set up ADC (e.g., `gcloud auth application-default login` or `GOOGLE_APPLICATION_CREDENTIALS` env var) is a common reason for authentication errors.
- gotcha Individual `google-cloud-*` client libraries have their own release cycles and major version updates can introduce breaking changes. The changelog for each specific library should be consulted before upgrading.
- gotcha Google Cloud Client Libraries for Python are compatible with actively maintained Python versions. Using End-of-Life (EOL) Python versions (e.g., Python 3.7, 3.8) can lead to lack of support, security patches, and compatibility issues.
Install
-
pip install google-cloud -
pip install google-cloud-storage
Imports
- Client
from google.cloud import storage storage_client = storage.Client()
- storage
from google.cloud import storage
Quickstart
import os
from google.cloud import storage
# Ensure GOOGLE_APPLICATION_CREDENTIALS environment variable is set
# or gcloud is configured for Application Default Credentials.
# For example: export GOOGLE_APPLICATION_CREDENTIALS="/path/to/key.json"
try:
# Instantiates a client for Google Cloud Storage
storage_client = storage.Client()
# List all buckets in the project
buckets = list(storage_client.list_buckets())
if buckets:
print("Buckets:")
for bucket in buckets:
print(f" - {bucket.name}")
else:
print("No buckets found in the project.")
except Exception as e:
print(f"An error occurred: {e}")
print("Please ensure you have authenticated properly (e.g., 'gcloud auth application-default login')")
print("and have the necessary permissions for the Google Cloud project.")