All Products
Search
Document Center

Image Search:SDK for Python

Last Updated:Apr 22, 2024

This topic describes how to use Image Search SDK for Python and provides sample code.

Note

To know more about Image Search, submit your questions on the presale online consultation page or contact us in the DingTalk group (ID 35035130) for technical support.

Methods

Method

Description

Add

Adds an image.

SearchImageByPic

Searches for similar images based on an image.

SearchImageByName

Searches for similar images based on the name of an existing image in the image gallery.

Delete

Removes one or more images.

UpdateImage

Updates an image.

Detail

Queries the information about an instance.

DumpMeta

Creates a task to export metadata.

DumpMetaList

Queries a list of tasks that are used to export metadata.

BatchTask

Creates a batch task.

BatchTaskList

Queries a list of tasks that are used to perform batch operations.

Preparations

  • Before you install and use an Alibaba Cloud SDK, make sure that you have created an Alibaba Cloud account and obtained the AccessKey pair of the Alibaba Cloud account. For more information, see Obtain an AccessKey pair.

  • Run the following command to install the dependency:

pip install alibabacloud_imagesearch20201214

Add

  • Sample code

    from alibabacloud_imagesearch20201214.client import Client
    from alibabacloud_imagesearch20201214.models import AddImageAdvanceRequest
    from alibabacloud_tea_openapi.models import Config
    from alibabacloud_tea_util.models import RuntimeOptions
    def addImage():
        request = AddImageAdvanceRequest()
        # Required. The name of the Image Search instance. Enter the instance name instead of the Instance ID. After an Image Search instance is purchased, obtain the instance name at https://imagesearch.console.aliyun.com/overview.
        request.instance_name = '<instanceName>'
        # Required. The ID of the product. The value cannot exceed 512 characters in length. 
        # A product ID can relate to multiple image names. 
        request.product_id = '<productId>'
        # Required. The name of the image. The value cannot exceed 512 characters in length. 
        # 1. Required. An image is uniquely identified by the values of the ProductId and PicName parameters. 
        # 2. If you add an image whose product ID (ProductId) and image name (PicName) are the same as those of an existing image, the newly added image overwrites the existing image. 
        request.pic_name = '<picName>'
        # The image. The image cannot exceed 4 MB in size. The transmission timeout period is 5 seconds. Only the following image formats are supported: PNG, JPG, JPEG, BMP, GIF, WebP, TIFF, and PPM.
        # For product, brand, and generic images, the length and the width of an image must range from 100 pixels to 4,096 pixels.
        # For cloth images, the length and the width of an image must range from 448 pixels to 4,096 pixels.
        # The image cannot contain rotation information.
    
        # The following sample code provides an example on how to specify an image URL:    
        # url = '<fileUrl>'    
        # f = BytesIO(requests.get(url).content)  
    
        # The following sample code provides an example on how to upload an image file:
        f = open('<filePath>', 'rb')
    
        request.pic_content_object = f
        # Optional. The ID of the product category. 
        # 1. Product search: If a category is specified, the specified category prevails. If no category is specified, the system predicts and selects a category. The category selected by the system is included in the response. 
        # 2. Cloth, brand, and generic image searches: The category ID is set to 88888888 regardless of whether a category ID is specified. 
        request.category_id = 3
        # Optional. The user-defined content. The value can be up to 4,096 characters in length. 
        # If you specify this parameter, the response includes this parameter and its value. You can add text such as an image description. 
        request.custom_content = "this is a simple test"
        # Optional. The attribute of the INT type. The attribute can be used to filter images in image searches. If you specify this parameter, the response includes this parameter and its value. 
        # For example, you can set different attributes for images from different sites or different users. This way, users can filter images by attribute and obtain more accurate search results.
        request.int_attr = 56
        # Optional. The attribute of the STRING type. The value cannot exceed 128 characters in length. The attribute can be used to filter images in image searches. If you specify this parameter, the response includes this parameter and its value. 
        request.str_attr = "test"
        # Optional. Specifies whether to recognize the main subject in the image. Default value: True. 
        # 1. If you set this parameter to true, the system recognizes the subject in the image, and searches for images based on the recognized subject. The response includes the recognition result. 
        # 2. If you set this parameter to false, the system searches for images based on the entire image without subject recognition. 
        # 3. For cloth image searches, this parameter does not take effect. The system searches for images based on the entire image. 
        request.crop = True
        # Optional. The main area of the image. The value is in the format of x1,x2,y1,y2. x1 and y1 indicate the position of the upper-left point of the area, in pixels. x2 and y2 indicate the position of the lower-right point of the area, in pixels. The specified area cannot cross the boundary of the image. 
        # If you specify the Region parameter, the system searches for images based on the value of Region regardless of the value of the Crop parameter. 
        # For cloth image searches, this parameter does not take effect. The system searches for images based on the entire image. 
        request.region = "167,467,221,407"
        config = Config()
        # For information about how to create an AccessKey pair, visit https://www.alibabacloud.com/help/en/resource-access-management/latest/accesskey-pairs-create-an-accesskey-pair-for-a-ram-user.
        # The AccessKey pair of an Alibaba Cloud account has the permissions to call all API operations. We recommend that you use the AccessKey pair of a Resource Access Management (RAM) user to call API operations or perform routine O&M. 
        # We recommend that you do not hard code your AccessKey ID and AccessKey secret in your project code. Otherwise, the AccessKey pair may be leaked and the security of all resources within your account is compromised. 
        # In this example, the AccessKey ID and AccessKey secret are saved as environment variables. You can also save the AccessKey ID and AccessKey secret to a configuration file based on your business requirements. 
        config.access_key_id = os.environ['CC_AK_ENV']
        config.access_key_secret = os.environ['CC_SK_ENV']
        # Replace the value with the endpoint in the region in which your Image Search instance resides. For example, if your Image Search instance resides in the China (Hangzhou) region, set the endpoint parameter to imagesearch.cn-hangzhou.aliyuncs.com.
        config.endpoint = 'imagesearch.[regionId].aliyuncs.com'
    
        # The following sample code provides an example on how to use a virtual private cloud (VPC) endpoint to call the Image Search API.
        # Note: You can use a VPC endpoint to call the Image Search API only from Elastic Compute Service (ECS) instances or resources that reside in the same region. For example, if your Image Search instance resides in the China (Shanghai) region, you can use a VPC endpoint to call the Image Search API only from the ECS instances or resources that reside in the China (Shanghai) region. Otherwise, the API operation fails to be called. In case of a failed API call, check whether your ECS instances or resources are in the same region as your Image Search instance before you call the Image Search API. 
        # config.endpointType = 'internal'  // If you want to use a VPC endpoint to call the Image Search API, you must specify the endpointType parameter and set the value to internal.
        # config.endpoint = 'imagesearch-vpc.[regionId].aliyuncs.com' // The VPC endpoint that is used to call the Image Search API. Replace the value with the VPC endpoint in the region in which your Image Search instance resides. For example, if your Image Search instance resides in the China (Hangzhou) region, set the endpoint parameter to imagesearch-vpc.cn-hangzhou.aliyuncs.com.
    
        # Replace the value with the region in which your Image Search instance resides. For example, if your Image Search instance resides in the China (Hangzhou) region, set the regionId parameter to cn-hangzhou.   
        config.region_id = '<regionId>'
        config.type = 'access_key'
        client = Client(config)
        runtime_option = RuntimeOptions()
        response = client.add_image_advance(request, runtime_option)
        print(response.to_map())
        f.close()
    if __name__ == '__main__':
        addImage()
  • Sample response

    {
      'RequestId': '7F769FFC-4F45-476E-BE6C-E4EF82E012A7',
      'Success': True,
      'Message': 'success',
      'Code': 0,
      'PicInfo': {
        'CategoryId': 20,
        'Region': '474,747,497,784'
      }
    }

