Google Cloud Storage (GCS) is a scalable, fully managed object storage service that lets you store and retrieve any amount of data at any time. It supports storing unstructured data such as images, videos, backups, and datasets with high durability, availability, and security. The GCPStorageHandler enables seamless interaction with Google Cloud Storage for tasks like managing buckets, listing files, retrieving metadata, and fetching IAM policies.

Example

import os
from superagentx_handlers.gcp.storage import GCPStorageHandler

gcs_handler = GCPStorageHandler(
    service_account_info=os.getenv("GCP_SERVICE_ACCOUNT_JSON")
)
List Buckets:
Retrieve all buckets in the Google Cloud Storage project.
buckets = await gcs_handler.list_buckets()
print(buckets)
Get Bucket:
Retrieve detailed information about a specific bucket.
bucket_info = await gcs_handler.get_bucket("my-bucket")
print(bucket_info)
Get Bucket ACL:
Retrieve the Access Control List (ACL) of a bucket.
acl = await gcs_handler.get_bucket_acl("my-bucket")
print(acl)
Get Bucket CORS:
Retrieve the CORS configuration for a bucket.
cors = await gcs_handler.get_bucket_cors("my-bucket")
print(cors)
Get Bucket Encryption:
Retrieve the default KMS encryption key of a bucket.
encryption = await gcs_handler.get_bucket_encryption("my-bucket")
print(encryption)
Get Bucket Labels:
Retrieve all labels assigned to a bucket.
labels = await gcs_handler.get_bucket_labels("my-bucket")
print(labels)
Get Bucket Lifecycle Rules:
Retrieve lifecycle rules applied to a bucket.
rules = await gcs_handler.get_bucket_lifecycle_rules("my-bucket")
print(rules)
Get Bucket Location:
Retrieve the geographic location of a bucket.
location = await gcs_handler.get_bucket_location("my-bucket")
print(location)
Get Bucket Logging:
Retrieve the logging configuration of a bucket.
logging_cfg = await gcs_handler.get_bucket_logging("my-bucket")
print(logging_cfg)
Get Bucket Notifications:
Retrieve the notification configurations of a bucket.
notifications = await gcs_handler.get_bucket_notification_config("my-bucket")
print(notifications)
Get Bucket Owner:
Retrieve the ownership information of a bucket.
owner = await gcs_handler.get_bucket_owner("my-bucket")
print(owner)
Get Bucket IAM Policy:
Retrieve the IAM policy attached to a bucket.
iam_policy = await gcs_handler.get_bucket_iam_policy("my-bucket")
print(iam_policy)
Get All Buckets Info:
Retrieve full details (ACL, encryption, IAM, logging, notifications) of all buckets.
all_info = await gcs_handler.get_all_buckets_info()
print(all_info)
List Files:
List all files (blobs) in a bucket with an optional prefix.
files = await gcs_handler.list_files("my-bucket", prefix="folder/")
print(files)
Get File Info:
Retrieve metadata and properties of a file (blob) in a bucket.
file_info = await gcs_handler.get_file_info(
    bucket_name="my-bucket",
    file_name="data/report.csv"
)
print(file_info)