This topic describes how to use the server SDK for Python.

Prerequisites

Python 2.7 or later is installed.

Procedure

  1. Log on to the server.
  2. Install the server SDK for Python.
    1. Install Alibaba Cloud SDK for Python.
      sudo pip install aliyun-python-sdk-core
    2. Install ApsaraVideo Live SDK.
      sudo pip install aliyun-python-sdk-live
  3. Update the SDKs.
    1. Update Alibaba Cloud SDK for Python.
      sudo pip install aliyun-python-sdk-core --upgrade
    2. Update ApsaraVideo Live SDK.
      sudo pip install aliyun-python-sdk-live --upgrade
  4. Use ApsaraVideo Live SDK.
    1. Read the file description. In this example, the DescribeLiveStreamsFrameRateAndBitRateDataRequest.py file in ApsaraVideo Live SDK is described.
      # Licensed to the Apache Software Foundation (ASF) under one
      # or more contributor license agreements.  See the NOTICE file
      # distributed with this work for additional information
      # regarding copyright ownership.  The ASF licenses this file
      # to you under the Apache License, Version 2.0 (the
      # "License"); you may not use this file except in compliance
      # with the License.  You may obtain a copy of the License at
      #
      #     http://www.apache.org/licenses/LICENSE-2.0
      #
      #
      #
      # Unless required by applicable law or agreed to in writing,
      # software distributed under the License is distributed on an
      # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
      # KIND, either express or implied.  See the License for the
      # specific language governing permissions and limitations
      # under the License.
      from aliyunsdkcore.request import RpcRequest
      class DescribeLiveStreamsFrameRateAndBitRateDataRequest(RpcRequest):
          def __init__(self):
              RpcRequest.__init__(self, 'live', '2016-11-01', 'DescribeLiveStreamsFrameRateAndBitRateData','live')
          def get_SecurityToken(self):
              return self.get_query_params().get('SecurityToken')
          def set_SecurityToken(self,SecurityToken):
              self.add_query_param('SecurityToken',SecurityToken)
          def get_OwnerId(self):
              return self.get_query_params().get('OwnerId')
          def set_OwnerId(self,OwnerId):
              self.add_query_param('OwnerId',OwnerId)
          def get_DomainName(self):
              return self.get_query_params().get('DomainName')
          def set_DomainName(self,DomainName):
              self.add_query_param('DomainName',DomainName)
          def get_AppName(self):
              return self.get_query_params().get('AppName')
          def set_AppName(self,AppName):
              self.add_query_param('AppName',AppName)
          def get_StreamName(self):
              return self.get_query_params().get('StreamName')
          def set_StreamName(self,StreamName):
              self.add_query_param('StreamName',StreamName)
          def get_StartTime(self):
              return self.get_query_params().get('StartTime')
          def set_StartTime(self,StartTime):
              self.add_query_param('StartTime',StartTime)
          def get_EndTime(self):
              return self.get_query_params().get('EndTime')
          def set_EndTime(self,EndTime):
              self.add_query_param('EndTime',EndTime)

      For the DescribeLiveStreamsFrameRateAndBitRateDataRequest class, the file provides several pairs of get_X and set_X methods in one-on-one correspondence, which are used to obtain and set the API request parameters.

    2. Call an operation. In this example, ApsaraVideo Live SDK v20161101 is used to call the DescribeLiveStreamsFrameRateAndBitRateDataRequest operation.
      # Import the package of Alibaba Cloud SDK for Python.
      from aliyunsdkcore import client
      # Import the package of ApsaraVideo Live SDK.
      from aliyunsdklive.request.v20161101 import DescribeLiveStreamsFrameRateAndBitRateDataRequest
      # Initialize the client.
      # Use the AccessKey ID and AccessKey secret of your Alibaba Cloud account. You can obtain them in the Alibaba Cloud Management Console.
      # Use cn-hangzhou as the region in this example.
      clt = client.AcsClient(AK, Secret, 'cn-hangzhou')
      # Create an API request.
      request = DescribeLiveStreamsFrameRateAndBitRateDataRequest.DescribeLiveStreamsFrameRateAndBitRateDataRequest()
      request.set_DomainName('qt1.alivecdn.com')
      request.set_AppName('caster')
      request.set_StreamName('cc8d5e157f5d4146afd091e246efd1f6')
      # Send the request.
      result = clt.do_action_with_exception(request)
      # Obtain the result.
      # The result is the ResponseBody string in the response.
      print result
      # If you need to further process the result, you can format the result based on the response format of the specific operation for further analysis or use.
      # The DescribeLiveStreamsFrameRateAndBitRateDataRequest operation returns data in the JSON format. You can import the JSON package to process the response.
      import json
      x = json.loads(result)
      print x['RequestId']
      print x['FrameRateAndBitRateInfos']

What to do next

To uninstall the SDKs, run the following commands:
  • sudo pip uninstall aliyun-python-sdk-core
  • sudo pip uninstall aliyun-python-sdk-live