bucket¶
S3 Vector Bucket Management
This module provides functionality for managing S3 vector buckets, including bucket creation with proper error handling. It integrates with the AWS S3 Vectors service to provide a Pythonic interface for bucket operations.
The module handles common AWS operations such as bucket creation and provides appropriate error handling for scenarios like bucket name conflicts.
- Example:
>>> bucket = Bucket(name="my-vector-bucket") >>> result = bucket.create(s3_vectors_client)
- class s3vectorm.bucket.Bucket(*, name: str)[source]¶
Represents an S3 vector bucket for storing and managing vector data.
This class provides a Pydantic model for S3 vector buckets with methods to create buckets in AWS S3 Vectors service. It handles common operations and error scenarios gracefully.
- Attributes:
name: The name of the vector bucket
- Example:
>>> bucket = Bucket(name="my-vector-bucket") >>> result = bucket.create(s3_vectors_client) >>> if result is not None: ... print("Bucket created successfully") ... else: ... print("Bucket already exists")
- create(s3_vectors_client: S3VectorsClient, encryption_configuration: EncryptionConfiguration = OPT) dict[str, Any] | None[source]¶
Create the vector bucket in AWS S3 Vectors service.
This method attempts to create a new S3 vector bucket with the specified name and optional encryption configuration. It handles the common case where a bucket with the same name already exists by returning None instead of raising an exception.
- Parameters:
s3_vectors_client – The AWS S3 Vectors client to use for the operation
encryption_configuration – Optional encryption settings for the bucket. If not provided, default encryption will be used.
- Returns:
A dictionary containing the AWS response if the bucket was created successfully, or None if the bucket already exists.
- Raises:
- botocore.exceptions.ClientError: For AWS errors other than bucket
name conflicts (e.g., permission errors, invalid bucket names).
- Example:
>>> bucket = Bucket(name="my-new-bucket") >>> client = boto3.client('s3vectors') >>> result = bucket.create(client) >>> if result: ... print(f"Created bucket: {result}") ... else: ... print("Bucket already exists")
- Reference:
- delete(s3_vectors_client: S3VectorsClient, vector_bucket_arn: str = OPT)[source]¶
Note
You have to delete all indexes in bucket before you can delete the bucket.
- list_index(s3_vectors_client: S3VectorsClient, vector_bucket_arn: str = OPT, prefix: str = OPT, page_size: int = 100, max_items: int = 9999) Generator[ListIndexesOutput, None, None][source]¶
List all indexes in the vector bucket with pagination support.
This method retrieves all vector indexes within the bucket using pagination to handle buckets with many indexes efficiently. It supports filtering by index name prefix.
- Parameters:
s3_vectors_client – The AWS S3 Vectors client to use for the operation
vector_bucket_arn – Optional ARN of the vector bucket. If provided, takes precedence over bucket name
prefix – Optional prefix to filter index names
page_size – Number of indexes per page (default: 100)
max_items – Maximum total number of indexes to retrieve (default: 9999)
- Yields:
Dict responses containing paginated index results
- Example:
>>> bucket = Bucket(name="my-bucket")
>>> for res in bucket.list_index(client): ... for index_summary in res.indexes: ... print(index_summary)
- Reference:
- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].