Python SDK
Updated at:
This topic describes how to install and use the Python SDK.
SDK installation
Install the Alibaba Cloud VS SDK for Python.
pip install alibabacloud_vs20181212==2.0.0
SDK usage
The following code sample shows the three main steps to use the Alibaba Cloud Python SDK:
Create a Config instance. When you create the instance, provide the Endpoint, AccessKey ID, and AccessKey secret.
Create an API request and set the parameters.
Initiate the request and handle the response or exceptions.
# -*- coding: utf-8 -*-
# This file is auto-generated, don't edit it. Thanks.
import os
import sys
from typing import List
from alibabacloud_vs20181212.client import Client as vs20181212Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_vs20181212 import models as vs_20181212_models
from alibabacloud_tea_util import models as util_models
from alibabacloud_tea_util.client import Client as UtilClient
class Sample:
def __init__(self):
pass
@staticmethod
def create_client() -> vs20181212Client:
"""
Initialize the client with an AK&SK.
@return: Client
@throws Exception
"""
# Leaking your project code may cause your AccessKey to be leaked and threaten the security of all resources in your account. The following code is for reference only.
# Use a more secure method, such as Security Token Service (STS). For more information about authentication methods, see https://help.aliyun.com/document_detail/378659.html.
config = open_api_models.Config(
# Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is set in your runtime environment.
access_key_id=os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'],
# Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is set in your runtime environment.
access_key_secret=os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET']
)
# For the Endpoint, see https://api.aliyun.com/product/vs
config.endpoint = f'vs.cn-beijing.aliyuncs.com'
return vs20181212Client(config)
@staticmethod
def main(
args: List[str],
) -> None:
client = Sample.create_client()
add_vs_pull_stream_info_config_request = vs_20181212_models.AddVsPullStreamInfoConfigRequest(
domain_name='your_value',
app_name='your_value'
)
try:
# If you copy the code to run it, print the API return value.
client.add_vs_pull_stream_info_config_with_options(add_vs_pull_stream_info_config_request, util_models.RuntimeOptions())
except Exception as error:
# The printing is for demonstration only. Handle exceptions with caution. Do not ignore exceptions in your project.
# Error message
print(error.message)
# Diagnosis address
print(error.data.get("Recommend"))
UtilClient.assert_as_string(error.message)
@staticmethod
async def main_async(
args: List[str],
) -> None:
client = Sample.create_client()
add_vs_pull_stream_info_config_request = vs_20181212_models.AddVsPullStreamInfoConfigRequest(
domain_name='your_value',
app_name='your_value'
)
try:
# If you copy the code to run it, print the API return value.
await client.add_vs_pull_stream_info_config_with_options_async(add_vs_pull_stream_info_config_request, util_models.RuntimeOptions())
except Exception as error:
# The printing is for demonstration only. Handle exceptions with caution. Do not ignore exceptions in your project.
# Error message
print(error.message)
# Diagnosis address
print(error.data.get("Recommend"))
UtilClient.assert_as_string(error.message)
if __name__ == '__main__':
Sample.main(sys.argv[1:])
Is this page helpful?