All Products
Search
Document Center

ApsaraVideo Media Processing:Initialize the SDK client

Last Updated:Aug 28, 2023

This topic describes how to initialize the client of ApsaraVideo Media Processing (MPS) SDK for Python.

Obtain an AccessKey pair from environment variables

You can define the environment variables ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET to configure the default credentials. When you call an API operation, the system reads the AccessKey pair from the default credentials and uses the AccessKey pair to complete authentication.

Procedure

Configure the environment variables ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET.

  • Linux or macOS

Run the following commands:

export ALIBABA_CLOUD_ACCESS_KEY_ID=<access_key_id>
export ALIBABA_CLOUD_ACCESS_KEY_SECRET=<access_key_secret>

Replace <access_key_id> and <access_key_secret> with your AccessKey ID and AccessKey secret.

  • Windows

    1. Create an environment variable file, add the environment variables ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET to the file, and then enter your AccessKey ID and AccessKey secret.

    2. Restart the Windows operating system.

Initialize the SDK client

  1. Create an AcsClient instance.

    # Obtain an AccessKey ID and an AccessKey secret from environment variables.
    credentials = AccessKeyCredential(os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'], os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET'])
    # The region_id parameter specifies the ID of the region in which your MPS service is deployed. For information about supported regions, see https://www.alibabacloud.com/help/zh/apsaravideo-for-media-processing/latest/service-regions.
    client = AcsClient(region_id='cn-shanghai', credential=credentials)
  2. Create a request and set the required parameters.

    # In this example, the QueryPipelineList operation is called.
    request = QueryPipelineListRequest()
    request.set_PipelineIds("9bad31a2b3c22c4df9c6****")
    request.set_accept_format('json')
  3. Send the request and handle the response or exception.

    response = client.do_action_with_exception(request)
    # Display the response.
    print(str(response, encoding='utf-8'))

Sample code

import os
from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.acs_exception.exceptions import ClientException
from aliyunsdkcore.acs_exception.exceptions import ServerException
from aliyunsdkcore.auth.credentials import AccessKeyCredential
from aliyunsdkmts.request.v20140618.QueryPipelineListRequest import QueryPipelineListRequest

# Obtain an AccessKey ID and an AccessKey secret from environment variables.
credentials = AccessKeyCredential(os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'], os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET'])
# The region_id parameter specifies the ID of the region in which your MPS service is deployed. For information about supported regions, see https://www.alibabacloud.com/help/zh/apsaravideo-for-media-processing/latest/service-regions.
client = AcsClient(region_id = 'cn-shanghai', credential = credentials)

request = QueryPipelineListRequest()
request.set_PipelineIds("9*********61c22c4df9c6")
request.set_accept_format('json')

response = client.do_action_with_exception(request)
# Display the response.
print(str(response, encoding='utf-8'))