SearchImageByPic

  • Sample code

    from alibabacloud_imagesearch20201214.client import Client
    from alibabacloud_imagesearch20201214.models import SearchImageByPicAdvanceRequest
    from alibabacloud_tea_openapi.models import Config
    from alibabacloud_tea_util.models import RuntimeOptions
    def searchImageByPic() :
        request = SearchImageByPicAdvanceRequest()
        # Required. The name of the Image Search instance. Enter the instance name instead of the Instance ID. After an Image Search instance is purchased, obtain the instance name at https://imagesearch.console.aliyun.com/overview.
        request.instance_name = '<instanceName>'
        # The image. The image cannot exceed 4 MB in size. The transmission timeout period is 5 seconds. Only the following image formats are supported: PNG, JPG, JPEG, BMP, GIF, WebP, TIFF, and PPM.
        # For product, brand, and generic images, the length and the width of an image must range from 100 pixels to 4,096 pixels.
        # For cloth images, the length and the width of an image must range from 448 pixels to 4,096 pixels.
        # The image cannot contain rotation properties.
    
        # The following sample code provides an example on how to specify an image URL:    
        # url = '<fileUrl>'    
        # f = BytesIO(requests.get(url).content)  
    
        # The following sample code provides an example on how to upload an image file:
        f = open('<filePath>', 'rb')
    
        request.pic_content_object = f
        # Optional. The ID of the product category. 
        # 1. Product search: If a category is specified, the specified category prevails. If no category is specified, the system predicts and selects a category. The category selected by the system is included in the response. 
        # 2. Cloth, brand, and generic image searches: The category ID is set to 88888888 regardless of whether a category ID is specified. 
        request.category_id = 3
        # Optional. The number of entries to be returned. Valid values: 1 to 100. Default value: 10. 
        request.num = 10
        # Optional. The ordinal number of the first entry to be returned. Valid values: 0 to 499. Default value: 0. 
        request.start = 0
        # Optional. Specifies whether to recognize the main subject in the image. Default value: True. 
        # 1. If you set this parameter to true, the system recognizes the subject in the image, and searches for images based on the recognized subject. The response includes the recognition result. 
        # 2. If you set this parameter to false, the system searches for images based on the entire image without subject recognition. 
        # 3. For cloth image searches, this parameter does not take effect. The system searches for images based on the entire image. 
        request.crop = True
        # Optional. The main area of the image. The value is in the format of x1,x2,y1,y2. x1 and y1 indicate the position of the upper-left point of the area, in pixels. x2 and y2 indicate the position of the lower-right point of the area, in pixels. The specified area cannot cross the boundary of the image. 
        # If you specify the Region parameter, the system searches for images based on the value of Region regardless of the value of the Crop parameter. 
        # 3. For cloth image searches, this parameter does not take effect. The system searches for images based on the entire image. 
        request.region="167,467,221,407"
        # Optional. The filter condition.
        # int_attr supports the following operators: >, >=, <, <=, and =. str_attr supports the = and != operators. You can set the logical operator between conditions to AND or OR. 
        # Examples:
        # 1. Filter results based on int_attr>=100.
        # 2. Filter results based on str_attr!="value1".
        # 3. Filter results based on int_attr and str_attr: int_attr=1000 AND str_attr="value1".
        request.filter="int_attr=56 AND str_attr=\"test\""
        config = Config()
        # For information about how to create an AccessKey pair, visit https://www.alibabacloud.com/help/en/resource-access-management/latest/accesskey-pairs-create-an-accesskey-pair-for-a-ram-user.
        # The AccessKey pair of an Alibaba Cloud account has the permissions to call all API operations. We recommend that you use the AccessKey pair of a RAM user to call API operations or perform routine O&M. 
        # We recommend that you do not hard code your AccessKey ID and AccessKey secret in your project code. Otherwise, the AccessKey pair may be leaked and the security of all resources within your account is compromised. 
        # In this example, the AccessKey ID and AccessKey secret are saved as environment variables. You can also save the AccessKey ID and AccessKey secret to a configuration file based on your business requirements. 
        config.access_key_id = os.environ['CC_AK_ENV']
        config.access_key_secret = os.environ['CC_SK_ENV']
        # Replace the value with the endpoint in the region in which your Image Search instance resides. For example, if your Image Search instance resides in the China (Hangzhou) region, set the endpoint parameter to imagesearch.cn-hangzhou.aliyuncs.com.
        config.endpoint = 'imagesearch.<regionId>.aliyuncs.com'
    
        # The following sample code provides an example on how to use a VPC endpoint to call the Image Search API.
        # Note: You can use a VPC endpoint to call the Image Search API only from ECS instances or resources that reside in the same region. For example, if your Image Search instance resides in the China (Shanghai) region, you can use a VPC endpoint to call the Image Search API only from the ECS instances or resources that reside in the China (Shanghai) region. Otherwise, the API operation fails to be called. In case of a failed API call, check whether your ECS instances or resources are in the same region as your Image Search instance before you call the Image Search API. 
        # config.endpointType = 'internal'  // If you want to use a VPC endpoint to call the Image Search API, you must specify the endpointType parameter and set the value to internal.
        # config.endpoint = 'imagesearch-vpc.<regionId>.aliyuncs.com' // The VPC endpoint that is used to call the Image Search API. Replace the value with the VPC endpoint in the region in which your Image Search instance resides. For example, if your Image Search instance resides in the China (Hangzhou) region, set the endpoint parameter to imagesearch-vpc.cn-hangzhou.aliyuncs.com.
    
        # Replace the value with the region in which your Image Search instance resides. For example, if your Image Search instance resides in the China (Hangzhou) region, set the regionId parameter to cn-hangzhou.
        config.region_id = '<regionId>'
        config.type = 'access_key'
        client = Client(config)
        runtime_option = RuntimeOptions()
        response = client.search_image_by_pic_advance(request, runtime_option)
        print(response.to_map())
        f.close()
    if __name__ == '__main__':
        searchImageByPic()
  • Sample response

    {
      'RequestId': '53C481F3-E064-428D-AB25-B6C57A704E68',
      'Success': True,
      'Code': 0,
      'Msg': 'success',
      'Auctions': [{
        'CategoryId': 20,
        'ProductId': 'test-version-001',
        'PicName': 'test-version-001.jpg',
        'CustomContent': None,
        'Score': 1.0
        'SortExprValues': '5.37633353624177e+24;0',
        'IntAttr': None,
        'StrAttr': None
      }, {
        'CategoryId': 20,
        'ProductId': 'test_0426_1',
        'PicName': 'test_0426_1.png',
        'CustomContent': None,
        'Score': 1.0,
        'SortExprValues': '2.71303606033325;263',
        'IntAttr': None,
        'StrAttr': None
      }],
      'Head': {
        'DocsReturn': 5,
        'DocsFound': 5,
        'SearchTime': 295
      },
      'PicInfo': {
        'CategoryId': 20,
        'Region': '474,747,497,784',
        'AllCategories': [{
          'Id': 0,
          'Name': 'Tops'
        }, {
          'Id': 1,
          'Name': 'Dress'
        }, {
          'Id': 2,
          'Name': 'Bottoms'
        }, {
          'Id': 3,
          'Name': 'Bag'
        }, {
          'Id': 4,
          'Name': 'Shoes'
        }, {
          'Id': 5,
          'Name': 'Accessories'
        }, {
          'Id': 6,
          'Name': 'Snack'
        }, {
          'Id': 7,
          'Name': 'Makeup'
        }, {
          'Id': 8,
          'Name': 'Bottle'
        }, {
          'Id': 9,
          'Name': 'Furniture'
        }, {
          'Id': 20,
          'Name': 'Toy'
        }, {
          'Id': 21,
          'Name': 'Underwear'
        }, {
          'Id': 22,
          'Name': 'Digital device'
        }, {
          'Id': 88888888,
          'Name': 'Other'
        }],
        'MultiRegion': [{
            'Region': '112,440,76,387'
         }]
      }
    }

