• Object Storage Service

  1. Help Center
  2. Object Storage Service
  3. Developer Guide (Python SDK)
  4. Bucket Management
  5. Deleting a Bucket

Deleting a Bucket

You can call ObsClient.deleteBucket to delete a bucket. Sample code is as follows:

# Import the module.
from com.obs.client.obs_client import ObsClient

# Create an instance of ObsClient.
obsClient = ObsClient(
    access_key_id='*** Provide your Access Key ***',    
    secret_access_key='*** Provide your Secret Key ***',    

# Delete a bucket.
resp = obsClient.deleteBucket('bucketname')
if resp.status < 300:    
    print('requestId:', resp.requestId)
    print('errorCode:', resp.errorCode)
    print('errorMessage:', resp.errorMessage)
  • Only empty buckets (without objects and part fragments) can be deleted.
  • Bucket deletion is a non-idempotence operation and will fail if the to-be-deleted bucket does not exist.