All Products
Search
Document Center

:Container Registry SDK for Python

Last Updated:Jul 27, 2023

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.

Installation

To install Alibaba Cloud SDK for Python, you need to follow the original SDK. For more information, see Python. Then, run the following command to install the Container Registry part:

pip install aliyun-python-sdk-cr==4.1.2

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 a request.
try:
    response = apiClient.do_action_with_exception(request)
    print(response)
except ServerException as e:
    print(e)
except ClientException as e:
    print(e)