All Products
Search
Document Center

Object Storage Service:OSS Python SDK V2

Last Updated:Jun 20, 2026

GitHub | OSS SDK for Python 2.0 Developer Guide | OSS SDK for Python 2.0 Docs

Quick start

image

Prerequisites

You need Python 3.8 or later.

To check your Python version, run the python --version command. If Python is not installed or your version is lower than 3.8, download and install Python.

Install the SDK

  • Install the latest version to ensure the code examples run correctly.

    pip install alibabacloud-oss-v2
  • Import the SDK package:

    import alibabacloud_oss_v2 as oss

Configure access credentials

Configure credentials with a RAM user's AccessKey pair.

  1. In the RAM console, create a RAM user and select Using permanent AccessKey to access. Save the AccessKey pair, and then grant the AliyunOSSFullAccess permission to the user.

  2. Use the RAM user's AccessKey pair to configure environment variables.

    Linux

    1. Append the environment variables to the ~/.bashrc file.

      echo "export OSS_ACCESS_KEY_ID='YOUR_ACCESS_KEY_ID'" >> ~/.bashrc
      echo "export OSS_ACCESS_KEY_SECRET='YOUR_ACCESS_KEY_SECRET'" >> ~/.bashrc
      1. Apply the changes.

        source ~/.bashrc
      2. Verify the environment variables.

        echo $OSS_ACCESS_KEY_ID
        echo $OSS_ACCESS_KEY_SECRET

    macOS

    1. Check the default shell type.

      echo $SHELL
      1. Follow the steps for your shell type.

        Zsh

        1. Append the environment variables to the ~/.zshrc file.

          echo "export OSS_ACCESS_KEY_ID='YOUR_ACCESS_KEY_ID'" >> ~/.zshrc
          echo "export OSS_ACCESS_KEY_SECRET='YOUR_ACCESS_KEY_SECRET'" >> ~/.zshrc
        2. Apply the changes.

          source ~/.zshrc
        3. Verify the environment variables.

          echo $OSS_ACCESS_KEY_ID
          echo $OSS_ACCESS_KEY_SECRET

        Bash

        1. Append the environment variables to the ~/.bash_profile file.

          echo "export OSS_ACCESS_KEY_ID='YOUR_ACCESS_KEY_ID'" >> ~/.bash_profile
          echo "export OSS_ACCESS_KEY_SECRET='YOUR_ACCESS_KEY_SECRET'" >> ~/.bash_profile
        2. Apply the changes.

          source ~/.bash_profile
        3. Verify the environment variables.

          echo $OSS_ACCESS_KEY_ID
          echo $OSS_ACCESS_KEY_SECRET

    Windows

    CMD

    1. Set the environment variables in CMD.

      setx OSS_ACCESS_KEY_ID "YOUR_ACCESS_KEY_ID"
      setx OSS_ACCESS_KEY_SECRET "YOUR_ACCESS_KEY_SECRET"
      1. Verify the environment variables.

        echo %OSS_ACCESS_KEY_ID%
        echo %OSS_ACCESS_KEY_SECRET%

    PowerShell

    1. Set the environment variables in PowerShell.

      [Environment]::SetEnvironmentVariable("OSS_ACCESS_KEY_ID", "YOUR_ACCESS_KEY_ID", [EnvironmentVariableTarget]::User)
      [Environment]::SetEnvironmentVariable("OSS_ACCESS_KEY_SECRET", "YOUR_ACCESS_KEY_SECRET", [EnvironmentVariableTarget]::User)
      1. Verify the environment variables.

        [Environment]::GetEnvironmentVariable("OSS_ACCESS_KEY_ID", [EnvironmentVariableTarget]::User)
        [Environment]::GetEnvironmentVariable("OSS_ACCESS_KEY_SECRET", [EnvironmentVariableTarget]::User)

Initialize client

Important

Due to a policy change to improve compliance and security, starting March 20, 2025, new OSS users must use a custom domain name (CNAME) to perform data API operations on OSS buckets located in Chinese mainland regions. Default public endpoints are restricted for these operations. Refer to the official announcement for a complete list of the affected operations. If you access your data via HTTPS, you must bind a valid SSL Certificate to your custom domain. This is mandatory for OSS Console access, as the console enforces HTTPS.

Before you run the sample code, replace placeholders such as <region-id> with the actual region and endpoint, such as ap-southeast-1.

Sync OSSClient

import alibabacloud_oss_v2 as oss

def main():
    """
    Configuration details for initializing the Python SDK V2 client:

    1. Signature version: The SDK uses Signature V4 by default for enhanced security.
    2. Region configuration: When you initialize the client, you must specify an Alibaba Cloud region ID.
    3. Endpoint configuration:
       - You can use the endpoint parameter to specify a custom endpoint for service requests.
       - If you do not specify an endpoint, the SDK automatically constructs a public endpoint based on the specified region.
    4. Protocol configuration:
       - The SDK uses HTTPS to construct the endpoint by default.
       - To use HTTP, you must explicitly specify the protocol in the endpoint.
    """

    # Load credentials from environment variables for authentication.
    credentials_provider = oss.credentials.EnvironmentVariableCredentialsProvider()

    # Load the default SDK configurations and set the credentials provider.
    cfg = oss.config.load_default()
    cfg.credentials_provider = credentials_provider

    # Method 1: Specify only the region (Recommended).
    # You must specify a region ID. The SDK automatically constructs an HTTPS endpoint based on the region.
    cfg.region = '<region-id>' 

    # # Method 2: Specify both the region and the endpoint.
    # # You must specify a region ID.
    # cfg.region = '<region-id>'
    # # Specify the public endpoint of the region where the bucket is located.
    # cfg.endpoint = '<endpoint>'

    # Create an OSS client with the specified configurations.
    client = oss.Client(cfg)

    # Define the string to upload.
    text_string = "Hello, OSS!"
    data = text_string.encode('utf-8')  # Encode the string as a UTF-8 byte string.

    # Send a request to upload the object. Specify the bucket name, object key, and data.
    result = client.put_object(oss.PutObjectRequest(
        bucket="Your Bucket Name",
        key="Your Object Key",
        body=data,
    ))

    # Print the status code, request ID, and ETag to verify that the request was successful.
    print(f'status code: {result.status_code}\n'
          f'request id: {result.request_id}\n'
          f'etag: {result.etag}'
    )

# When this script is run directly, call the main function.
if __name__ == "__main__":
    main()

Async OSSClient

Async OSSClient requirements:

  • alibabacloud-oss-v2: >= 1.2.0

  • Install aiohttp: pip install aiohttp

import asyncio
import alibabacloud_oss_v2 as oss
import alibabacloud_oss_v2.aio as oss_aio