SearchImageByName

  • Sample code

    from alibabacloud_imagesearch20201214.client import Client
    from alibabacloud_imagesearch20201214.models import SearchImageByNameRequest
    from alibabacloud_tea_openapi.models import Config
    from alibabacloud_tea_util.models import RuntimeOptions
    def searchImageByName() :
        request = SearchImageByNameRequest()
        # Required. The name of the Image Search instance. Enter the instance name instead of the Instance ID. After an Image Search instance is purchased, obtain the instance name at https://imagesearch.console.aliyun.com/overview.
        request.instance_name = '<instanceName>'
        # Required. The ID of the product. The value cannot exceed 512 characters in length. 
        # A product ID can relate to multiple image names. 
        request.product_id = '<productId>'
        # Required. The name of the image. The value cannot exceed 512 characters in length. 
        # 1. Required. An image is uniquely identified by the values of the ProductId and PicName parameters. 
        # 2. If you add an image whose product ID (ProductId) and image name (PicName) are the same as those of an existing image, the newly added image overwrites the existing image. 
        request.pic_name = '<picName>'
        # Optional. The ID of the product category. 
        # 1. Product search: If a category is specified, the specified category prevails. If no category is specified, the system predicts and selects a category. The category selected by the system is included in the response. 
        # 2. Cloth, brand, and generic image searches: The category ID is set to 88888888 regardless of whether a category ID is specified. 
        request.category_id = 3
        # Optional. The number of entries to be returned. Valid values: 1 to 100. Default value: 10. 
        request.num = 10
        # Optional. The ordinal number of the first entry to be returned. Valid values: 0 to 499. Default value: 0. 
        request.start = 0
        # Optional. Specifies whether to recognize the main subject in the image. Default value: True. 
        # 1. If you set this parameter to true, the system recognizes the subject in the image, and searches for images based on the recognized subject. The response includes the recognition result. 
        # 2. If you set this parameter to false, the system searches for images based on the entire image without subject recognition. 
        # 3. For cloth image searches, this parameter does not take effect. The system searches for images based on the entire image. 
        request.crop = True
        # Optional. The main area of the image. The value is in the format of x1,x2,y1,y2. x1 and y1 indicate the position of the upper-left point of the area, in pixels. x2 and y2 indicate the position of the lower-right point of the area, in pixels. The specified area cannot cross the boundary of the image. 
        # If you specify the Region parameter, the system searches for images based on the value of Region regardless of the value of the Crop parameter. 
        # 3. For cloth image searches, this parameter does not take effect. The system searches for images based on the entire image. 
        request.region="167,467,221,407"
        # Optional. The filter condition.
        # int_attr supports the following operators: >, >=, <, <=, and =. str_attr supports the = and != operators. You can set the logical operator between conditions to AND or OR. 
        # Examples:
        # 1. Filter results based on int_attr>=100.
        # 2. Filter results based on str_attr!="value1".
        # 3. Filter results based on int_attr and str_attr: int_attr=1000 AND str_attr="value1".
        request.filter="int_attr=56 AND str_attr=\"test\""
        config = Config()
        # For information about how to create an AccessKey pair, visit https://www.alibabacloud.com/help/en/resource-access-management/latest/accesskey-pairs-create-an-accesskey-pair-for-a-ram-user.
        # The AccessKey pair of an Alibaba Cloud account has the permissions to call all API operations. We recommend that you use the AccessKey pair of a RAM user to call API operations or perform routine O&M. 
        # We recommend that you do not hard code your AccessKey ID and AccessKey secret in your project code. Otherwise, the AccessKey pair may be leaked and the security of all resources within your account is compromised. 
        # In this example, the AccessKey ID and AccessKey secret are saved as environment variables. You can also save the AccessKey ID and AccessKey secret to a configuration file based on your business requirements. 
        config.access_key_id = os.environ['CC_AK_ENV']
        config.access_key_secret = os.environ['CC_SK_ENV']
        # Replace the value with the endpoint in the region in which your Image Search instance resides. For example, if your Image Search instance resides in the China (Hangzhou) region, set the endpoint parameter to imagesearch.cn-hangzhou.aliyuncs.com.
        config.endpoint = 'imagesearch.<regionId>.aliyuncs.com'
    
        # The following sample code provides an example on how to use a VPC endpoint to call the Image Search API.
        # Note: You can use a VPC endpoint to call the Image Search API only from ECS instances or resources that reside in the same region. For example, if your Image Search instance resides in the China (Shanghai) region, you can use a VPC endpoint to call the Image Search API only from the ECS instances or resources that reside in the China (Shanghai) region. Otherwise, the API operation fails to be called. In case of a failed API call, check whether your ECS instances or resources are in the same region as your Image Search instance before you call the Image Search API. 
        # config.endpointType = 'internal'  // If you want to use a VPC endpoint to call the Image Search API, you must specify the endpointType parameter and set the value to internal.
        # config.endpoint = 'imagesearch-vpc.<regionId>.aliyuncs.com' // The VPC endpoint that is used to call the Image Search API. Replace the value with the VPC endpoint in the region in which your Image Search instance resides. For example, if your Image Search instance resides in the China (Hangzhou) region, set the endpoint parameter to imagesearch-vpc.cn-hangzhou.aliyuncs.com.
    
        # Replace the value with the region in which your Image Search instance resides. For example, if your Image Search instance resides in the China (Hangzhou) region, set the regionId parameter to cn-hangzhou.
        config.region_id = '<regionId>'
        config.type = 'access_key'
        client = Client(config)
        response = client.search_image_by_name(request)
        print(response.to_map())
    if __name__ == '__main__':
        searchImageByName()
  • Sample response

    {
      'RequestId': '7BC00158-3B9B-49C4-9E25-FFEC28AF3CE8',
      'Success': True,
      'Code': 0,
      'Msg': 'success',
      'Auctions': [{
        'CategoryId': 20,
        'ProductId': 'test-version-001',
        'PicName': 'test-version-001.jpg',
        'CustomContent': None,
        'score':1.0,
        'SortExprValues': '5.37633353624177e+24;0',
        'IntAttr': None,
        'StrAttr': None
      }, {
        'CategoryId': 20,
        'ProductId': 'test_0426_1',
        'PicName': 'test_0426_1.png',
        'CustomContent': None,
        'score':1.0,
        'SortExprValues': '2.71303606033325;263',
        'IntAttr': None,
        'StrAttr': None
      }],
      'Head': {
        'DocsReturn': 5,
        'DocsFound': 5,
        'SearchTime': 15
      },
      'PicInfo': {
        'CategoryId': 20,
        'Region': None,
        'AllCategories': [{
          'Id': 0,
          'Name': 'Tops'
        }, {
          'Id': 1,
          'Name': 'Dress'
        }, {
          'Id': 2,
          'Name': 'Bottoms'
        }, {
          'Id': 3,
          'Name': 'Bag'
        }, {
          'Id': 4,
          'Name': 'Shoes'
        }, {
          'Id': 5,
          'Name': 'Accessories'
        }, {
          'Id': 6,
          'Name': 'Snack'
        }, {
          'Id': 7,
          'Name': 'Makeup'
        }, {
          'Id': 8,
          'Name': 'Bottle'
        }, {
          'Id': 9,
          'Name': 'Furniture'
        }, {
          'Id': 20,
          'Name': 'Toy'
        }, {
          'Id': 21,
          'Name': 'Underwear'
        }, {
          'Id': 22,
          'Name': 'Digital device'
        }, {
          'Id': 88888888,
          'Name': 'Other'
        }],
        'MultiRegion': [{
            'Region': '112,440,76,387'
         }]
      }
    }

