Container Registry SDK for Python includes Alibaba Cloud SDK for Python, which is the common part, and the Container Registry part. The common part depends on aliyun-python-sdk-core. The Container Registry part depends on aliyun-python-sdk-cr. For more information about how to use each operation, see List of operations by function.

Installation

Install Alibaba Cloud SDK for Python. For more information, see Quick start. Then, run the following command to install Alibaba Cloud SDK for Python:

pip install aliyun-python-sdk-cr

API call example

#! /usr/bin/env python
# coding=utf-8

from aliyunsdkcore.acs_exception.exceptions import ClientException
from aliyunsdkcore.acs_exception.exceptions import ServerException
from aliyunsdkcore.client import AcsClient

from aliyunsdkcr.request.v20160607 import GetImageLayerRequest

# We recommend that you update aliyun-python-sdk-core to the latest version if an error occurs.

# Configure the client.
apiClient = AcsClient('AccessKeyId', 'AccessKeySecret', 'cn-hangzhou')

# Construct a request.
request = GetImageLayerRequest.GetImageLayerRequest()

# Set request parameters.
request.set_RepoNamespace("repoNamespaceName")
request.set_RepoName("repoName")
request.set_Tag("tag")

# Set the RegionId parameter to the region where the resources reside.
# Specify the endpoint in the format of cr.{regionId}.aliyuncs.com.
request.set_endpoint("cr.cn-hangzhou.aliyuncs.com")

# Initiate the request.
try:
    response = apiClient.do_action_with_exception(request)
    print(response)
except ServerException as e:
    print(e)
except ClientException as e:
    print(e)