All Products
Search
Document Center

Python sample

Last Updated: Oct 30, 2018

Overview

Python SDK consists of the public and product components of Alibaba Cloud Python SDK. The public component relies on aliyun-python-sdk-core, and the product component relies on aliyun-python-sdk-cr. For more information about each interface, see API overview.

Installation

To install the public component of Python SDK, see Getting started Python SDK. Run the following command to install the product component of Python SDK.

  1. pip install aliyun-python-sdk-cr

API call example

  1. #!/usr/bin/env python
  2. # coding=utf-8
  3. from aliyunsdkcore.acs_exception.exceptions import ClientException
  4. from aliyunsdkcore.acs_exception.exceptions import ServerException
  5. from aliyunsdkcore.client import AcsClient
  6. from aliyunsdkcr.request.v20160607 import GetImageLayerRequest
  7. # Set a client
  8. apiClient = AcsClient('AccessKeyId', 'AccessKeySecret', 'cn-hangzhou')
  9. # Build a request
  10. request = GetImageLayerRequest.GetImageLayerRequest()
  11. # Set the parameters
  12. request.set_RepoNamespace("repoNamespaceName")
  13. request.set_RepoName("repoName")
  14. request.set_Tag("tag")
  15. request.set_endpoint("cr.cn-hangzhou.aliyuncs.com")
  16. # Make a request
  17. try:
  18. response = apiClient.do_action_with_exception(request)
  19. print(response)
  20. except ServerException as e:
  21. print(e)
  22. except ClientException as e:
  23. print(e)