Delete

  • Sample code

    from alibabacloud_imagesearch20201214.client import Client
    from alibabacloud_imagesearch20201214.models import DeleteImageRequest
    from alibabacloud_tea_openapi.models import Config
    from alibabacloud_tea_util.models import RuntimeOptions
    
    def deleteImage() :
        request = DeleteImageRequest()
        # Required. The name of the Image Search instance. Enter the instance name instead of the Instance ID. After an Image Search instance is purchased, obtain the instance name at https://imagesearch.console.aliyun.com/overview.
        request.instance_name = '<instanceName>'
        # Required. The ID of the product. The value cannot exceed 512 characters in length. 
        # A product ID can relate to multiple image names. 
        request.product_id = '<productId>'
        # Required. The name of the image. The value cannot exceed 512 characters in length. 
        # 1. Required. An image is uniquely identified by the values of the ProductId and PicName parameters. 
        # 2. If you add an image whose product ID (ProductId) and image name (PicName) are the same as those of an existing image, the newly added image overwrites the existing image. 
        request.pic_name = '<picName>'
        config = Config()
        # The AccessKey pair of an Alibaba Cloud account has the permissions to call all API operations. We recommend that you use the AccessKey pair of a RAM user to call API operations or perform routine O&M. 
        # We recommend that you do not hard code your AccessKey ID and AccessKey secret in your project code. Otherwise, the AccessKey pair may be leaked and the security of all resources within your account is compromised. 
        # In this example, the AccessKey ID and AccessKey secret are saved as environment variables. You can also save the AccessKey ID and AccessKey secret to a configuration file based on your business requirements. 
        config.access_key_id = os.environ['CC_AK_ENV']
        config.access_key_secret = os.environ['CC_SK_ENV']
        # Replace the value with the endpoint in the region in which your Image Search instance resides. For example, if your Image Search instance resides in the China (Hangzhou) region, set the endpoint parameter to imagesearch.cn-hangzhou.aliyuncs.com.
        config.endpoint = 'imagesearch.<regionId>.aliyuncs.com'
    
        # The following sample code provides an example on how to use a VPC endpoint to call the Image Search API.
        # Note: You can use a VPC endpoint to call the Image Search API only from ECS instances or resources that reside in the same region. For example, if your Image Search instance resides in the China (Shanghai) region, you can use a VPC endpoint to call the Image Search API only from the ECS instances or resources that reside in the China (Shanghai) region. Otherwise, the API operation fails to be called. In case of a failed API call, check whether your ECS instances or resources are in the same region as your Image Search instance before you call the Image Search API. 
        # config.endpointType = 'internal'  // If you want to use a VPC endpoint to call the Image Search API, you must specify the endpointType parameter and set the value to internal.
        # config.endpoint = 'imagesearch-vpc.<regionId>.aliyuncs.com' // The VPC endpoint that is used to call the Image Search API. Replace the value with the VPC endpoint in the region in which your Image Search instance resides. For example, if your Image Search instance resides in the China (Hangzhou) region, set the endpoint parameter to imagesearch-vpc.cn-hangzhou.aliyuncs.com.
    
        # Replace the value with the region in which your Image Search instance resides. For example, if your Image Search instance resides in the China (Hangzhou) region, set the regionId parameter to cn-hangzhou.
        config.region_id = '<regionId>'
        # For information about how to create an AccessKey pair, visit https://www.alibabacloud.com/help/en/resource-access-management/latest/accesskey-pairs-create-an-accesskey-pair-for-a-ram-user.
        config.type = 'access_key'
        client = Client(config)
        response = client.delete_image(request)
        print(response.to_map())
    if __name__ == '__main__':
        deleteImage()
  • Sample response

    {
      'RequestId': '9ADA959B-B639-4B3B-841D-2399F1C34DA8',
      'Success': True,
      'Message': 'success',
      'Code': 0
    }

