google.cloud.storage.Client 的“受保护”成员是存储桶属性的映射,与您正在寻找的 API 表示文档非常匹配。它可能会发生变化,因为它不在公开的 API 中,但您可以清楚地了解现在可用的内容。这是一个sn-p:
#! /usr/bin/env python
from pprint import pprint
from typing import Dict
from google.cloud import storage
BUCKET_NAME = "your-bucket-here"
def get_bucket_metadata(bucket_name: str, gcs: storage.Client) -> Dict[str, str]:
bucket = gcs.get_bucket(bucket_name)
return bucket._properties
def main():
gcs = storage.Client()
metadata = get_bucket_metadata(BUCKET_NAME, gcs)
pprint(metadata)
if __name__ == "__main__":
main()
我通过运行print(dir(bucket)) 并检查可用的方法和属性发现了这一点。您可能会以这种方式找到其他对您感兴趣的人。
这是一个输出示例:
{'etag': 'CAE=',
'iamConfiguration': {'bucketPolicyOnly': {'enabled': False}},
'id': 'your-bucket-here',
'kind': 'storage#bucket',
'location': 'US-WEST1',
'metageneration': '1',
'name': 'your-bucket-here',
'projectNumber': '264682420247',
'selfLink': 'https://www.googleapis.com/storage/v1/b/your-bucket-here',
'storageClass': 'REGIONAL',
'timeCreated': '2019-02-20T21:53:30.130Z',
'updated': '2019-02-20T21:53:30.130Z'}
HTH。