async def main():
    """
    Configuration details for initializing the Python SDK V2 async client:

    1. Signature version: The SDK uses Signature V4 by default for enhanced security.
    2. Region configuration: When you initialize the AsyncClient, you must specify an Alibaba Cloud region ID.
    3. Endpoint configuration:
       - You can use the endpoint parameter to specify a custom endpoint for service requests.
       - If you do not specify an endpoint, the SDK automatically constructs a public endpoint based on the specified region.
    4. Protocol configuration:
       - The SDK uses HTTPS to construct the endpoint by default.
       - To use HTTP, you must explicitly specify the protocol in the endpoint.
    5. Asynchronous features:
       - Import the async module: import alibabacloud_oss_v2.aio as oss_aio
       - Create an async client: oss_aio.AsyncClient(cfg)
       - All operations require the await keyword.
       - You must call await client.close() in a finally block to close the connection.
       - You must install the aiohttp dependency: pip install aiohttp
    """

    # Load credentials from environment variables for authentication.
    credentials_provider = oss.credentials.EnvironmentVariableCredentialsProvider()

    # Load the default SDK configurations and set the credentials provider.
    cfg = oss.config.load_default()
    cfg.credentials_provider = credentials_provider

    # Method 1: Specify only the region (Recommended).
    # You must specify a region ID. The SDK automatically constructs an HTTPS endpoint based on the region.
    cfg.region = '<region-id>'

    # # Method 2: Specify both the region and the endpoint.
    # # You must specify a region ID.
    # cfg.region = '<region-id>'
    # # Specify the public endpoint of the region where the bucket is located.
    # cfg.endpoint = '<endpoint>'

    # Create an OSS async client with the specified configurations.
    client = oss_aio.AsyncClient(cfg)

    try:
        # Define the string to upload.
        text_string = "Hello, OSS!"
        data = text_string.encode('utf-8')  # Encode the string as a UTF-8 byte string.

        # Send an async request to upload the object. Specify the bucket name, object key, and data.
        # Note: Use the await keyword to wait for the async operation to complete.
        result = await client.put_object(
            oss.PutObjectRequest(
                bucket="Your Bucket Name",
                key="Your Object Key",
                body=data,
            )
        )

        # Print the status code, request ID, and ETag to verify that the request was successful.
        print(f'status code: {result.status_code}\n'
              f'request id: {result.request_id}\n'
              f'etag: {result.etag}'
        )

    except Exception as e:
        print(f'Upload failed: {e}')

    finally:
        # Close the async client connection to prevent resource leaks.
        await client.close()

# When this script is run directly, call the main function.
if __name__ == "__main__":
    # Use asyncio.run() to run the async main function.
    asyncio.run(main())

Successful upload output:

status code: 200
request id: 6875F95738B0ED3030F086A0
etag: "56AAD346F0899BFE8BDD02C06BBE511E"

Client configuration

Parameter

Description

Example

region

(Required) The region to which requests are sent.

oss.config.Config(region="<region-id>")

credentials_provider

(Required) The access credential provider.

oss.config.Config(credentials_provider=provider)

endpoint

The service endpoint. If not specified, the client automatically generates an endpoint from the region.

oss.config.Config(endpoint="oss-<region-id>.aliyuncs.com")

http_client

The HTTP client. If not specified, the client uses a default HTTP client.

oss.config.Config(http_client=customClient)

retry_max_attempts

The maximum number of retries for a failed HTTP request. The default is 3.

oss.config.Config(retry_max_attempts=5)

retryer

A custom retry strategy for HTTP requests.

oss.config.Config(retryer=customRetryer)

connect_timeout

The connection timeout in seconds. The default is 10.

oss.config.Config(connect_timeout=20)

readwrite_timeout

The read/write timeout in seconds. The default is 20.

oss.config.Config(readwrite_timeout=30)

insecure_skip_verify

Skips SSL certificate verification. The default is false (verification is performed).

oss.config.Config(insecure_skip_verify=true)

enabled_redirect

Enables HTTP redirection. The default is false.

oss.config.Config(enabled_redirect=true)

proxy_host

The proxy server for requests.

oss.config.Config(proxy_host="http://user:passswd@proxy.example-***.com")

signature_version

The signature version to use. The default is v4.

oss.config.Config(signature_version="v1")

disable_ssl

Disables SSL and uses HTTP. The default is false (HTTPS is used).

oss.config.Config(disable_ssl=true)

use_path_style