UpdateImage

  • Sample code

    from alibabacloud_imagesearch20201214.client import Client
    from alibabacloud_imagesearch20201214.models import UpdateImageRequest
    from alibabacloud_tea_openapi.models import Config
    from alibabacloud_tea_util.models import RuntimeOptions
    
    def updateImage() :
        config = Config()
        # For information about how to create an AccessKey pair, visit https://www.alibabacloud.com/help/en/resource-access-management/latest/accesskey-pairs-create-an-accesskey-pair-for-a-ram-user.
        # The AccessKey pair of an Alibaba Cloud account has the permissions to call all API operations. We recommend that you use the AccessKey pair of a RAM user to call API operations or perform routine O&M. 
        # We recommend that you do not hard code your AccessKey ID and AccessKey secret in your project code. Otherwise, the AccessKey pair may be leaked and the security of all resources within your account is compromised. 
        # In this example, the AccessKey ID and AccessKey secret are saved as environment variables. You can also save the AccessKey ID and AccessKey secret to a configuration file based on your business requirements. 
        config.access_key_id = os.environ['CC_AK_ENV']
        config.access_key_secret = os.environ['CC_SK_ENV']
        # Replace the value with the endpoint in the region in which your Image Search instance resides. For example, if your Image Search instance resides in the China (Hangzhou) region, set the endpoint parameter to imagesearch.cn-hangzhou.aliyuncs.com.
        config.endpoint = 'imagesearch.<regionId>.aliyuncs.com'
    
        # The following sample code provides an example on how to use a VPC endpoint to call the Image Search API.
        # Note: You can use a VPC endpoint to call the Image Search API only from ECS instances or resources that reside in the same region. For example, if your Image Search instance resides in the China (Shanghai) region, you can use a VPC endpoint to call the Image Search API only from the ECS instances or resources that reside in the China (Shanghai) region. Otherwise, the API operation fails to be called. In case of a failed API call, check whether your ECS instances or resources are in the same region as your Image Search instance before you call the Image Search API. 
        # config.endpointType = 'internal'  // If you want to use a VPC endpoint to call the Image Search API, you must specify the endpointType parameter and set the value to internal.
        # config.endpoint = 'imagesearch-vpc.<regionId>.aliyuncs.com' // The VPC endpoint that is used to call the Image Search API. Replace the value with the VPC endpoint in the region in which your Image Search instance resides. For example, if your Image Search instance resides in the China (Hangzhou) region, set the endpoint parameter to imagesearch-vpc.cn-hangzhou.aliyuncs.com.
    
        # Replace the value with the region in which your Image Search instance resides. For example, if your Image Search instance resides in the China (Hangzhou) region, set the regionId parameter to cn-hangzhou.
        config.region_id = '<regionId>'
        config.type = 'access_key'
        client = Client(config)
    
        request = UpdateImageRequest()
        # Required. The name of the Image Search instance. Enter the instance name instead of the Instance ID. After an Image Search instance is purchased, obtain the instance name at https://imagesearch.console.aliyun.com/overview.
        request.instance_name = "xxxxxx"
        # Required. The ID of the product. The product ID cannot be changed. 
        request.product_id = "1"
        # Required. The name of the image. The image name cannot be changed. 
        request.pic_name = "1"
        # Optional. The attribute of the INT type. The attribute can be used to filter images in image searches. If you specify this parameter, the response includes this parameter and its value. 
        request.int_attr = "1"
        # Optional. The attribute of the STRING type. The value cannot exceed 128 characters in length. The attribute can be used to filter images in image searches. If you specify this parameter, the response includes this parameter and its value. 
        request.str_attr = "test"
        # Optional. The user-defined content. The value can be up to 4,096 characters in length. 
        request.CustomContent ="This is a sample description";
        response = client.update_image(request)
        print(response.body.to_map())
    
    if __name__ == '__main__':
        updateImage()
  • Sample response

    {'Code': 0, 'RequestId': '864F581A-F2F8-1AF8-B1EA-1EFBF177E9F9', 'Success': True}

