Help Center> Object Storage Service> SDK Reference> Python> Bucket-Related APIs> Obtaining Bucket Storage Information

Obtaining Bucket Storage Information

API Description

You can use this API to obtain storage information about a bucket, including the bucket size and number of objects in the bucket.

Method Definition

ObsClient.getBucketStorageInfo(bucketName)

Request Parameters

Field

Type

Optional or Mandatory

Description

bucketName

str

Mandatory

Bucket name

Returned Results

Type

Description

GetResult

SDK common result object

GetResult.body Type

Description

GetBucketStorageInfoResponse

Response result of the request for obtaining storage information about a bucket

Sample Code

try:
    resp = obsClient.getBucketStorageInfo('bucketname') 
     
    if resp.status < 300: 
        print('requestId:', resp.requestId) 
        print('size:', resp.body.size) 
        print('objectNumber:', resp.body.objectNumber) 
    else: 
        print('errorCode:', resp.errorCode) 
        print('errorMessage:', resp.errorMessage)
except:
    import traceback
    print(traceback.format_exc())