Use the Alibaba Cloud Python SDK

Updated at:

This topic describes how to install and use the Alibaba Cloud Python SDK.

Install the Alibaba Cloud Python SDK

You can install the Alibaba Cloud Python SDK by downloading it or using the pip command:

pip3 install -i https://pypi.python.org/simple alibabacloud-et-industry-openapi20210105

Call Example

Note

Before you call an API, you must configure environment variables for your access credentials.

For example:

For the brainindustrial Open Platform, the environment variable for the AccessKey ID is AK_ENV and the environment variable for the AccessKey secret is SK_ENV.

# -*-coding:utf-8-*- 
from alibabacloud_et_industry_openapi20210105.models import OpenApiInvokeRequest
from alibabacloud_et_industry_openapi20210105.client import Client
from alibabacloud_tea_openapi import models as open_api_models
import uuid,JSON
import os

'''Example for an ECS instance'''

# Initialize Config.
# An Alibaba Cloud account AccessKey has full permissions for all APIs. For security, use a Resource Access Management (RAM) user for API calls or routine O&M. 
# To create a RAM user, log on to the RAM console.
# Do not save your AccessKey ID and AccessKey secret in your project code. This can lead to an AccessKey leak and compromise the security of all resources in your account.
# This example saves the AccessKey pair in environment variables. You can also save the AccessKey pair to a configuration file as needed.
config = open_api_models.Config(
    access_key_id=os.getenv('AK_ENV'),
    access_key_secret=os.getenv('SK_ENV'),
    region_id='cn-hangzhou'
)
client = Client(config)
# Initialize Request.
request = OpenApiInvokeRequest(service_id='your serviceId',type='EXPERIMENT')

uid = str(uuid.uuid4())
suid = ''.join(uid.split('-'))

request.job_id = suid
request.params='{"api-in-field1":{"api-in-field1-key1":"api-in-field1-key1-value"}}'
print(request)
# Call the API.
response = client.open_api_invoke(request)
print(response.body)