This topic describes how to install Python SDK and provides an operation example.

Installation

To download Python SDK, click either of the following links:

Example

#!/usr/bin/env python
#coding=utf-8
from aliyunsdkcore import client
from aliyunsdkcore.profile import region_provider
from aliyunsdksts.request.v20150401 import AssumeRoleRequest
# Construct an Alibaba Cloud client to initiate a request.
# Set the access key ID and access key secret.
REGIONID = 'cn-shanghai'
ENDPOINT = 'sts.cn-shanghai.aliyuncs.com'
# Configure the STS endpoint to be accessed.
region_provider.add_endpoint('Sts', REGIONID, ENDPOINT)
# Initialize the client.
clt = client.AcsClient('<access-key-id>','<access-key-secret>', REGIONID)
# Construct the "AssumeRole" request.
request = AssumeRoleRequest.AssumeRoleRequest()
# Specify the Alibaba Cloud Resource Name (ARN) of the role.
request.set_RoleArn('<role-arn>')
# Set the session name. The session name is used to identify the user who is calling this API action.
request.set_RoleSessionName('<role-session-name>')
# Initiate a request and obtain a response.
response = clt.do_action_with_exception(request)
print response
Note