You need to enable JavaScript to run this app.
Torch Object Storage

Torch Object Storage

Copy page
Download PDF
Vector bucket
DeleteVectorBucketPolicy(TOS Vectors Python SDK)
Copy page
Download PDF
DeleteVectorBucketPolicy(TOS Vectors Python SDK)
The delete_vector_bucket_policy API removes the access policy for a specified vector bucket. This article explains how to perform this action using the delete_vector_bucket_policy interface of the TOS Vectors Python SDK.​
Notes​
  • You need to fill in the region and endpoint in the sample code according to your actual scenario. For details, refer to Region and Endpoint.​
  • To prevent key leakage, the sample code reads the Access Key ID and Secret Access Key from environment variables. Therefore, before using the SDK, configure long-term credentials. For details, refer to Configure Long-Term Credentials.​
  • The TOS Vectors Python SDK supports temporary credentials and provides timeout, retry policies, and other flexible settings to enhance application security according to your business needs. For details, refer to Common Configuration Scenarios.​
  • Before deleting a vector bucket, ensure the bucket is empty, meaning all vector indexes have been deleted.​
Permissions required​
The root account has all permissions by default, while IAM users have no permissions by default. If you need to use a sub-account to perform the delete_vector_bucket_policy operation, the main account must grant the following permissions to the sub-account through IAM policy and bucket policy:​
tosvectors:DeleteVectorBucketPolicy​
Code example​
Delete vector bucket IAM policy​
​
# Delete the IAM policy for the vector bucket.​
import os​
import tos​
​
# Retrieve AK and SK information from environment variables.​
ak = os.getenv('TOS_ACCESS_KEY')​
sk = os.getenv('TOS_SECRET_KEY')​
# Fill in your endpoint and your region with the endpoint corresponding to the bucket's region. # For example, for China (Beijing), set your endpoint to https://tosvectors-cn-beijing.volces.com and your region to cn-beijing.​
endpoint = 'Provide your endpoint'​
region = 'Provide your region'​
vector_bucket_name = 'Provide your bucket name'​
​
# Get the account ID from the environment variable.​
account_id = os.getenv('TOS_ACCOUNT_ID')​
​
try:​
# Create a VectorClient object; all vector operations are handled through VectorClient.​
client = tos.VectorClient(ak, sk, endpoint, region)​
​
# Delete the IAM policy for the vector storage bucket.​
# vector_bucket_name: Vector bucket name, which needs to be created in advance.​
# account_id: Account ID, used for identity verification.​
result = client.delete_vector_bucket_policy(​
vector_bucket_name=vector_bucket_name,​
account_id=account_id​
)​
​
# Print deletion result.​
print('Delete the IAM policy for the vector bucket successfully.')​
print('Request ID:', result.request_id)​
print('Status Code:', result.status_code)​
print('Response Headers:', result.header)​
​
except tos.exceptions.TosClientError as e:​
# The operation failed and a client exception was caught. This is usually due to invalid request parameters or a network exception.​
print('fail with client error, message:{}, cause: {}'.format(e.message, e.cause))​
except tos.exceptions.TosServerError as e:​
# The operation failed and a server exception occurred. See the response for the error details.​
print('fail with server error, code: {}'.format(e.code))​
# Use the request ID for troubleshooting purposes. We strongly recommend including the request ID in the logs.​
print('error with request id: {}'.format(e.request_id))​
print('error with message: {}'.format(e.message))​
print('error with http code: {}'.format(e.status_code))​
print('error with ec: {}'.format(e.ec))​
print('error with request url: {}'.format(e.request_url))​
except Exception as e:​
print('fail with unknown error: {}'.format(e))​
​
Related documentation​
For the API documentation of DeleteVectorBucketPolicy, see DeleteVectorBucketPolicy.​
Last updated: 2026.02.06 18:01:47