Help Center> Object Storage Service> SDK Reference> Python> Objects-Related APIs> Downloading an Object – Obtaining the Download Progress

Downloading an Object – Obtaining the Download Progress

You can set the callback function to obtain download progress. Sample code is as follows:

# Import the module.
from obs import ObsClient
  
# Create an ObsClient instance.
obsClient = ObsClient(
    access_key_id='*** Provide your Access Key ***',    
    secret_access_key='*** Provide your Secret Key ***',    
    server='https://your-endpoint'
)
def callback(transferredAmount, totalAmount, totalSeconds):
    # Obtain the average download rate (KB/s).
    print(transferredAmount * 1.0 / totalSeconds / 1024)
    # Obtain the download progress in percentage.
    print(transferredAmount * 100.0 / totalAmount)

resp = obsClient.getObject('bucketname', 'objectname', progressCallback=callback)
if resp.status < 300:
    print('requestId:', resp.requestId)
    # Read the object content.
    while True:
        chunk = resp.body.response.read(65536)
        if not chunk:
            break
        print(chunk)
    resp.body.response.close()
else:
    print('errorCode:', resp.errorCode)
    print('errorMessage:', resp.errorMessage)

You can obtain the download progress when downloading an object in binary, streaming, file, or resumable mode.