Python SDK

Preparing a Development Environment

  • JDK 1.8 or later has been installed and the environment has been configured. For details about how to install the JDK, see JDK Installation.
  • Python 3.7 or later has been installed. If not, download it from the Python official website.
  • PIP has been installed. If not, download it from the PIP official website.
  • A development environment such as JetBrains PyCharm 2018.1.4 x64 has been prepared.

Integrating SDK

  1. Decompress the downloaded mpc-python-sdk package to your local PC.
  2. Open PyCharm, select Open, select the path where the SDK is decompressed, and click OK.
  3. Configure the project interpreter.

    1. Choose File > Settings > Project: OceanConnect _ Python _SDK_Demo > Project Interpreter.

    2. Select the interpreter where the SDK is located, for example, C:\Program Files\Python37\python.exe, click Apply, and then click OK.

    3. Add the requests module to PyCharm, choose pycharm > File > Settings > Project: Python > Project Interpreter> file, and click the green plus sign (+) on the right.

    4. On the page displayed, search for requests and click install Package.

      If the installation fails, ensure that PIP of the latest version is installed.

Setting MPC Configuration Items

MPC configuration items are used to obtain authorization. You can set the configuration items when creating an MpcClient instance. Table 1 describes the parameters.

1
2
# Initialize the client object.
client = mpc_client.MPCClient("ak","sk", "endpoint","ProjectId")
Table 1 MPC parameters

Parameter

Type

Description

ak

String

Access key ID (AK). For details, see Obtaining the AK/SK Pair.

sk

String

Secret Access Key (SK) used together with the AK. For details, see Obtaining the AK/SK Pair.

endPoint

String

Endpoint. For details, see Obtaining an Endpoint.

ProjectId

String

Project ID. For details, see Obtaining a Project ID and Account Name.

API Calling

All service APIs are in main.py. You can add the target API to if __name__ == '_main__'. Table 2 shows the APIs in the Python SDK.

Mappings Between MPC SDK & APIs

Table 2 Mapping between MPC Python SDK and APIs

API

Request URI

Description

createTrancodeTemplate

POST /v1/{project_id}/template/transcodings

Creating a Transcoding Template

deleteTrancodeTemplate

DELETE /v1/{project_id}/template/transcodings

Deleting a Transcoding Template

createTrancodeTask

POST /v1/{project_id}/transcodings

Creating a Transcoding Task

deleteTrancodeTask

DELETE /v1/{project_id}/transcodings

Deleting a Transcoding Task

createThumbnailTask

POST /v1/{project_id}/thumbnails

Creating a Snapshot Task

deleteThumbnailTask

DELETE /v1/{project_id}/thumbnails

Deleting a Snapshot Task

createExtractTask

POST /v1/{project_id}/extract-metadata

Creating a Video Parsing Task

deleteExtractTask

DELETE /v1/{project_id}/extract-metadata

Deleting a Video Parsing Task