使用Python SDK V2调用ListVectorBuckets接口列举当前阿里云账号下的所有向量 Bucket,支持分页查询。
权限说明
阿里云账号默认拥有全部权限。阿里云账号下的RAM用户或RAM角色默认没有任何权限,需要阿里云账号或账号管理员通过RAM Policy或Bucket Policy授予操作权限。
API | Action | 说明 |
ListVectorBuckets |
| 列举向量Bucket。 |
方法定义
Python SDK V2提供了两种方式列举向量Bucket:
list_vector_buckets()
:直接调用接口,需要手动处理分页。list_vector_buckets_paginator()
:使用分页器,SDK会自动处理分页逻辑,推荐使用。
# 直接调用
list_vector_buckets(request: ListVectorBucketsRequest, **kwargs) → ListVectorBucketsResult
请求参数列表
参数名 | 类型 | 说明 |
request | ListVectorBucketsRequest | 设置请求参数,具体请参见ListVectorBucketsRequest |
返回值列表
类型 | 说明 |
ListVectorBucketsResult | 返回值,具体请参见ListVectorBucketsResult |
关于获取向量Bucket信息方法的完整定义,请参见list_vector_buckets。
# 使用分页器
list_vector_buckets_paginator(**kwargs) → ListVectorBucketsPaginator[source]
返回值列表
类型 | 说明 |
ListVectorBucketsPaginator | 返回值,具体请参见ListVectorBucketsPaginator |
关于使用分页器列举向量Bucket方法的完整定义,请参见list_vector_buckets_paginator。
示例代码
推荐使用分页器(Paginator)列举所有向量Bucket,SDK会自动处理分页请求,代码更简洁。
import argparse
import alibabacloud_oss_v2 as oss
import alibabacloud_oss_v2.vectors as oss_vectors
parser = argparse.ArgumentParser(description="list vector buckets sample")
parser.add_argument('--region', help='The region in which the bucket is located.', required=True)
parser.add_argument('--endpoint', help='The domain names that other services can use to access OSS')
parser.add_argument('--account_id', help='The account id.', required=True)
def main():
args = parser.parse_args()
# Loading credentials values from the environment variables
credentials_provider = oss.credentials.EnvironmentVariableCredentialsProvider()
# Using the SDK's default configuration
cfg = oss.config.load_default()
cfg.credentials_provider = credentials_provider
cfg.region = args.region
cfg.account_id = args.account_id
if args.endpoint is not None:
cfg.endpoint = args.endpoint
client = oss_vectors.Client(cfg)
# Create the Paginator for the ListVectorBuckets operation
paginator = client.list_vector_buckets_paginator()
# Iterate through the vector bucket pages
for page in paginator.iter_page(oss_vectors.models.ListVectorBucketsRequest(
)
):
for o in page.buckets:
print(f'Bucket: {o.name}, {o.location}')
if __name__ == "__main__":
main()
相关文档
关于列举向量Bucket的完整示例代码,请参见list_vector_buckets.py。
该文章对您有帮助吗?