All Products
Search
Document Center

Object Storage Service:Transfer acceleration (Python SDK V1)

Last Updated:Nov 28, 2025

The transfer acceleration feature allows users worldwide to access objects stored in Object Storage Service (OSS) in a short period of time. This feature is suitable for scenarios where data must be transferred over long geographical distances. This feature can also be used to download or upload large objects that are gigabytes or terabytes in size.

Usage notes

  • In this topic, the public endpoint of the China (Hangzhou) region is used. If you want to access OSS from other Alibaba Cloud services in the same region as OSS, use an internal endpoint. For more information about OSS regions and endpoints, see Regions and endpoints.

  • In this topic, an OSSClient instance is created by using an OSS endpoint. If you want to create an OSSClient instance by using custom domain names or Security Token Service (STS), see Initialization.

Enable transfer acceleration

The following code provides an example of how to enable transfer acceleration for a bucket named `examplebucket`.

import oss2
from oss2.credentials import EnvironmentVariableCredentialsProvider

# Obtain access credentials from environment variables. Before you run the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are set.
auth = oss2.ProviderAuthV4(EnvironmentVariableCredentialsProvider())

# Specify the Endpoint for the region where the bucket is located. For example, if the bucket is in the China (Hangzhou) region, set the Endpoint to https://oss-cn-hangzhou.aliyuncs.com.
endpoint = "https://oss-cn-hangzhou.aliyuncs.com"
# Specify the region information that corresponds to the Endpoint, such as cn-hangzhou. Note: This parameter is required for V4 signatures.
region = "cn-hangzhou"

# Specify the bucket name, for example, examplebucket.
bucket = oss2.Bucket(auth, endpoint, "examplebucket", region=region)

# Set the transfer acceleration status of the bucket.
# If you set enabled to true, transfer acceleration is enabled. If you set enabled to false, transfer acceleration is disabled.
enabled = 'true'
bucket.put_bucket_transfer_acceleration(enabled)

Query the transfer acceleration status

The following code provides an example of how to query the transfer acceleration status of a bucket named `examplebucket`.

import oss2
from oss2.credentials import EnvironmentVariableCredentialsProvider

# Obtain access credentials from environment variables. Before you run the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are set.
auth = oss2.ProviderAuthV4(EnvironmentVariableCredentialsProvider())

# Specify the Endpoint for the region where the bucket is located. For example, if the bucket is in the China (Hangzhou) region, set the Endpoint to https://oss-cn-hangzhou.aliyuncs.com.
endpoint = "https://oss-cn-hangzhou.aliyuncs.com"
# Specify the region information that corresponds to the Endpoint, such as cn-hangzhou. Note: This parameter is required for V4 signatures.
region = "cn-hangzhou"

# Specify the bucket name, for example, examplebucket.
bucket = oss2.Bucket(auth, endpoint, "examplebucket", region=region)

# Query the transfer acceleration status of the bucket.
# If the return value is true, transfer acceleration is enabled for the bucket. If the return value is false, transfer acceleration is disabled for the bucket.
result = bucket.get_bucket_transfer_acceleration()
enabled_text = result.enabled
print("Returns whether to enable transfer acceleration: ", enabled_text)

References