Detail

  • Sample code

    from alibabacloud_imagesearch20201214.client import Client
    from alibabacloud_imagesearch20201214.models import DetailRequest
    from alibabacloud_tea_openapi.models import Config
    from alibabacloud_tea_util.models import RuntimeOptions
    
    def detail() :
        config = Config()
        # For information about how to create an AccessKey pair, visit https://www.alibabacloud.com/help/en/resource-access-management/latest/accesskey-pairs-create-an-accesskey-pair-for-a-ram-user.
        # The AccessKey pair of an Alibaba Cloud account has the permissions to call all API operations. We recommend that you use the AccessKey pair of a RAM user to call API operations or perform routine O&M. 
        # We recommend that you do not hard code your AccessKey ID and AccessKey secret in your project code. Otherwise, the AccessKey pair may be leaked and the security of all resources within your account is compromised. 
        # In this example, the AccessKey ID and AccessKey secret are saved as environment variables. You can also save the AccessKey ID and AccessKey secret to a configuration file based on your business requirements. 
        config.access_key_id = os.environ['CC_AK_ENV']
        config.access_key_secret = os.environ['CC_SK_ENV']
        # Replace the value with the endpoint in the region in which your Image Search instance resides. For example, if your Image Search instance resides in the China (Hangzhou) region, set the endpoint parameter to imagesearch.cn-hangzhou.aliyuncs.com.
        config.endpoint = 'imagesearch.<regionId>.aliyuncs.com'
    
        # The following sample code provides an example on how to use a VPC endpoint to call the Image Search API.
        # Note: You can use a VPC endpoint to call the Image Search API only from ECS instances or resources that reside in the same region. For example, if your Image Search instance resides in the China (Shanghai) region, you can use a VPC endpoint to call the Image Search API only from the ECS instances or resources that reside in the China (Shanghai) region. Otherwise, the API operation fails to be called. In case of a failed API call, check whether your ECS instances or resources are in the same region as your Image Search instance before you call the Image Search API. 
        # config.endpointType = 'internal'  // If you want to use a VPC endpoint to call the Image Search API, you must specify the endpointType parameter and set the value to internal.
        # config.endpoint = 'imagesearch-vpc.<regionId>.aliyuncs.com' // The VPC endpoint that is used to call the Image Search API. Replace the value with the VPC endpoint in the region in which your Image Search instance resides. For example, if your Image Search instance resides in the China (Hangzhou) region, set the endpoint parameter to imagesearch-vpc.cn-hangzhou.aliyuncs.com.
    
        # Replace the value with the region in which your Image Search instance resides. For example, if your Image Search instance resides in the China (Hangzhou) region, set the regionId parameter to cn-hangzhou.
        config.region_id = '<regionId>'
        config.type = 'access_key'
        client = Client(config)
    
        request = DetailRequest()
        # Required. The name of the Image Search instance. Enter the instance name instead of the Instance ID. After an Image Search instance is purchased, obtain the instance name at https://imagesearch.console.aliyun.com/overview.
        request.instance_name = "xxxxxx"
        response = client.detail(request)
        print(response.body.to_map())
    
    if __name__ == '__main__':
        detail()
  • Sample response

    {
      'Instance': {
        'Capacity': 10,
        'Name': 'xxxxx',
        'Qps': 1,
        'Region': 'cn-shanghai',
        'ServiceType': 0,
        'TotalCount': 99999,
        'UtcCreate': 1620382716000,
        'UtcExpireTime': 1623081600000
      },
      'RequestId': '1BEEACA0-A4C9-1B83-93A6-3005BB769B4E',
      'Success': True
    }

DumpMeta

  • Sample code

    from alibabacloud_imagesearch20201214.client import Client
    from alibabacloud_imagesearch20201214.models import DumpMetaRequest
    from alibabacloud_tea_openapi.models import Config
    from alibabacloud_tea_util.models import RuntimeOptions
    
    def dumpMeta() :
        config = Config()
        # For information about how to create an AccessKey pair, visit https://www.alibabacloud.com/help/en/resource-access-management/latest/accesskey-pairs-create-an-accesskey-pair-for-a-ram-user.
        # The AccessKey pair of an Alibaba Cloud account has the permissions to call all API operations. We recommend that you use the AccessKey pair of a RAM user to call API operations or perform routine O&M. 
        # We recommend that you do not hard code your AccessKey ID and AccessKey secret in your project code. Otherwise, the AccessKey pair may be leaked and the security of all resources within your account is compromised. 
        # In this example, the AccessKey ID and AccessKey secret are saved as environment variables. You can also save the AccessKey ID and AccessKey secret to a configuration file based on your business requirements. 
        config.access_key_id = os.environ['CC_AK_ENV']
        config.access_key_secret = os.environ['CC_SK_ENV']
        # Replace the value with the endpoint in the region in which your Image Search instance resides. For example, if your Image Search instance resides in the China (Hangzhou) region, set the endpoint parameter to imagesearch.cn-hangzhou.aliyuncs.com.
        config.endpoint = 'imagesearch.<regionId>.aliyuncs.com'
    
        # The following sample code provides an example on how to use a VPC endpoint to call the Image Search API.
        # Note: You can use a VPC endpoint to call the Image Search API only from ECS instances or resources that reside in the same region. For example, if your Image Search instance resides in the China (Shanghai) region, you can use a VPC endpoint to call the Image Search API only from the ECS instances or resources that reside in the China (Shanghai) region. Otherwise, the API operation fails to be called. In case of a failed API call, check whether your ECS instances or resources are in the same region as your Image Search instance before you call the Image Search API. 
        # config.endpointType = 'internal'  // If you want to use a VPC endpoint to call the Image Search API, you must specify the endpointType parameter and set the value to internal.
        # config.endpoint = 'imagesearch-vpc.<regionId>.aliyuncs.com' // The VPC endpoint that is used to call the Image Search API. Replace the value with the VPC endpoint in the region in which your Image Search instance resides. For example, if your Image Search instance resides in the China (Hangzhou) region, set the endpoint parameter to imagesearch-vpc.cn-hangzhou.aliyuncs.com.
    
        # Replace the value with the region in which your Image Search instance resides. For example, if your Image Search instance resides in the China (Hangzhou) region, set the regionId parameter to cn-hangzhou.
        config.region_id = '<regionId>'
        config.type = 'access_key'
        client = Client(config)
    
        request = DumpMetaRequest()
        # Required. The name of the Image Search instance. Enter the instance name instead of the Instance ID. After an Image Search instance is purchased, obtain the instance name at https://imagesearch.console.aliyun.com/overview.
        request.instance_name = "xxxxxx"
        response = client.dump_meta(request)
        print(response.body.to_map())
    
    if __name__ == '__main__':
        dumpMeta()
  • Sample response

    {
      'Data': {
        'DumpMetaStatus': 'PROCESSING',
        'Id': 570
      },
      'RequestId': '5F70A624-D90D-1CDE-9549-542D97B68329',
      'Success': True
    }