Indicates whether to use path-style addressing (for example, https://endpoint/bucket-name). The default, false, uses virtual-hosted-style addressing (for example, https://bucket-name.endpoint).

oss.config.Config(use_path_style=true)

use_cname

Uses a custom domain name for access. The default is false.

oss.config.Config(use_cname=true)

use_dualstack_endpoint

Uses a dual-stack endpoint for access. The default is false.

oss.config.Config(use_dualstack_endpoint=true)

use_accelerate_endpoint

Uses an acceleration endpoint for access. The default is false.

oss.config.Config(use_accelerate_endpoint=true)

use_internal_endpoint

Uses an internal endpoint for access. The default is false.

oss.config.Config(use_internal_endpoint=true)

disable_upload_crc64_check

Disables the CRC64 check for uploads. The default is false (the check is enabled).

oss.config.Config(disable_upload_crc64_check=true)

disable_download_crc64_check

Disables the CRC64 check for downloads. The default is false (the check is enabled).

oss.config.Config(disable_download_crc64_check=true)

additional_headers

Specifies additional request headers to include in the signature. This parameter applies only to signature version v4.

oss.config.Config(additional_headers=["content-length"])

user_agent

Specifies a custom string to append to the User-Agent header.

oss.config.Config(user_agent="user identifier")

Custom domain name

Custom domain names enable object previews in a browser and CDN-accelerated delivery.

Before running the sample code, replace the <region-id> placeholder with the region and endpoint, for example, ap-southeast-1.
import alibabacloud_oss_v2 as oss

def main():
    # Load credentials from environment variables.
    credentials_provider = oss.credentials.EnvironmentVariableCredentialsProvider()

    # Load the default SDK configurations and set the credentials provider.
    cfg = oss.config.load_default()
    cfg.credentials_provider = credentials_provider

    # Specify the bucket's region.
    cfg.region = '<region-id>'

    # Specify your custom domain name. For example, www.example-***.com.
    cfg.endpoint = 'https://www.example-***.com'

    # Set use_cname to True to use a custom domain name.
    cfg.use_cname = True

    # Create an OSS client.
    client = oss.Client(cfg)

    # Use the client for subsequent operations.

# Script entry point.
if __name__ == "__main__":
    main()

Timeout control

Before you run the sample code, replace the <region-id> placeholder with a region and endpoint, such as ap-southeast-1.
import alibabacloud_oss_v2 as oss
from typing import Dict, Any

def main():
    # Load credentials from environment variables.
    credentials_provider = oss.credentials.EnvironmentVariableCredentialsProvider()

    # Load the default configuration.
    cfg = oss.config.load_default()

    # Override the default connection timeout (10 seconds).
    cfg.connect_timeout = 30

    # Override the default read/write timeout (20 seconds).
    cfg.readwrite_timeout = 30

    # Set the credentials provider.
    cfg.credentials_provider = credentials_provider

    # Specify the region.
    cfg.region = '<region-id>'

    # Create an OSS client with the specified configuration.
    client = oss.Client(cfg)

# Run the main function when the script is executed directly.
if __name__ == "__main__":
    main()

Retry policy

Before running the sample code, replace the <region-id> placeholder with the region and endpoint, for example, ap-southeast-1.
import alibabacloud_oss_v2 as oss

def main():
    """
    SDK retry policy configuration:

    Default retry policy:
    If you do not configure a retry policy, the SDK uses StandardRetryer() by default. The default configuration is as follows:
    - max_attempts: The maximum number of retry attempts. Default: 3.
    - max_backoff: The maximum backoff time in seconds. Default: 20.
    - base_delay: The base delay time in seconds. Default: 0.2.
    - backoff_delayer: The backoff algorithm. The SDK uses exponential backoff with jitter (FullJitter) by default.
      Formula: random.uniform(0, 1) * min(2 ** attempts * base_delay, max_backoff)
    - error_retryables: The types of retryable errors. For more information, see https://gosspublic.alicdn.com/sdk-doc/alibabacloud-oss-python-sdk-v2/latest/_modules/alibabacloud_oss_v2/retry/error_retryable.html

    When a retryable error occurs, the client delays and retries the request according to this configuration.
    The overall request latency increases with each retry. If the default configuration does not meet your requirements,
    you can customize the retry parameters or modify the retry implementation.
    """

    # Load credentials from environment variables.
    credentials_provider = oss.credentials.EnvironmentVariableCredentialsProvider()

    # Load the default configurations.
    cfg = oss.config.load_default()

    # Retry policy configuration examples:

    # 1. Customize the maximum number of retries (default: 3, set to 5 here).
    cfg.retryer = oss.retry.StandardRetryer(max_attempts=5)

    # 2. Customize the backoff delay time.
    # Adjust base_delay to 0.5 seconds (default: 0.2) and max_backoff to 25 seconds (default: 20).
    # cfg.retryer = oss.retry.StandardRetryer(max_backoff=25, base_delay=0.5)

    # 3. Customize the backoff algorithm.
    # Replace the default FullJitter algorithm with a fixed-delay backoff of 2 seconds.
    # cfg.retryer = oss.retry.StandardRetryer(backoff_delayer=oss.retry.FixedDelayBackoff(2))

    # 4. Disable the retry policy.
    # Use retry.NopRetryer() to disable all retry attempts.
    # cfg.retryer = oss.retry.NopRetryer()

    # Set the credentials provider.
    cfg.credentials_provider = credentials_provider

    # Specify the region where the bucket is located.
    cfg.region = '<region-id>'

    # Create an OSS client with the specified configurations.
    client = oss.Client(cfg)

    # Use the created client for subsequent operations...

# When this script is run directly, call the main function.
if __name__ == "__main__":
    main()

Set the connection pool size

For the http_client, use the max_connections parameter to set the connection pool size.

Before you run the sample code, replace the <region-id> placeholder with an actual region, for example, ap-southeast-1.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# OSS Python SDK V2 connection pool configuration example

import alibabacloud_oss_v2 as oss

def main():

    # Load access credentials from environment variables (OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET must be set).
    credentials_provider = oss.credentials.EnvironmentVariableCredentialsProvider()

    # Load the default SDK configuration and set the credentials provider.
    config = oss.config.load_default()
    config.credentials_provider = credentials_provider

    # Set the OSS service region.
    config.region = "<region-id>"

    # ============ Custom HTTP client configuration ============
    # Create a dictionary for the HTTP client configuration.
    http_client_config = {}
    
    # Set the connection pool size to 100. The default is 20.
    http_client_config["max_connections"] = 100
    
    # Create an HTTP client with the custom configuration.
    http_client = oss.transport.RequestsHttpClient(**http_client_config)
    
    # Set the custom HTTP client in the configuration object.
    config.http_client = http_client
    # ============================================
    
    # Initialize the OSS client instance.
    client = oss.Client(config)

    # Configure bucket and object information.
    bucket = "example-bucket"             # bucket name
    key = "dest.jpg"                      # object key in OSS
    file_path = "dest.jpg"                # Local save path

    # Download the object from OSS to the specified local path.
    client.get_object_to_file(oss.GetObjectRequest(bucket, key), file_path)
    print(f"Object download complete: {key} -> {file_path}")
    print(f"Connection pool size set to: {http_client_config['max_connections']}")

if __name__ == "__main__":
    # Program entry point
    try:
        main()
    except Exception as e:
        print(f"An error occurred during execution: {e}")
        raise

HTTP/HTTPS

Use cfg.disable_ssl = True to disable HTTPS requests.

Before running the sample code, replace the <region-id> placeholder with a region and endpoint, such as or ap-southeast-1.
import alibabacloud_oss_v2 as oss

def main():
    # Load credentials from environment variables.
    credentials_provider = oss.credentials.EnvironmentVariableCredentialsProvider()

    # Load the default SDK configuration and set the credentials provider.
    cfg = oss.config.load_default()
    cfg.credentials_provider = credentials_provider

    # Specify the client region.
    cfg.region = '<region-id>'

    # Disable HTTPS requests.
    cfg.disable_ssl = True

    # Create an OSS client using the specified configuration.
    client = oss.Client(cfg)

    # Use the created client to perform subsequent operations...

# The following entry point calls the main function when the script is run directly.
if __name__ == "__main__":
    main()

Proxy server

Configure a proxy server when corporate policies restrict direct internet access.

Before running the sample code, replace the <region-id> placeholder with a valid region and endpoint, for example, or ap-southeast-1.
import alibabacloud_oss_v2 as oss

def main():
    # Load credentials from environment variables for authentication.
    credentials_provider = oss.credentials.EnvironmentVariableCredentialsProvider()

    # Load the default SDK configurations and set the credentials provider.
    cfg = oss.config.load_default()
    cfg.credentials_provider = credentials_provider

    # Specify the region where the bucket is located.
    cfg.region = '<region-id>'

    # Set the user agent.
    cfg.user_agent = 'aliyun-sdk-python'

    # Set the proxy server.
    cfg.proxy_host = 'http://user:passswd@proxy.example-***.com'

    # Create an OSS client with the specified configurations.
    client = oss.Client(cfg)

    # Use the created client to perform subsequent operations...

# When this script is run directly, call the main function.
if __name__ == "__main__":
    main()

Use an internal endpoint

Access OSS resources in the same region through an internal endpoint to reduce costs and latency.

Before you run the sample code, replace placeholders such as <region-id> with your actual region and endpoint values, such as ap-southeast-1.
import alibabacloud_oss_v2 as oss

def main():
    # Load credentials from environment variables for authentication.
    credentials_provider = oss.credentials.EnvironmentVariableCredentialsProvider()

    # Load the default SDK configuration and set the credentials provider.
    cfg = oss.config.load_default()
    cfg.credentials_provider = credentials_provider

    # Method 1: Specify the region and set use_internal_endpoint to true.
    # Specify the region where the bucket is located.
    cfg.region = '<region-id>'
    cfg.use_internal_endpoint = True

    # # Method 2: Specify the region and endpoint directly.
    # # Specify the region where the bucket is located.
    # cfg.region = '<region-id>'
    # # Specify the internal endpoint for the bucket's region.
    # cfg.endpoint = '<endpoint>'

    # Create the OSS client.
    client = oss.Client(cfg)

    # Use the client for subsequent operations...

# Call the main function if the script is executed directly.
if __name__ == "__main__":
    main()

Transfer acceleration

Before you run the sample code, replace the <region-id> placeholder with a region and endpoint, for example, or ap-southeast-1.
import alibabacloud_oss_v2 as oss

def main():
    # Load credentials from environment variables.
    credentials_provider = oss.credentials.EnvironmentVariableCredentialsProvider()

    # Load default SDK configurations and set the credentials provider.
    cfg = oss.config.load_default()
    cfg.credentials_provider = credentials_provider

    # Method 1: Specify the region and set use_accelerate_endpoint to true.
    # Specify the bucket's region.
    cfg.region = '<region-id>'
    cfg.use_accelerate_endpoint = True

    # # Method 2: Directly specify the region and the acceleration endpoint.
    # # Specify the bucket's region.
    # cfg.region = '<region-id>'
    # # Specify the acceleration endpoint.
    # cfg.endpoint = 'https://oss-accelerate.aliyuncs.com'

    # Create an OSS client with the configuration.
    client = oss.Client(cfg)

    # Use this client for subsequent operations...

# Run the main function if the script is executed directly.
if __name__ == "__main__":
    main()

Use a dedicated domain

Before running the sample code, replace the <region-id> placeholder with your region and endpoint, such as ap-southeast-1.
import alibabacloud_oss_v2 as oss

def main():
    # Load credentials from environment variables.
    credentials_provider = oss.credentials.EnvironmentVariableCredentialsProvider()

    # Load the default SDK configurations and set the credentials provider.
    cfg = oss.config.load_default()
    cfg.credentials_provider = credentials_provider

    # Specify the region where the bucket is located.
    cfg.region = '<region-id>'

    # Specify your dedicated domain. For example, https://service.corp.example.com.
    cfg.endpoint = 'https://service.corp.example.com'

    # Create an OSS client with the specified configurations.
    client = oss.Client(cfg)

    # Use the created client to perform subsequent operations...

# When this script is run directly, call the main function.
if __name__ == "__main__":
    main()

Custom HTTP client

Replace the default HTTP client with cfg.http_client when standard configuration parameters are insufficient.

Before running the sample code, replace the <region-id> placeholder with a valid region and endpoint, for example, or ap-southeast-1.
import alibabacloud_oss_v2 as oss
from typing import Dict, Any

def main():
    # Load credentials from environment variables for authentication.
    credentials_provider = oss.credentials.EnvironmentVariableCredentialsProvider()

    # Load the default configuration.
    cfg = oss.config.load_default()

    # Set the parameters for the HTTP client.
    kwargs: Dict[str, Any] = {}

    # Set the session.
    # kwargs["session"] = requests.Session()

    # Set the adapter.
    # kwargs["adapter"] = HTTPAdapter()

    # Specifies whether to skip certificate verification. Default: false.
    # kwargs["insecure_skip_verify"] = False

    # Specifies whether to enable HTTP redirection. Default: false.
    # kwargs["enabled_redirect"] = False

    # Set the proxy server.
    # kwargs["proxy_host"] = config.proxy_host

    # Set the block size.
    # kwargs["block_size"] = 16 * 1024

    # Connection timeout in seconds. Default: 10.
    kwargs["connect_timeout"] = 30

    # Read-write timeout in seconds. Default: 20.
    kwargs["readwrite_timeout"] = 30

    # Maximum connections. Default: 20.
    kwargs["max_connections"] = 1024

    # Create an HTTP client with the specified parameters.
    cfg.http_client = oss.transport.RequestsHttpClient(**kwargs)

    # Set the credentials provider.
    cfg.credentials_provider = credentials_provider

    # Specify the region where the bucket is located.
    cfg.region = '<region-id>'

    # Create an OSS client with the specified configuration.
    client = oss.Client(cfg)

    # Use the client for subsequent OSS operations...

# Calls the main function when the script is executed directly.
if __name__ == "__main__":
    main()

Access credential configuration

Choose a credential method for your use case.

How to choose an access credential

Initialization method

Scenarios

Prerequisite

Credential type

Validity

Refresh method

Use the AccessKey of a RAM user

Long-running applications in secure environments without credential rotation needs.

Yes

AccessKey

Long-term

Manual rotation

Use an STS token

Applications in untrusted environments requiring time-limited, scoped access.

Yes

STS token

Temporary

Manual refresh

Use a RAM role ARN

Delegated access scenarios such as cross-account access.

Yes

STS token

Temporary

Auto-refresh

Use an ECS instance RAM role

Applications on Alibaba Cloud compute (ECS, ECI, or ACK worker nodes).

No

STS token

Temporary

Auto-refresh

Use an OIDC role ARN

Untrusted applications on ACK worker nodes.

No

STS token

Temporary

Auto-refresh

Use a custom access credential

Custom credential retrieval when built-in methods are insufficient.

Custom

Custom

Custom

Custom

Use a RAM user's AccessKey

Initialize the credential provider with an AccessKey pair (AccessKey ID and AccessKey Secret) of your Alibaba Cloud account or a RAM user. This method requires manual key management and carries higher security risk.

Warning
  • An Alibaba Cloud account has full permissions over its resources. A leaked AccessKey pair poses a significant security threat to your system. We strongly recommend that you do not use the AccessKey pair of an Alibaba Cloud account. Instead, use the AccessKey pair of a RAM user with the minimum required permissions.

  • To create an AccessKey pair for a RAM user, see Create an AccessKey pair. The AccessKey ID and AccessKey secret are displayed only when you create the pair. Save them in a secure location immediately. If you lose them, you cannot retrieve them and must create a new AccessKey pair.

Environment variables

  1. Use the AccessKey pair of a RAM user to configure environment variables.

    Linux

    1. Run the following commands on the CLI to add the configurations of the environment variables to the ~/.bashrc file:

      echo "export OSS_ACCESS_KEY_ID='YOUR_ACCESS_KEY_ID'" >> ~/.bashrc
      echo "export OSS_ACCESS_KEY_SECRET='YOUR_ACCESS_KEY_SECRET'" >> ~/.bashrc
      1. Apply the changes.

        source ~/.bashrc
      2. Check whether the environment variables have taken effect:

        echo $OSS_ACCESS_KEY_ID
        echo $OSS_ACCESS_KEY_SECRET

    macOS

    1. Run the following command in the terminal to view the default shell type:

      echo $SHELL
      1. Configure environment variables based on the default shell type.

        Zsh

        1. Run the following commands to add the configurations of the environment variables to the ~/.zshrc file:

          echo "export OSS_ACCESS_KEY_ID='YOUR_ACCESS_KEY_ID'" >> ~/.zshrc
          echo "export OSS_ACCESS_KEY_SECRET='YOUR_ACCESS_KEY_SECRET'" >> ~/.zshrc
        2. Apply the changes.

          source ~/.zshrc
        3. Check whether the environment variables have taken effect:

          echo $OSS_ACCESS_KEY_ID
          echo $OSS_ACCESS_KEY_SECRET

        Bash

        1. Run the following commands to add the configurations of the environment variables to the ~/.bash_profile file:

          echo "export OSS_ACCESS_KEY_ID='YOUR_ACCESS_KEY_ID'" >> ~/.bash_profile
          echo "export OSS_ACCESS_KEY_SECRET='YOUR_ACCESS_KEY_SECRET'" >> ~/.bash_profile
        2. Apply the changes.

          source ~/.bash_profile
        3. Check whether the environment variables have taken effect:

          echo $OSS_ACCESS_KEY_ID
          echo $OSS_ACCESS_KEY_SECRET

    Windows

    CMD

    1. Run the following commands in CMD:

      setx OSS_ACCESS_KEY_ID "YOUR_ACCESS_KEY_ID"
      setx OSS_ACCESS_KEY_SECRET "YOUR_ACCESS_KEY_SECRET"
      1. Check whether the environment variables take effect:

        echo %OSS_ACCESS_KEY_ID%
        echo %OSS_ACCESS_KEY_SECRET%

    PowerShell

    1. Run the following commands in PowerShell:

      [Environment]::SetEnvironmentVariable("OSS_ACCESS_KEY_ID", "YOUR_ACCESS_KEY_ID", [EnvironmentVariableTarget]::User)
      [Environment]::SetEnvironmentVariable("OSS_ACCESS_KEY_SECRET", "YOUR_ACCESS_KEY_SECRET", [EnvironmentVariableTarget]::User)
      1. Check whether the environment variable takes effect:

        [Environment]::GetEnvironmentVariable("OSS_ACCESS_KEY_ID", [EnvironmentVariableTarget]::User)
        [Environment]::GetEnvironmentVariable("OSS_ACCESS_KEY_SECRET", [EnvironmentVariableTarget]::User)
  2. After you update the system environment variables, restart or refresh your build and runtime environment, including your IDE, command-line interface, other desktop applications, and background services, to load the latest system environment variables.

  3. Use environment variables to pass credentials.

    Before you run the sample code, replace the <region-id> placeholder with a region and endpoint, for example, or ap-southeast-1.
    import alibabacloud_oss_v2 as oss
    
    def main():
        # Load credentials from environment variables for authentication.
        credentials_provider = oss.credentials.EnvironmentVariableCredentialsProvider()
    
        # Load the default SDK configurations and set the credential provider.
        cfg = oss.config.load_default()
        cfg.credentials_provider = credentials_provider
    
        # Specify the region where the bucket is located.
        cfg.region = '<region-id>'
    
        # Create an OSS client with the specified configurations.
        client = oss.Client(cfg)
    
        # Use the created client to perform subsequent operations...
    
    # When this script is run directly, call the main function.
    if __name__ == "__main__":
        main()  # Script entry point. Calls the main function when the file is run directly.

Static credentials

Hard-code an AccessKey pair for testing (not for production):

Warning

Do not embed credentials directly in your application in production environments. This method is for testing purposes only.

Before you run the sample code, replace the <region-id> placeholder with a region and endpoint, for example, or ap-southeast-1.
import alibabacloud_oss_v2 as oss

def main():
    # Create a static credential provider and explicitly set the AccessKey ID and AccessKey secret.
    # Replace the placeholders with the AccessKey ID and AccessKey secret of your RAM user.
    credentials_provider = oss.credentials.StaticCredentialsProvider(
        access_key_id="RAM AccessKey ID",
        access_key_secret="RAM AccessKey Secret"
    )

    # Load the default SDK configurations and set the credential provider.
    cfg = oss.config.load_default()
    cfg.credentials_provider = credentials_provider

    # Specify the region where the bucket is located.
    cfg.region = '<region-id>'

    # Create an OSS client with the specified configurations.
    client = oss.Client(cfg)

    # Use the created client to perform subsequent operations...

# When this script is run directly, call the main function.
if __name__ == "__main__":
    main()  # Script entry point. Calls the main function when the file is run directly.

Use temporary credentials from STS

Initialize the credential provider with temporary STS credentials (AccessKey ID, AccessKey Secret, and Security Token). Tokens must be refreshed manually before expiration.

Important

Environment variables

  1. Use temporary identity credentials to set environment variables.

    macOS/Linux/Unix

    Warning
    • These environment variables require the temporary identity credentials (AccessKey ID, AccessKey Secret, and Security Token) from STS, not the AccessKey ID and AccessKey Secret of a RAM user.

    • The AccessKey ID obtained from STS starts with STS., for example, STS.L4aBSCSJVMuKg5U1****.

    export OSS_ACCESS_KEY_ID=<STS_ACCESS_KEY_ID>
    export OSS_ACCESS_KEY_SECRET=<STS_ACCESS_KEY_SECRET>
    export OSS_SESSION_TOKEN=<STS_SECURITY_TOKEN>

    Windows

    Warning
    • These environment variables require the temporary identity credentials (AccessKey ID, AccessKey Secret, and Security Token) from STS, not the AccessKey ID and AccessKey Secret of a RAM user.

    • The AccessKey ID obtained from STS starts with STS., for example, STS.L4aBSCSJVMuKg5U1****.

    set OSS_ACCESS_KEY_ID=<STS_ACCESS_KEY_ID>
    set OSS_ACCESS_KEY_SECRET=<STS_ACCESS_KEY_SECRET>
    set OSS_SESSION_TOKEN=<STS_SECURITY_TOKEN>
  2. Configure the SDK to read credentials from the environment variables.

    Before you run the sample code, replace the <region-id> placeholder with an actual region and endpoint, for example, or ap-southeast-1.
    import alibabacloud_oss_v2 as oss
    
    def main():
        # Load credentials from environment variables.
        credentials_provider = oss.credentials.EnvironmentVariableCredentialsProvider()
    
        # Load the default SDK configurations and set the credential provider.
        cfg = oss.config.load_default()
        cfg.credentials_provider = credentials_provider
    
        # Specify the region where the Bucket is located.
        cfg.region = '<region-id>'
    
        # Create an OSS client with the specified configurations.
        client = oss.Client(cfg)
    
        # Use the created client to perform subsequent operations...
    
    # Script entry point
    if __name__ == "__main__":
        main()  # Calls the main function.

Static credentials

Hard-code temporary credentials directly (testing only):

Warning

Do not embed access credentials in your application in a production environment. This method is for testing purposes only.

Before you run the sample code, replace the <region-id> placeholder with an actual region and endpoint, for example, or ap-southeast-1.
import alibabacloud_oss_v2 as oss

def main():
    # Use the temporary AccessKey ID and AccessKey Secret from STS, not the credentials of your Alibaba Cloud account.
    # Note that the AccessKey ID from STS starts with "STS.".
    sts_access_key_id = 'STS.****************'
    sts_access_key_secret = 'yourAccessKeySecret'
    # Provide the Security Token obtained from STS.
    sts_security_token = 'yourSecurityToken'

    # Create a static credential provider and explicitly set the temporary AccessKey ID, AccessKey Secret, and Security Token.
    credentials_provider = oss.credentials.StaticCredentialsProvider(
        access_key_id=sts_access_key_id,
        access_key_secret=sts_access_key_secret,
        security_token=sts_security_token,
    )

    # Load the default SDK configurations and set the credential provider.
    cfg = oss.config.load_default()
    cfg.credentials_provider = credentials_provider

    # Specify the region where the Bucket is located.
    cfg.region = '<region-id>'

    # Create an OSS client with the specified configurations.
    client = oss.Client(cfg)

    # Use the created client to perform subsequent operations...

# Script entry point
if __name__ == "__main__":
    main()  # Calls the main function.

Use a RAM role ARN

Initialize the credential provider with a RAM role ARN for delegated access (such as cross-account). The SDK automatically refreshes the STS token via AssumeRole. Use the policy parameter to restrict permissions.

Important
  • An Alibaba Cloud account has full permissions over its resources. A leaked AccessKey pair poses a significant security risk to your account. Do not use the AccessKey pair of an Alibaba Cloud account. Use an AccessKey pair from a RAM user with only the minimum required permissions.

  • To create an AccessKey pair for a RAM user, see Create an AccessKey pair. The AccessKey ID and AccessKey secret are shown only once, during creation. You must save them immediately. If the AccessKey pair is lost, you must create a new one to replace it.

  • To obtain a RAM role ARN, see CreateRole - Create a RAM role.

  1. Add the alibabacloud_credentials dependency.

    pip install alibabacloud_credentials
  2. Configure the AccessKey pair and RAM role ARN as access credentials.

    Before you run the sample code, replace the <region-id> placeholder with the actual region and endpoint, for example, or ap-southeast-1.
    # -*- coding: utf-8 -*-
    import os
    from alibabacloud_credentials.client import Client
    from alibabacloud_credentials.models import Config
    import alibabacloud_oss_v2 as oss
    
    def main():
        config = Config(
            # The RAM user's AccessKey ID and AccessKey secret, retrieved from environment variables.
            access_key_id=os.getenv('ALIBABA_CLOUD_ACCESS_KEY_ID'),
            access_key_secret=os.getenv('ALIBABA_CLOUD_ACCESS_KEY_SECRET'),
            type='ram_role_arn',
            # The ARN of the RAM role to assume. Example: acs:ram::123456789012****:role/adminrole. You can set this using the ALIBABA_CLOUD_ROLE_ARN environment variable.
            role_arn='<RoleArn>',
            # The role session name. You can set this using the ALIBABA_CLOUD_ROLE_SESSION_NAME environment variable.
            role_session_name='<RoleSessionName>',
            # Optional. A more restrictive permission policy. Example: {"Statement": [{"Action": ["*"],"Effect": "Allow","Resource": ["*"]}],"Version":"1"}
            policy='<Policy>',
            # Optional. The session duration in seconds. Default: 3600 (1 hour).
            role_session_expiration=3600
        )
    
        cred_client = Client(config)
    
        def get_credentials_wrapper():
            cred = cred_client.get_credential()
            return oss.credentials.Credentials(access_key_id=cred.access_key_id, access_key_secret=cred.access_key_secret, security_token=cred.security_token)
    
        # Create a credential provider to dynamically load credentials.
        credentials_provider = oss.credentials.CredentialsProviderFunc(func=get_credentials_wrapper)
    
        # Load the default OSS SDK configurations.
        cfg = oss.config.load_default()
        cfg.credentials_provider = credentials_provider
    
        # Specify the region where the bucket is located.
        cfg.region = '<region-id>'
    
        # Create an OSS client instance.
        client = oss.Client(cfg)
    
        # Use the client for subsequent operations...
    
    if __name__ == "__main__":
        main()  # Script entry point. Calls the main function when the file is run directly.

Use an ECS instance RAM role

For applications on ECS instances, ECI instances, or Container Service for Kubernetes worker nodes, use an ECS instance RAM role. The SDK automatically refreshes the STS token without hardcoded credentials. Create a RAM role.

  1. Add the alibabacloud_credentials dependency.

    pip install alibabacloud_credentials
  2. Configure the ECS instance RAM role as the access credential.

    Before you run the sample code, replace the <region-id> placeholder with an actual region ID, for example, or ap-southeast-1.
    from alibabacloud_credentials.client import Client
    from alibabacloud_credentials.models import Config
    import alibabacloud_oss_v2 as oss
    
    def main():
        config = Config(
            type='ecs_ram_role',      # Specifies the access credential type. Must be 'ecs_ram_role'.
            role_name='EcsRoleExample'    # Optional: The name of the RAM role granted to the ECS instance. If omitted, the role name is automatically retrieved. We recommend that you set this parameter to reduce requests.
        )
    
        cred_client = Client(config)
    
        def get_credentials_wrapper():
            cred = cred_client.get_credential()
            return oss.credentials.Credentials(access_key_id=cred.access_key_id, access_key_secret=cred.access_key_secret, security_token=cred.security_token)
    
        # Create a credentials provider to dynamically load credentials.
        credentials_provider = oss.credentials.CredentialsProviderFunc(func=get_credentials_wrapper)
    
        # Load the default OSS SDK configurations.
        cfg = oss.config.load_default()
        cfg.credentials_provider = credentials_provider
    
        # Specify the region where the bucket is located.
        cfg.region = '<region-id>'
    
        # Create an OSS client instance.
        client = oss.Client(cfg)
    
        # Use the client for subsequent operations...
    
    if __name__ == "__main__":
        main()

OIDC role ARN

For untrusted applications on Container Service for Kubernetes worker nodes, use RRSA (RAM Roles for Service Accounts) to enforce least-privilege at the pod level. RRSA mounts an OIDC token file per pod and calls AssumeRoleWithOIDC to exchange it for a scoped STS token. Isolate pod permissions based on RRSA.

  1. Add the alibabacloud_credentials dependency.

    pip install alibabacloud_credentials
  1. Configure the OIDC role ARN as the access credential.

    Before you run the sample code, replace the <region-id> placeholder with a region and endpoint, for example, or ap-southeast-1.
    # -*- coding: utf-8 -*-
    import os
    from alibabacloud_credentials.client import Client
    from alibabacloud_credentials.models import Config
    import alibabacloud_oss_v2 as oss
    
    def main():
        config = Config(
            # Specify the credential type. The value is fixed to 'oidc_role_arn'.
            type='oidc_role_arn',
            # The ARN of the RAM role. You can set this value by using the ALIBABA_CLOUD_ROLE_ARN environment variable.
            role_arn=os.environ.get('<RoleArn>'),
            # The OIDC provider ARN. You can set this value by using the ALIBABA_CLOUD_OIDC_PROVIDER_ARN environment variable.
            oidc_provider_arn=os.environ.get('<OidcProviderArn>'),
            # The OIDC token file path. You can set this value by using the ALIBABA_CLOUD_OIDC_TOKEN_FILE environment variable.
            oidc_token_file_path=os.environ.get('<OidcTokenFilePath>'),
            # The role session name. You can set this value by using the ALIBABA_CLOUD_ROLE_SESSION_NAME environment variable.
            role_session_name='<RoleSessionName>',
            # A more restrictive permission policy. This parameter is optional. Example: {"Statement": [{"Action": ["*"],"Effect": "Allow","Resource": ["*"]}],"Version":"1"}
            policy='<Policy>',
            # The validity period of the role session in seconds. The default is 3600 seconds (1 hour). This parameter is optional.
            role_session_expiration=3600
        )
    
        cred_client = Client(config)
    
        def get_credentials_wrapper():
            cred = cred_client.get_credential()
            return oss.credentials.Credentials(access_key_id=cred.access_key_id, access_key_secret=cred.access_key_secret, security_token=cred.security_token)
    
        # Create a credentials provider to dynamically load credentials.
        credentials_provider = oss.credentials.CredentialsProviderFunc(func=get_credentials_wrapper)
    
        # Load the default OSS SDK configurations.
        cfg = oss.config.load_default()
        cfg.credentials_provider = credentials_provider
    
        # Specify the region where the bucket is located.
        cfg.region = '<region-id>'
    
        # Create an OSS client instance.
        client = oss.Client(cfg)
    
        # Use the client for subsequent operations...
    
    # Call the main function when this script is run directly.
    if __name__ == "__main__":
        main()  # Script entry point. Calls the main function when the file is run directly.

Custom access credentials

Customize credential retrieval with one of these approaches:

  1. Using the credentials.CredentialsProviderFunc interface

    Before you run the sample code, replace the <region-id> placeholder with the actual region and endpoint, for example, or ap-southeast-1.
    import argparse
    import alibabacloud_oss_v2 as oss
    import os
    
    def main():
    
        def get_credentials_wrapper():
            # Return long-term credentials.
            return oss.credentials.Credentials(access_key_id='access_key_id', access_key_secret='access_key_security')
            # Return temporary STS credentials.
            # return oss.credentials.Credentials(access_key_id='access_key_id', access_key_secret='access_key_security', security_token='security_token')
    
        credentials_provider = oss.credentials.CredentialsProviderFunc(func=get_credentials_wrapper)
    
       # Load the default SDK configurations and set the credentials provider.
        cfg = oss.config.load_default()
        cfg.credentials_provider = credentials_provider
        
        # Specify the region where the bucket is located.
        cfg.region = "<region-id>"
    
        # Create an OSS client with the specified configurations.
        client = oss.Client(cfg)
    
        # Use the client to perform subsequent operations...
    
    if __name__ == "__main__":
        main()  # Script entry point. Calls the main function when the file is run directly.
  2. Implementing the credentials.CredentialsProvider interface

    Before you run the sample code, replace the <region-id> placeholder with the actual region and endpoint, for example, or ap-southeast-1.
    # -*- coding: utf-8 -*-
    import alibabacloud_oss_v2 as oss
    
    class CredentialProviderWrapper(oss.credentials.CredentialsProvider):
        def get_credentials(self):
            # TODO
            # Customize the logic for obtaining access credentials.
    
            # Return long-term credentials: access_key_id, access_key_secret.
            return oss.credentials.Credentials('<access_key_id>', '<access_key_secret>')
    
            # Return temporary STS credentials: access_key_id, access_key_secret, token.
            # Temporary credentials must be refreshed before they expire.
            # return oss.credentials.Credentials('<access_key_id>', '<access_key_secret>', '<token>');
    
    def main():
        # Instantiate a custom credentials provider.
        credentials_provider = CredentialProviderWrapper()
    
        # Load the default OSS SDK configurations.
        cfg = oss.config.load_default()
        cfg.credentials_provider = credentials_provider
    
        # Specify the region where the bucket is located.
        cfg.region = '<region-id>'
    
        client = oss.Client(cfg)
    
        # Use the client to perform subsequent operations...
    
    if __name__ == "__main__":
        main()  # Script entry point. Calls the main function when the file is run directly.

Anonymous access

Access public-read OSS resources without credentials.

Before you run the sample code, replace the <region-id> placeholder with an actual region and endpoint, for example, or ap-southeast-1.
import alibabacloud_oss_v2 as oss

# Create an anonymous credentials provider.
credentials_provider = oss.credentials.AnonymousCredentialsProvider()

# Configure the client.
cfg = oss.config.load_default()
cfg.credentials_provider = credentials_provider
# Specify the bucket's region.
cfg.region = '<region-id>'

# Create an OSS client.
client = oss.Client(cfg)

Troubleshoot errors

When a request fails, the response includes an HTTP status code, message, request ID, and error code (EC). Use the EC to diagnose the root cause.

  1. For example, the following code triggers an error by attempting to download an object that does not exist.

    Before you run the sample code, replace placeholders such as <region-id> with an actual region and endpoint, for example, or ap-southeast-1.
    import alibabacloud_oss_v2 as oss
    
    def main():
        # Load credentials from environment variables for authentication.
        credentials_provider = oss.credentials.EnvironmentVariableCredentialsProvider()
    
        # Load the default SDK configurations and set the credentials provider.
        cfg = oss.config.load_default()
        cfg.credentials_provider = credentials_provider
    
        # Set the region in the configuration.
        cfg.region = '<region-id>'
    
        # Create an OSS client with the specified configurations.
        client = oss.Client(cfg)
    
        # Send a request to get the object, specifying the bucket name and object key.
        result = client.get_object(oss.GetObjectRequest(
            bucket="Your Bucket Name",  # Specify the bucket name.
            key="Your Object Key",  # Specify the object key.
        ))
    
        # Print the status code and request ID from the response.
        print(f'status code: {result.status_code},'
              f' request id: {result.request_id},'
        )
    
        # Use a context manager to ensure the resource is released.
        with result.body as body_stream:
            data = body_stream.read()
            print(f"Object read complete. Data length: {len(data)} bytes")
    
            path = "./get-object-sample.txt"
            with open(path, 'wb') as f:
                f.write(data)
            print(f"Object downloaded and saved to: {path}")
    
    if __name__ == "__main__":
        main()  # Script entry point.
  2. Running the script returns the following error. The response includes the line 'EC': '0026-00000001', which provides a unique identifier for the cause of the error.

    alibabacloud_oss_v2.exceptions.OperationError: operation error GetObject: Error returned by Service.
            Http Status Code: 404.
            Error Code: NoSuchKey.
            Request Id: 67CA9AD3ECB4DB3034E5A92D.
            Message: The specified key does not exist..
            EC: 0026-00000001.
            Timestamp: 2025-03-07 07:05:55+00:00.
            Request Endpoint: GET https://xxx.oss-cn-hangzhou.aliyuncs.com/asghdjfjdas.
  3. To diagnose the error, use the EC from the error output and follow these steps.

    1. Open the OpenAPI Self-service Diagnostic Platform.

    2. In the search box, enter the EC, for example, 0026-00000001, and then click Diagnose.

    3. Review the search results for the error's cause and solution. The diagnostics page details the Problem Description (the target object does not exist) and lists Possible Causes (for example, the object failed to upload or was deleted by a user, a lifecycle rule, or cross-region replication), a Problem Example, and a Solution. The solution might suggest using the HeadObject interface to verify the object exists, using the ListObjectVersions interface to check the VersionID, or reviewing configurations for naming conventions, lifecycle rules, user permissions, and cross-region replication. The References section at the bottom links to documentation for NoSuchKey and NoSuchVersion.

Code examples

Common operation code examples:

Description

Sample file

Create a bucket (Python SDK V2)

put_bucket.py

List buckets (Python SDK V2)

list_buckets.py

Check whether a bucket exists (Python SDK V2)

is_bucket_exist.py

Get the region of a bucket (Python SDK V2)

get_bucket_location.py

Get bucket information (Python SDK V2)

get_bucket_info.py

Get the storage capacity of a bucket (Python SDK V2)

get_bucket_stat.py

Delete a bucket (Python SDK V2)

delete_bucket.py

Resource groups (Python SDK V2)

Bucket tags (Python SDK V2)

Requester Pays (Python SDK V2)

Get endpoint information (Python SDK V2)

describe_regions.py

Simple upload (Python SDK V2)

put_object.py

Append upload (Python SDK V2)

append_object.py

Multipart upload (Python SDK V2)

complete_multipart_upload.py

Form upload (Python SDK V2)

post_object.py

Upload using a presigned URL (Python SDK V2)

presigner_put_object.py

File upload manager (Python SDK V2)

upload_file.py

Simple download (Python SDK V2)

get_object.py

Range download (Python SDK V2)

get_object.py

Read-only file-like access (Python SDK V2)

open_file.py

Download using a presigned URL (Python SDK V2)

presigner_get_object.py

File download manager (Python SDK V2)

download_file.py

Copy an object (Python SDK V2)

copy_object.py

Multipart copy (Python SDK V2)

upload_part_copy.py

File copy manager (Python SDK V2)

copier.py

Check whether an object exists (Python SDK V2)

is_object_exist.py

List objects (Python SDK V2)

list_objects_v2.py

Delete objects (Python SDK V2)

Restore an object (Python SDK V2)

Manage object metadata (Python SDK V2)

Change the storage class of an object (Python SDK V2)

copy_object.py

Rename an object (Python SDK V2)

copy_object.py

Manage symbolic links (Python SDK V2)

Manage bucket ACLs (Python SDK V2)

Manage object ACLs (Python SDK V2)

Bucket Policy (Python SDK V2)

put_bucket_policy.py

Manage versioning (Python SDK V2)

put_bucket_version.py

Hotlink protection (Python SDK V2)

CORS (Python SDK V2)

Retention policy (Python SDK V2)

Server-side encryption (Python SDK V2)

Client-side encryption (Python SDK V2)

Replication (Python SDK V2)

put_bucket_replication.py

Access monitoring (Python SDK V2)

put_bucket_access_monitor.py

Lifecycle management (Python SDK V2)

Bucket inventory (Python SDK V2)

Logging (Python SDK V2)

Archive Direct Read (Python SDK V2)

put_bucket_archive_direct_read.py

Scalar retrieval (Python SDK V2)

Vector index (Python SDK V2)

Bind a custom domain name (Python SDK V2)

Transfer acceleration (Python SDK V2)

put_bucket_transfer_acceleration.py

Synchronous processing (Python SDK V2)

process_object.py

Asynchronous processing (Python SDK V2)

async_process_object.py

Global Block Public Access for OSS (Python SDK V2)

put_public_access_block.py

Bucket-level Block Public Access (Python SDK V2)

put_bucket_public_access_block.py

Access point-level Block Public Access (Python SDK V2)

put_access_point_public_access_block.py

Resource pool QoS management (Python SDK V2)

-