Use the Python SDK V2 to call ListVectorBuckets and retrieve all vector buckets in your Alibaba Cloud account. The operation supports paging.
Permissions
An Alibaba Cloud account has all permissions by default. Resource Access Management (RAM) users and RAM roles have no permissions by default. Grant permissions through a RAM policy or a bucket policy.
| API | Action | Description |
|---|---|---|
| ListVectorBuckets | oss:ListVectorBuckets | Lists vector buckets. |
Methods
The SDK provides two methods:
| Method | Paging | When to use |
|---|---|---|
list_vector_buckets_paginator() | Automatic — the SDK handles all paging | Recommended for most use cases |
list_vector_buckets() | Manual — you handle paging manually | When you need direct control over each paging request |
list_vector_buckets_paginator (recommended)
Returns a ListVectorBucketsPaginator that automatically handles paging until all buckets are returned. No manual paging logic required.
list_vector_buckets_paginator(**kwargs) -> ListVectorBucketsPaginator[source]Return value
| Type | Description |
|---|---|
ListVectorBucketsPaginator | An auto-paging iterator over all vector buckets. See ListVectorBucketsPaginator. |
For the complete method definition, see list_vector_buckets_paginator.
list_vector_buckets
Calls the operation directly. Handle paging manually by tracking the continuation token across requests.
list_vector_buckets(request: ListVectorBucketsRequest, **kwargs) -> ListVectorBucketsResultRequest parameters
| Parameter | Type | Description |
|---|---|---|
request | ListVectorBucketsRequest | The request parameters. See ListVectorBucketsRequest. |
Return value
| Type | Description |
|---|---|
ListVectorBucketsResult | The result object. See ListVectorBucketsResult. |
For the complete method definition, see list_vector_buckets.
Sample code
The following example uses list_vector_buckets_paginator() to list all vector buckets. The SDK automatically handles paging — iter_page() fetches each page in sequence until all buckets are returned.
Minimal example
paginator = client.list_vector_buckets_paginator()
for page in paginator.iter_page(oss_vectors.models.ListVectorBucketsRequest()):
for o in page.buckets:
print(f'Bucket: {o.name}, {o.location}')Full example
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()References
For the complete sample code, see list_vector_buckets.py.