DumpMetaList

  • Sample code

    from alibabacloud_imagesearch20201214.client import Client
    from alibabacloud_imagesearch20201214.models import DumpMetaListRequest
    from alibabacloud_tea_openapi.models import Config
    from alibabacloud_tea_util.models import RuntimeOptions
    
    def dumpMetaList() :
        config = Config()
        # For information about how to create an AccessKey pair, visit https://www.alibabacloud.com/help/en/resource-access-management/latest/accesskey-pairs-create-an-accesskey-pair-for-a-ram-user.
        # The AccessKey pair of an Alibaba Cloud account has the permissions to call all API operations. We recommend that you use the AccessKey pair of a RAM user to call API operations or perform routine O&M. 
        # We recommend that you do not hard code your AccessKey ID and AccessKey secret in your project code. Otherwise, the AccessKey pair may be leaked and the security of all resources within your account is compromised. 
        # In this example, the AccessKey ID and AccessKey secret are saved as environment variables. You can also save the AccessKey ID and AccessKey secret to a configuration file based on your business requirements. 
        config.access_key_id = os.environ['CC_AK_ENV']
        config.access_key_secret = os.environ['CC_SK_ENV']
        # Replace the value with the endpoint in the region in which your Image Search instance resides. For example, if your Image Search instance resides in the China (Hangzhou) region, set the endpoint parameter to imagesearch.cn-hangzhou.aliyuncs.com.
        config.endpoint = 'imagesearch.<regionId>.aliyuncs.com'
    
        # The following sample code provides an example on how to use a VPC endpoint to call the Image Search API.
        # Note: You can use a VPC endpoint to call the Image Search API only from ECS instances or resources that reside in the same region. For example, if your Image Search instance resides in the China (Shanghai) region, you can use a VPC endpoint to call the Image Search API only from the ECS instances or resources that reside in the China (Shanghai) region. Otherwise, the API operation fails to be called. In case of a failed API call, check whether your ECS instances or resources are in the same region as your Image Search instance before you call the Image Search API. 
        # config.endpointType = 'internal'  // If you want to use a VPC endpoint to call the Image Search API, you must specify the endpointType parameter and set the value to internal.
        # config.endpoint = 'imagesearch-vpc.<regionId>.aliyuncs.com' // The VPC endpoint that is used to call the Image Search API. Replace the value with the VPC endpoint in the region in which your Image Search instance resides. For example, if your Image Search instance resides in the China (Hangzhou) region, set the endpoint parameter to imagesearch-vpc.cn-hangzhou.aliyuncs.com.
    
        # Replace the value with the region in which your Image Search instance resides. For example, if your Image Search instance resides in the China (Hangzhou) region, set the regionId parameter to cn-hangzhou.
        config.region_id = '<regionId>'
        config.type = 'access_key'
        client = Client(config)
    
        request = DumpMetaListRequest()
        # Required. The name of the Image Search instance. Enter the instance name instead of the Instance ID. After an Image Search instance is purchased, obtain the instance name at https://imagesearch.console.aliyun.com/overview.
        request.instance_name = "xxxxxx"
        # Optional. The ID of the task that is used to export metadata. 
        request.id = 567
        # Optional. The ordinal number of the first entry that is returned. Default value: 1. 
        request.page_number = 1
        # Optional. The number of entries to be returned. Default value: 20. 
        request.page_size = 1
        response = client.dump_meta_list(request)
        print(response.body.to_map())
    
    if __name__ == '__main__':
        dumpMetaList()
  • Sample response

    {
      'Data': {
        'DumpMetaList': [
          {
            'Code': '0',
            'Id': 567,
            'MetaUrl': 'https://xxx/xx/xx',
            'Msg': 'success',
            'Status': 'SUCCESS',
            'UtcCreate': 1639969113000,
            'UtcModified': 1639969140000
          }
        ],
        'PageNumber': 1,
        'PageSize': 1,
        'TotalCount': 1
      },
      'RequestId': '8B2B472B-72EC-1BE5-98F2-780BCBE67F82'
    }

