最近更新时间:2026-06-03 21:32:12
1. Python SDK从V1.4.0版本开始支持项目id过滤参数
project_ids。
2. Python SDK从V1.13.0版本开始支持根据Region、前缀、访问类型、存储类型进行过滤。
3. Python SDK从V1.17.0版本开始支持列出创建者信息。
from ks3.connection import Connection
# 金山云主账号AccessKey拥有所有API的访问权限,风险很高。
# 强烈建议您创建并使用子账号进行API访问或日常运维,请登录https://uc.console.ksyun.com/pro/iam/#/user/list创建子账号。
# 通过指定host(Endpoint),您可以在指定的地域使用存储空间。
c = Connection('<YOUR_ACCESS_KEY>', '<YOUR_SECRET_KEY>', host='<YOUR_REGION_ENDPOINT>')
# 获取客户所有的Bucket信息。
# 示例1:project_ids 为项目id,多个项目用“,”间隔
try:
buckets = c.get_all_buckets(project_ids="<YOUR_PROJECT_IDS>")
# 打印出bucket的信息。
for b in buckets:
print(b.name)
print(b.region)
print(b.VisitType)
print(b.type)
except Exception as e:
print('request_id: %s' % e.request_id)
print(e)
# SDK 1.13.0版本之后支持该功能
# 示例2:根据Region、前缀、访问类型、存储类型过滤Bucket
# 以 region:BEIJING,prefix:abc,visit_type:NORMAL,storage_type: NORMAL 为例
try:
buckets = c.get_all_buckets(region='BEIJING', prefix='abc', visit_type='NORMAL', storage_type='NORMAL')
# 打印出Bucket的信息。
for b in buckets:
print(b.name)
print(b.region)
print(b.VisitType)
print(b.type)
except Exception as e:
print('request_id: %s' % e.request_id)
print(e)
import base64
from ks3.connection import Connection
# 金山云主账号AccessKey拥有所有API的访问权限,风险很高。
# 强烈建议您创建并使用子账号进行API访问或日常运维,请登录https://uc.console.ksyun.com/pro/iam/#/user/list创建子账号。
# 通过指定host(Endpoint),您可以在指定的地域使用存储空间。
c = Connection('<YOUR_ACCESS_KEY>', '<YOUR_SECRET_KEY>', host='<YOUR_REGION_ENDPOINT>')
try:
buckets = c.get_all_buckets(region='BEIJING', prefix='abc', visit_type='NORMAL', storage_type='NORMAL')
# 打印出Bucket的信息。
for b in buckets:
print(b.name)
print(b.region)
print(b.VisitType)
print(b.type)
if (info := b.bucket_creator_info) is not None:
print(f"{base64.b64decode(info.access_key_id).decode()}, {base64.b64decode(info.krn).decode()}, {info.ip_address}")
except Exception as e:
print('request_id: %s' % e.request_id)
print(e)
有关列出存储空间详情,请参见List Buckets。
纯净模式
