This topic explains how to use OSS SDK for Python 2.0 to list all vector buckets in your Alibaba Cloud account. This operation supports paging.
Permissions
By default, an Alibaba Cloud account has full permissions on its resources. RAM users and RAM roles have no permissions by default. To allow a RAM user or RAM role to call this operation, an Alibaba Cloud account or a RAM administrator must grant the required permissions to the RAM user or RAM role using a RAM policy or a bucket policy.
|
API |
Action |
Description |
|
ListVectorBuckets |
|
Lists vector buckets. |
Method definition
OSS SDK for Python 2.0 provides two methods to list vector buckets:
-
list_vector_buckets(): Calls the operation directly. You must handle paging manually. -
list_vector_buckets_paginator(): Uses a paginator. The SDK automatically handles the paging logic. This method is recommended.
# Direct call
list_vector_buckets(request: ListVectorBucketsRequest, **kwargs) → ListVectorBucketsResult
Request parameters
|
Parameter |
Type |
Description |
|
request |
ListVectorBucketsRequest |
The request parameters. For more information, see ListVectorBucketsRequest |
Return values
|
Type |
Description |
|
ListVectorBucketsResult |
The return value. For more information, see ListVectorBucketsResult |
For the complete method definition, see list_vector_buckets.
# Use a paginator
list_vector_buckets_paginator(**kwargs) → ListVectorBucketsPaginator[source]
Return values
|
Type |
Description |
|
ListVectorBucketsPaginator |
The return value. For more information, see ListVectorBucketsPaginator |
For the complete definition of the method that uses a paginator, see list_vector_buckets_paginator.
Sample code
The following sample code uses a paginator to list all vector buckets. The SDK automatically handles paging requests, which simplifies the code.
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
cfg.use_internal_endpoint = True # To access OSS over the public network, set this parameter to False or delete this line.
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 for listing vector buckets, see list_vector_buckets.py.