BatchTask

  • Sample code

    from alibabacloud_imagesearch20201214.client import Client
    from alibabacloud_imagesearch20201214.models import IncreaseInstanceRequest
    from alibabacloud_tea_openapi.models import Config
    from alibabacloud_tea_util.models import RuntimeOptions
    
    def batchTask() :
        config = Config()
        # For information about how to create an AccessKey pair, visit https://www.alibabacloud.com/help/en/resource-access-management/latest/accesskey-pairs-create-an-accesskey-pair-for-a-ram-user.
        # The AccessKey pair of an Alibaba Cloud account has the permissions to call all API operations. We recommend that you use the AccessKey pair of a RAM user to call API operations or perform routine O&M. 
        # We recommend that you do not hard code your AccessKey ID and AccessKey secret in your project code. Otherwise, the AccessKey pair may be leaked and the security of all resources within your account is compromised. 
        # In this example, the AccessKey ID and AccessKey secret are saved as environment variables. You can also save the AccessKey ID and AccessKey secret to a configuration file based on your business requirements. 
        config.access_key_id = os.environ['CC_AK_ENV']
        config.access_key_secret = os.environ['CC_SK_ENV']
        # Replace the value with the endpoint in the region in which your Image Search instance resides. For example, if your Image Search instance resides in the China (Hangzhou) region, set the endpoint parameter to imagesearch.cn-hangzhou.aliyuncs.com.
        config.endpoint = 'imagesearch.<regionId>.aliyuncs.com'
    
        # The following sample code provides an example on how to use a VPC endpoint to call the Image Search API.
        # Note: You can use a VPC endpoint to call the Image Search API only from ECS instances or resources that reside in the same region. For example, if your Image Search instance resides in the China (Shanghai) region, you can use a VPC endpoint to call the Image Search API only from the ECS instances or resources that reside in the China (Shanghai) region. Otherwise, the API operation fails to be called. In case of a failed API call, check whether your ECS instances or resources are in the same region as your Image Search instance before you call the Image Search API. 
        # config.endpointType = 'internal'  // If you want to use a VPC endpoint to call the Image Search API, you must specify the endpointType parameter and set the value to internal.
        # config.endpoint = 'imagesearch-vpc.<regionId>.aliyuncs.com' // The VPC endpoint that is used to call the Image Search API. Replace the value with the VPC endpoint in the region in which your Image Search instance resides. For example, if your Image Search instance resides in the China (Hangzhou) region, set the endpoint parameter to imagesearch-vpc.cn-hangzhou.aliyuncs.com.
    
        # Replace the value with the region in which your Image Search instance resides. For example, if your Image Search instance resides in the China (Hangzhou) region, set the regionId parameter to cn-hangzhou.
        config.region_id = '<regionId>'
        config.type = 'access_key'
        client = Client(config)
    
        request = IncreaseInstanceRequest()
        # Required. The name of the Image Search instance. Enter the instance name instead of the Instance ID. After an Image Search instance is purchased, obtain the instance name at https://imagesearch.console.aliyun.com/overview.
        request.instance_name = "xxxxxx"
        # Required. If images are stored in an Object Storage Service (OSS) bucket, enter the bucket name. 
        request.bucket_name = "bucketName"
        # Required. The path to the service where the images are stored. The path must start with a forward slash (/) and cannot end with a forward slash (/). 
        # Create a file named increment.meta in the path in which the images are stored. For more information, see the "Perform batch operations" topic in the "User Guide" of the Image Search documentation. 
        request.path = "/public/xxx"
        # Optional. The callback address if the call succeeds. The address must start with the string http:// or https://. 
        request.callback_address = "http://xxx/xxx"
        response = client.increase_instance(request)
        print(response.body.to_map())
    
    if __name__ == '__main__':
        batchTask()
  • Sample response

    {
      'Data': {
        'Id': 472,
        'IncrementStatus': 'PROCESSING'
      },
      'RequestId': '5D4391D4-54EA-14CD-B616-F23BDE4ECAA3',
      'Success': True
    }

BatchTaskList

  • Sample code

    from alibabacloud_imagesearch20201214.client import Client
    from alibabacloud_imagesearch20201214.models import IncreaseListRequest
    from alibabacloud_tea_openapi.models import Config
    from alibabacloud_tea_util.models import RuntimeOptions
    
    def batchTaskList() :
        config = Config()
        # For information about how to create an AccessKey pair, visit https://www.alibabacloud.com/help/en/resource-access-management/latest/accesskey-pairs-create-an-accesskey-pair-for-a-ram-user.
        # The AccessKey pair of an Alibaba Cloud account has the permissions to call all API operations. We recommend that you use the AccessKey pair of a RAM user to call API operations or perform routine O&M. 
        # We recommend that you do not hard code your AccessKey ID and AccessKey secret in your project code. Otherwise, the AccessKey pair may be leaked and the security of all resources within your account is compromised. 
        # In this example, the AccessKey ID and AccessKey secret are saved as environment variables. You can also save the AccessKey ID and AccessKey secret to a configuration file based on your business requirements. 
        config.access_key_id = os.environ['CC_AK_ENV']
        config.access_key_secret = os.environ['CC_SK_ENV']
        # Replace the value with the endpoint in the region in which your Image Search instance resides. For example, if your Image Search instance resides in the China (Hangzhou) region, set the endpoint parameter to imagesearch.cn-hangzhou.aliyuncs.com.
        config.endpoint = 'imagesearch.<regionId>.aliyuncs.com'
    
        # The following sample code provides an example on how to use a VPC endpoint to call the Image Search API.
        # Note: You can use a VPC endpoint to call the Image Search API only from ECS instances or resources that reside in the same region. For example, if your Image Search instance resides in the China (Shanghai) region, you can use a VPC endpoint to call the Image Search API only from the ECS instances or resources that reside in the China (Shanghai) region. Otherwise, the API operation fails to be called. In case of a failed API call, check whether your ECS instances or resources are in the same region as your Image Search instance before you call the Image Search API. 
        # config.endpointType = 'internal'  // If you want to use a VPC endpoint to call the Image Search API, you must specify the endpointType parameter and set the value to internal.
        # config.endpoint = 'imagesearch-vpc.<regionId>.aliyuncs.com' // The VPC endpoint that is used to call the Image Search API. Replace the value with the VPC endpoint in the region in which your Image Search instance resides. For example, if your Image Search instance resides in the China (Hangzhou) region, set the endpoint parameter to imagesearch-vpc.cn-hangzhou.aliyuncs.com.
    
        # Replace the value with the region in which your Image Search instance resides. For example, if your Image Search instance resides in the China (Hangzhou) region, set the regionId parameter to cn-hangzhou.
        config.region_id = '<regionId>'
        config.type = 'access_key'
        client = Client(config)
    
        request = IncreaseListRequest()
        # Required. The name of the Image Search instance. Enter the instance name instead of the Instance ID. After an Image Search instance is purchased, obtain the instance name at https://imagesearch.console.aliyun.com/overview.
        request.instance_name = "xxxxxx"
        # Optional. The ID of the task. 
        request.id = 567
        # Optional. Query the name of the OSS bucket. 
        request.bucket_name = "BucketName"
        # Optional. Query the path to the OSS bucket. 
        request.path = "/localization/xxxx"
        # Optional. The ordinal number of the first entry that is returned. Default value: 1. 
        request.page_number = 1
        # Optional. The number of entries to be returned. Default value: 20. 
        request.page_size = 1
        response = client.increase_list(request)
        print(response.body.to_map())
    
    if __name__ == '__main__':
        batchTaskList()
  • Sample response

    {
      'Data': {
        'Increments': {
          'Instance': [
            {
              'BucketName': 'xxxxx',
              'Code': '0',
              'ErrorUrl': 'https://ccx/xx/',
              'Id': 567,
              'Msg': 'success',
              'Path': '/public/xx',
              'Status': 'NORMAL',
              'UtcCreate': 1639107872000,
              'UtcModified': 1639125540000
            }
          ]
        },
        'PageNumber': 1,
        'PageSize': 1,
        'TotalCount': 1
      },
      'RequestId': 'C02F0C44-E61F-1E96-870C-CBE19E137ADF'
    }