• Object Storage Service

obs
  1. Help Center
  2. Object Storage Service
  3. Developer Guide (Python SDK)
  4. Bucket Management
  5. Listing Buckets

Listing Buckets

You can call ObsClient.listBuckets to list buckets. 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 ***',    
    server='yourdomainname'
)

# List buckets.
resp = obsClient.listBuckets()
if resp.status < 300:    
    print('requestId:', resp.requestId)
    index = 1    
    for bucket in resp.body.buckets:
        print('bucket [' + str(index) + ']')        
        print('name:', bucket.name)        
        print('create_date:', bucket.create_date)        
        index += 1
else:    
    print('errorCode:', resp.errorCode)
    print('errorMessage:', resp.errorMessage)
NOTE:

Obtained bucket names are listed in the lexicographical order.