Python SDK
Image Search provides a Python SDK with code examples for each API operation.
For more product details and technical support, click Online Consulting or contact us through our DingTalk group (35035130).
API operations
|
Interface name |
Description |
|
Add |
Adds an image. |
|
SearchImageByPic |
Searches for similar images using an image. |
|
SearchImageByName |
Searches for similar images using an indexed image specified by its name. |
|
SearchImageByText |
Text search is available only for the Product Multimodal Search service. |
SearchImageByFilter | Searches for images using filter conditions. |
|
Delete |
Deletes an image. |
|
UpdateImage |
Modifies an image. |
|
Detail |
Queries instance information. |
|
DumpMeta |
Exports metadata. |
|
DumpMetaList |
Lists metadata export tasks. |
|
BatchTask |
Submits a batch job. |
|
BatchTaskList |
Lists batch tasks. |
|
CompareSimilarByImage |
Compares the similarity between two images. |
|
CheckImageExists |
Checks whether an image exists. |
Prerequisites
-
Before you install the SDK, create an Alibaba Cloud account and get an AccessKey pair. SeeCreate an AccessKey.
-
Install the SDK.
pip install alibabacloud_imagesearch20201214
Add
-
Code example
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. Note that this is the instance name, not the instance ID. You can view the instance name in the instance information on the console after purchase: https://imagesearch.console.aliyun.com/overview request.instance_name = '<instanceName>' # Required. The product ID. The ID can be up to 256 characters long. # A product can have multiple images. request.product_id = '<productId>' # Required. The image name. The name can be up to 256 characters long. # 1. The combination of ProductId and PicName uniquely identifies an image. # 2. If you add an image with the same ProductId and PicName multiple times, the last added image overwrites the previous ones. request.pic_name = '<picName>' # The image content. The image can be up to 4 MB in size, with a transfer timeout of 5 seconds. Supported formats are PNG, JPG, JPEG, BMP, GIF, WEBP, TIFF, and PPM. # For product, trademark, and generic image search, the image height and width must be between 100 and 4096 pixels. # For fabric search, the image height and width must be between 448 and 4096 pixels. # The image cannot contain rotation information. # To use a URL, uncomment the following lines. # url = '<fileUrl>' # f = BytesIO(requests.get(url).content) # Add an image from a file. f = open('<filePath>', 'rb') request.pic_content_object = f # Optional. The product category. # 1. For product search: If you set a category, the specified category is used. If you do not set a category, the system predicts one. The predicted category is available in the response. # 2. For fabric, trademark, and generic search: The system sets the category to 88888888, regardless of whether you specify one. request.category_id = 3 # Optional. Custom content. It can be up to 4096 characters long. # This field is returned in the query response. For example, you can add a text description of the image. request.custom_content = "this is a simple test" # Optional. An integer attribute for filtering during queries. This field is returned in the query response. # For example, you can set different IntAttr values for images from different sites or users to isolate them during queries. request.int_attr = 56 # Optional. A string attribute for filtering during queries. It can be up to 128 characters long and is returned in the query response. request.str_attr = "test" # Optional. Specifies whether to perform subject identification. The default value is true. # 1. If true, the system performs subject identification and searches based on the identified subject. The identification result is available in the response. # 2. If false, the system searches using the entire image without subject identification. # 3. For fabric search, this parameter is ignored, and the system searches using the entire image. request.crop = True # Optional. The subject region of the image, in the format x1,x2,y1,y2. x1,y1 are the coordinates of the upper-left corner, and x2,y2 are the coordinates of the lower-right corner. The specified region cannot exceed the image boundaries. # If you specify a Region, the system searches using this region, regardless of the Crop parameter value. # For fabric search, this parameter is ignored, and the system searches using the entire image. request.region = "167,467,221,407" config = Config() # For information about how to create an AccessKey pair, see https://www.alibabacloud.com/help/en/ram/latest/create-an-accesskey-pair. # An AccessKey pair of an Alibaba Cloud account has full access permissions to all APIs. We recommend using a RAM user for API access and daily O&M. # We strongly recommend that you do not hard-code your AccessKey ID and AccessKey secret in your project code. Otherwise, your AccessKey pair may be leaked, which threatens the security of all your resources. # This example shows how to store the AccessKey ID and AccessKey secret in environment variables. You can also store them in a configuration file as needed. config.access_key_id = os.environ['CC_AK_ENV'] config.access_key_secret = os.environ['CC_SK_ENV'] # Replace with the region of your instance. For example, if your instance is in the China (Hangzhou) region, set the endpoint to 'imagesearch.cn-hangzhou.aliyuncs.com'. config.endpoint = 'imagesearch.[regionId].aliyuncs.com' # The following code shows how to access the service over an internal network (VPC). # Note: You can access the service over an internal network (VPC) only from an ECS instance or resource in the same region. For example, if your Image Search instance is in the China (Shanghai) region, your ECS instance or resource must also be in the China (Shanghai) region to access the Image Search service using a VPC endpoint. Otherwise, the call will fail. If a call fails, check whether your ECS instance or resource is in the same region as the Image Search instance. # config.endpointType = 'internal' // If you access the Image Search service over an internal network, this parameter is required and must be set to 'internal'. # config.endpoint = 'imagesearch-vpc.[regionId].aliyuncs.com' // This is the VPC endpoint. Replace with the region of your instance. For example, if your instance is in the China (Hangzhou) region, set the endpoint to 'imagesearch-vpc.cn-hangzhou.aliyuncs.com'. # Replace with the region of your instance. For example, if your instance is in the China (Hangzhou) region, set regionId 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
Code example
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. This is the instance name, not the instance ID. After you purchase an instance, you can find the name in the instance information section of the console: https://imagesearch.console.aliyun.com/overview request.instance_name = '<instanceName>' # The image content. The image can be up to 4 MB in size and has a transfer timeout of 5 seconds. The supported formats are PNG, JPG, JPEG, BMP, GIF, WEBP, TIFF, and PPM. # For product, trademark, and generic image searches, the height and width of the image must each be between 100 and 4,096 pixels. # For fabric searches, the height and width of the image must each be between 448 and 4,096 pixels. # The image cannot contain rotation information. # To search by using a URL, uncomment the following lines. # url = '<fileUrl>' # f = BytesIO(requests.get(url).content) # Search for similar images by using an image from a local file. f = open('<filePath>', 'rb') request.pic_content_object = f # Optional. The product category. # 1. For product searches: If you specify a category, the search uses it. Otherwise, the system predicts a category, which is included in the response. # 2. For fabric, trademark, and generic searches: The system sets the category to 88888888, regardless of whether you specify a category. request.category_id = 3 # Optional. The number of results to return. Valid values: 1 to 100. Default value: 10. request.num = 10 # Optional. The starting position of the results to return. Valid values: 0 to 499. Default value: 0. request.start = 0 # Optional. Specifies whether to perform subject identification. Default value: true. # 1. If set to true, the system performs subject identification, searches based on the identified subject, and includes the identification result in the response. # 2. If set to false, the system searches the entire image without performing subject identification. # 3. For fabric searches, this parameter is ignored, and the system searches based on the entire image. request.crop = True # Optional. The subject region of the image, in the format x1,x2,y1,y2. In this format, (x1, y1) are the coordinates of the upper-left corner, and (x2, y2) are the coordinates of the lower-right corner. The specified region cannot exceed the image boundaries. # If you specify this parameter, the system searches that region, ignoring the Crop parameter. # This parameter is ignored for fabric searches. request.region ="167,467,221,407" # Optional. The filter conditions. # The int_attr parameter supports the following operators: in, not in, >, >=, <, <=, and =. The str_attr parameter supports the following operators: in, not in, =, and !=. You can use AND and OR to combine multiple conditions. # Examples: # 1. Filter results based on IntAttr: int_attr>=100 # 2. Filter results based on StrAttr: str_attr!="value1" # 3. Filter results based on a combination of IntAttr and StrAttr: int_attr=1000 AND str_attr="value1" request.filter = "int_attr=56 AND str_attr=\"test\" AND int_attr2 in (56)" # Optional. The similarity score threshold. # Returns only images with similarity scores greater than or equal to the threshold. The threshold is a value from 0.00 to 1.00. The value can have up to two decimal places. Default: 0.00. request.score_threshold = "0.54" # Optional. If set to true, groups the response by product ID. request.distinct_product_id = False config = Config() # For information about how to create an AccessKey pair, see https://www.alibabacloud.com/help/en/ram/latest/create-an-accesskey-pair. # An Alibaba Cloud account's AccessKey pair has full permissions on all API operations. We recommend using a RAM user for API access and daily O&M. # We strongly recommend that you do not hard-code your AccessKey ID and AccessKey Secret in your project code. Leaking your AccessKey pair compromises the security of all your resources. # This example shows how to store the AccessKey ID and AccessKey Secret in environment variables. You can also store them in a configuration file. config.access_key_id = os.environ['CC_AK_ENV'] config.access_key_secret = os.environ['CC_SK_ENV'] # Replace the value with the region of your instance. For example, if your instance is in the China (Hangzhou) region, set the endpoint to 'imagesearch.cn-hangzhou.aliyuncs.com'. config.endpoint = 'imagesearch.<regionId>.aliyuncs.com' # The following code shows how to access the service over an internal network (VPC). # Note: To access the service over an internal network (VPC), the calling resource, such as an ECS instance, must be in the same region as the Image Search instance. Otherwise, the call will fail. # config.endpointType = 'internal' // Required and must be set to 'internal' for internal network access. # config.endpoint = 'imagesearch-vpc.<regionId>.aliyuncs.com' // The VPC endpoint. For example, if your instance is in the China (Hangzhou) region, set the endpoint to 'imagesearch-vpc.cn-hangzhou.aliyuncs.com'. # The ID of the region where your instance is located. For example, if your instance is in the China (Hangzhou) region, set regionId 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
-
Code example
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. Note that this is the instance name, not the instance ID. You can view the instance name in the instance information on the console after purchase: https://imagesearch.console.aliyun.com/overview request.instance_name = '<instanceName>' # Required. The product ID. The ID can be up to 256 characters long. # A product can have multiple images. request.product_id = '<productId>' # Required. The image name. The name can be up to 256 characters long. # 1. The combination of ProductId and PicName uniquely identifies an image. # 2. If you add an image with the same ProductId and PicName multiple times, the last added image overwrites the previous ones. request.pic_name = '<picName>' # Optional. The product category. # 1. For product search: If you set a category, the specified category is used. If you do not set a category, the system predicts one. The predicted category is available in the response. # 2. For fabric, trademark, and generic search: The system sets the category to 88888888, regardless of whether you specify one. request.category_id = 3 # Optional. The number of results to return. Value range: 1 to 100. Default value: 10. request.num = 10 # Optional. The starting position of the results. Value range: 0 to 499. Default value: 0. request.start = 0 # Optional. Specifies whether to perform subject identification. The default value is true. # 1. If true, the system performs subject identification and searches based on the identified subject. The identification result is available in the response. # 2. If false, the system searches using the entire image without subject identification. # 3. For fabric search, this parameter is ignored, and the system searches using the entire image. request.crop = True # Optional. The subject region of the image, in the format x1,x2,y1,y2. x1,y1 are the coordinates of the upper-left corner, and x2,y2 are the coordinates of the lower-right corner. The specified region cannot exceed the image boundaries. # If you specify a Region, the system searches using this region, regardless of the Crop parameter value. # 3. For fabric search, this parameter is ignored, and the system searches using the entire image. request.region="167,467,221,407" # Optional. Filter conditions. # The int_attr parameter supports the following operators: in, not in, >, >=, <, <=, and =. The str_attr parameter supports the following operators: in, not in, =, and !=. You can use AND and OR to combine multiple conditions. # Examples: # 1. Filter results by IntAttr: int_attr>=100 # 2. Filter results by StrAttr: str_attr!="value1" # 3. Filter results by both IntAttr and StrAttr: int_attr=1000 AND str_attr="value1" request.filter= "int_attr=56 AND str_attr=\"test\" AND int_attr2 in (56)" # Optional. The similarity score threshold. # After you set a similarity score threshold, only images with a similarity score greater than or equal to the threshold are returned. The threshold ranges from 0.00 to 1.00, with up to two decimal places supported. The default value is 0.00. request.score_threshold= "0.54" config = Config() # For information about how to create an AccessKey pair, see https://www.alibabacloud.com/help/en/ram/latest/create-an-accesskey-pair. # An AccessKey pair of an Alibaba Cloud account has full access permissions to all APIs. We recommend using a RAM user for API access and daily O&M. # We strongly recommend that you do not hard-code your AccessKey ID and AccessKey secret in your project code. Otherwise, your AccessKey pair may be leaked, which threatens the security of all your resources. # This example shows how to store the AccessKey ID and AccessKey secret in environment variables. You can also store them in a configuration file as needed. config.access_key_id = os.environ['CC_AK_ENV'] config.access_key_secret = os.environ['CC_SK_ENV'] # Replace with the region of your instance. For example, if your instance is in the China (Hangzhou) region, set the endpoint to 'imagesearch.cn-hangzhou.aliyuncs.com'. config.endpoint = 'imagesearch.<regionId>.aliyuncs.com' # The following code shows how to access the service over an internal network (VPC). # Note: You can access the service over an internal network (VPC) only from an ECS instance or resource in the same region. For example, if your Image Search instance is in the China (Shanghai) region, your ECS instance or resource must also be in the China (Shanghai) region to access the Image Search service using a VPC endpoint. Otherwise, the call will fail. If a call fails, check whether your ECS instance or resource is in the same region as the Image Search instance. # config.endpointType = 'internal' // If you access the Image Search service over an internal network, this parameter is required and must be set to 'internal'. # config.endpoint = 'imagesearch-vpc.<regionId>.aliyuncs.com' // This is the VPC endpoint. Replace with the region of your instance. For example, if your instance is in the China (Hangzhou) region, set the endpoint to 'imagesearch-vpc.cn-hangzhou.aliyuncs.com'. # Replace with the region of your instance. For example, if your instance is in the China (Hangzhou) region, set regionId 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' }] } }
SearchImageByText
The SearchImageByText operation is available only for the product multimodal search service type.
-
Code example
from alibabacloud_imagesearch20201214.client import Client from alibabacloud_imagesearch20201214.models import SearchImageByTextRequest from alibabacloud_tea_openapi.models import Config from alibabacloud_tea_util.models import RuntimeOptions def searchImageByText() : request = SearchImageByTextRequest() # Required. The name of the Image Search instance. Note that this is the instance name, not the instance ID. You can view the instance name in the instance information on the console after purchase: https://imagesearch.console.aliyun.com/overview # Note: This operation is available only for the product multimodal search service type. request.instance_name = '<instanceName>' # Optional. The number of results to return. Value range: 1 to 100. Default value: 10. request.num = 10 # Optional. The starting position of the results. Value range: 0 to 499. Default value: 0. request.start = 0 # Optional. Filter conditions. # The int_attr parameter supports the following operators: in, not in, >, >=, <, <=, and =. The str_attr parameter supports the following operators: in, not in, =, and !=. You can use AND and OR to combine multiple conditions. # Examples: # 1. Filter results by IntAttr: int_attr>=100 # 2. Filter results by StrAttr: str_attr!="value1" # 3. Filter results by both IntAttr and StrAttr: int_attr=1000 AND str_attr="value1" request.filter= "int_attr=56 AND str_attr=\"test\" AND int_attr2 in (56)" # Optional. The similarity score threshold. # After you set a similarity score threshold, only images with a similarity score greater than or equal to the threshold are returned. The threshold ranges from 0.00 to 1.00, with up to two decimal places supported. The default value is 0.00. request.score_threshold= "0.54" # The descriptive text. It supports both Chinese and English and can be up to 512 characters long. request.text = "xxxxx" config = Config() # For information about how to create an AccessKey pair, see https://www.alibabacloud.com/help/en/ram/latest/create-an-accesskey-pair. # An AccessKey pair of an Alibaba Cloud account has full access permissions to all APIs. We recommend using a RAM user for API access and daily O&M. # We strongly recommend that you do not hard-code your AccessKey ID and AccessKey secret in your project code. Otherwise, your AccessKey pair may be leaked, which threatens the security of all your resources. # This example shows how to store the AccessKey ID and AccessKey secret in environment variables. You can also store them in a configuration file as needed. config.access_key_id = os.environ['CC_AK_ENV'] config.access_key_secret = os.environ['CC_SK_ENV'] # Replace with the region of your instance. For example, if your instance is in the China (Hangzhou) region, set the endpoint to 'imagesearch.cn-hangzhou.aliyuncs.com'. config.endpoint = 'imagesearch.<regionId>.aliyuncs.com' # The following code shows how to access the service over an internal network (VPC). # Note: You can access the service over an internal network (VPC) only from an ECS instance or resource in the same region. For example, if your Image Search instance is in the China (Shanghai) region, your ECS instance or resource must also be in the China (Shanghai) region to access the Image Search service using a VPC endpoint. Otherwise, the call will fail. If a call fails, check whether your ECS instance or resource is in the same region as the Image Search instance. # config.endpointType = 'internal' // If you access the Image Search service over an internal network, this parameter is required and must be set to 'internal'. # config.endpoint = 'imagesearch-vpc.<regionId>.aliyuncs.com' // This is the VPC endpoint. Replace with the region of your instance. For example, if your instance is in the China (Hangzhou) region, set the endpoint to 'imagesearch-vpc.cn-hangzhou.aliyuncs.com'. # Replace with the region of your instance. For example, if your instance is in the China (Hangzhou) region, set regionId to 'cn-hangzhou'. config.region_id = '<regionId>' config.type = 'access_key' client = Client(config) response = client.search_image_by_text(request) print(response.to_map()) if __name__ == '__main__': searchImageByText() -
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, 'IntAttr': None, 'StrAttr': None }, { 'CategoryId': 20, 'ProductId': 'test_0426_1', 'PicName': 'test_0426_1.png', 'CustomContent': None, 'score':1.0, 'IntAttr': None, 'StrAttr': None }], 'Head': { 'DocsReturn': 5, 'DocsFound': 5, 'SearchTime': 15 }, 'PicInfo': { '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' }], } }
SearchImageByFilter API
Code example
from alibabacloud_imagesearch20201214.client import Client from alibabacloud_imagesearch20201214.models import SearchImageByFilterRequest from alibabacloud_tea_openapi.models import Config from alibabacloud_tea_util.models import RuntimeOptions def searchImageByFilter() : request = SearchImageByFilterRequest() # Required. The Image Search instance name. This is the instance name, not the instance ID. After you purchase an instance, find the name in the instance information section of the console: https://imagesearch.console.aliyun.com/overview request.instance_name = '<instanceName>' # Optional. The number of results to return. Valid values: 1 to 100. Default value: 10. request.num = 10 # Optional. The starting position of the results to return. Valid values: 0 to 499. Default value: 0. request.start = 0 # Required. The filter conditions. # The int_attr parameter supports the following operators: in, not in, >, >=, <, <=, and =. The str_attr parameter supports the following operators: in, not in, =, and !=. You can use AND and OR to combine multiple conditions. # Examples: # 1. Filter results by IntAttr: int_attr>=100 # 2. Filter results by StrAttr: str_attr!="value1" # 3. Filter results by a combination of IntAttr and StrAttr: int_attr=1000 AND str_attr="value1" request.filter = "int_attr=56 AND str_attr=\"test\" AND int_attr2 in (56)" config = Config() # To create an AccessKey pair, see https://help.aliyun.com/document_detail/116401.htm # An Alibaba Cloud account's AccessKey pair grants full permissions for all API operations. Use a RAM user to call API operations or perform routine O&M. # Do not hard-code the AccessKey ID and AccessKey Secret in your project code. This prevents AccessKey pair leaks that could compromise the security of all your resources. # This example shows how to store the AccessKey ID and AccessKey Secret in environment variables. You can also store them in a configuration file based on your business needs. config.access_key_id = os.environ['CC_AK_ENV'] config.access_key_secret = os.environ['CC_SK_ENV'] # Replace the value with the region of your instance. For example, if your instance is in the China (Hangzhou) region, set the endpoint to 'imagesearch.cn-hangzhou.aliyuncs.com'. config.endpoint = 'imagesearch.<regionId>.aliyuncs.com' # To use VPC access: # Note: VPC access is available only for ECS instances or resources in the same region as the Image Search instance. For example, if your Image Search instance is in the China (Shanghai) region, your ECS instance or resource must also be in the China (Shanghai) region to access the Image Search service through a VPC endpoint. Otherwise, the call fails. If this occurs, verify that your ECS instance or resource is in the same region as the Image Search instance. # config.endpointType = 'internal' // Required for VPC access. You must set this parameter to 'internal'. # config.endpoint = 'imagesearch-vpc.<regionId>.aliyuncs.com' // Specify the VPC endpoint. Replace the value with the region of your instance. For example, if your instance is in the China (Hangzhou) region, set the endpoint to 'imagesearch-vpc.cn-hangzhou.aliyuncs.com'. # Replace the value with the region of your instance. For example, if your instance is in the China (Hangzhou) region, set regionId to 'cn-hangzhou'. config.region_id = '<regionId>' config.type = 'access_key' client = Client(config) response = client.search_image_by_filter(request) print(response.to_map()) if __name__ == '__main__': searchImageByFilter()Sample response
{ 'statusCode': 200, 'body': { 'Auctions': [ ], 'Code': 0, 'Msg': 'success', 'RequestId': 'xx-D43C-19E8-AD14-E7FE326574B0', 'Success': True } }
Delete
Code example
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. This is the instance name, not the instance ID. After purchasing an instance, you can find this name in the Instance Information section of the Image Search console: https://imagesearch.console.aliyun.com/overview request.instance_name = '<instanceName>' # Required. The product ID. The ID can be up to 256 characters. # A product can have multiple images. request.product_id = '<productId>' # Required. The image name. The name can be up to 256 characters. # 1. The combination of ProductId and PicName uniquely identifies an image. # 2. If you add multiple images with the same ProductId and PicName, the most recently added image overwrites the others. request.pic_name = '<picName>' # Optional. Set to true to delete images based on the filter or a combination of the filter and the product ID. request.is_delete_by_filter = False request.filter = 'intattr3=xxx' config = Config() # An AccessKey pair for an Alibaba Cloud account has permissions for all API operations. We recommend that you use a RAM user for API access or routine O&M. # We strongly recommend that you do not hard-code the AccessKey ID and AccessKey Secret in your project code. Otherwise, your AccessKey pair could be leaked, compromising the security of all your resources. # This example shows how to store the AccessKey ID and AccessKey Secret in environment variables. You can also store them in a configuration file based on your business needs. config.access_key_id = os.environ['CC_AK_ENV'] config.access_key_secret = os.environ['CC_SK_ENV'] # Replace the placeholder with the ID of your instance's region. For example, if your instance is in the China (Hangzhou) region, set the endpoint to 'imagesearch.cn-hangzhou.aliyuncs.com'. config.endpoint = 'imagesearch.<regionId>.aliyuncs.com' # The following code shows how to access the service over an internal network (VPC). # Note: You can access the service over an internal network (VPC) only from an ECS instance or resource in the same region. For example, to access an Image Search instance in China (Shanghai) via a VPC endpoint, your ECS instance must also be in China (Shanghai). If a call fails, verify that your ECS instance and Image Search instance are in the same region. # config.endpointType = 'internal' // Required for internal network (VPC) access. Set to 'internal'. # config.endpoint = 'imagesearch-vpc.<regionId>.aliyuncs.com' // The VPC endpoint. Replace the placeholder with the region ID of your instance. For example, if your instance is in the China (Hangzhou) region, set the endpoint to 'imagesearch-vpc.cn-hangzhou.aliyuncs.com'. # Replace the placeholder with the ID of your instance's region. For example, if your instance is in the China (Hangzhou) region, set regionId to 'cn-hangzhou'. config.region_id = '<regionId>' # To create an AccessKey pair, see https://help.aliyun.com/document_detail/116401.htm 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
Code example
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, see https://www.alibabacloud.com/help/en/ram/latest/create-an-accesskey-pair. # The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. We recommend that you use a RAM user to call API operations or perform routine O&M. # Do not hard-code the AccessKey ID and AccessKey secret in your project code. Leaking your AccessKey pair compromises the security of all your resources. # This example shows how to store the AccessKey ID and AccessKey secret in environment variables. You can also store them in a configuration file. config.access_key_id = os.environ['CC_AK_ENV'] config.access_key_secret = os.environ['CC_SK_ENV'] # Replace the value with the region ID of your instance. For example, if your instance is in the China (Hangzhou) region, set the endpoint to 'imagesearch.cn-hangzhou.aliyuncs.com'. config.endpoint = 'imagesearch.<regionId>.aliyuncs.com' # The following code shows how to access the service over an internal network (VPC). # Note: You can access the service over an internal network (VPC) only from an ECS instance or resource in the same region. For example, if your Image Search instance is in the China (Shanghai) region, your ECS instance or resource must also be in the China (Shanghai) region to access the Image Search service by using a VPC endpoint. Otherwise, the call fails. # config.endpointType = 'internal' // Required for internal network access. Set this parameter to 'internal'. # config.endpoint = 'imagesearch-vpc.<regionId>.aliyuncs.com' // This is the VPC endpoint. Replace the value with the region ID of your instance. For example, if your instance is in the China (Hangzhou) region, set the endpoint to 'imagesearch-vpc.cn-hangzhou.aliyuncs.com'. # Replace the value with the region ID of your instance. For example, if your instance is in the China (Hangzhou) region, set the value to 'cn-hangzhou'. config.region_id = '<regionId>' config.type = 'access_key' client = Client(config) request = UpdateImageRequest() # Required. The Image Search instance name. This is the instance name, not the instance ID. After you purchase an instance, you can find its name in the instance information section of the Image Search console: https://imagesearch.console.aliyun.com/overview request.instance_name = "xxxxxx" # Required. The product ID. This parameter cannot be modified. request.product_id = "1" # Optional. The image name. If you omit this parameter, the service updates one or more images that have the specified product ID. request.pic_name = "1" # Optional. An integer attribute for filtering during queries. This attribute is returned in the query results. request.int_attr = "1" # Optional. A string attribute for filtering during queries. The attribute can be up to 128 characters long and is returned in the query results. request.str_attr = "test" # Optional. Custom content, which can be up to 4,096 characters long. request.custom_content = "This is a test 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
-
Code example
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, see https://www.alibabacloud.com/help/en/ram/latest/create-an-accesskey-pair. # An AccessKey pair of an Alibaba Cloud account has full access permissions to all APIs. We recommend using a RAM user for API access and daily O&M. # We strongly recommend that you do not hard-code your AccessKey ID and AccessKey secret in your project code. Otherwise, your AccessKey pair may be leaked, which threatens the security of all your resources. # This example shows how to store the AccessKey ID and AccessKey secret in environment variables. You can also store them in a configuration file as needed. config.access_key_id = os.environ['CC_AK_ENV'] config.access_key_secret = os.environ['CC_SK_ENV'] # Replace with the region of your instance. For example, if your instance is in the China (Hangzhou) region, set the endpoint to 'imagesearch.cn-hangzhou.aliyuncs.com'. config.endpoint = 'imagesearch.<regionId>.aliyuncs.com' # The following code shows how to access the service over an internal network (VPC). # Note: You can access the service over an internal network (VPC) only from an ECS instance or resource in the same region. For example, if your Image Search instance is in the China (Shanghai) region, your ECS instance or resource must also be in the China (Shanghai) region to access the Image Search service using a VPC endpoint. Otherwise, the call will fail. If a call fails, check whether your ECS instance or resource is in the same region as the Image Search instance. # config.endpointType = 'internal' // If you access the Image Search service over an internal network, this parameter is required and must be set to 'internal'. # config.endpoint = 'imagesearch-vpc.<regionId>.aliyuncs.com' // This is the VPC endpoint. Replace with the region of your instance. For example, if your instance is in the China (Hangzhou) region, set the endpoint to 'imagesearch-vpc.cn-hangzhou.aliyuncs.com'. # Replace with the region of your instance. For example, if your instance is in the China (Hangzhou) region, set regionId to 'cn-hangzhou'. config.region_id = '<regionId>' config.type = 'access_key' client = Client(config) request = DetailRequest() # Required. The name of the Image Search instance. Note that this is the instance name, not the instance ID. You can view the instance name in the instance information on the console after purchase: 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
-
Code example
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, see https://www.alibabacloud.com/help/en/ram/latest/create-an-accesskey-pair. # An AccessKey pair of an Alibaba Cloud account has full access permissions to all APIs. We recommend using a RAM user for API access and daily O&M. # We strongly recommend that you do not hard-code your AccessKey ID and AccessKey secret in your project code. Otherwise, your AccessKey pair may be leaked, which threatens the security of all your resources. # This example shows how to store the AccessKey ID and AccessKey secret in environment variables. You can also store them in a configuration file as needed. config.access_key_id = os.environ['CC_AK_ENV'] config.access_key_secret = os.environ['CC_SK_ENV'] # Replace with the region of your instance. For example, if your instance is in the China (Hangzhou) region, set the endpoint to 'imagesearch.cn-hangzhou.aliyuncs.com'. config.endpoint = 'imagesearch.<regionId>.aliyuncs.com' # The following code shows how to access the service over an internal network (VPC). # Note: You can access the service over an internal network (VPC) only from an ECS instance or resource in the same region. For example, if your Image Search instance is in the China (Shanghai) region, your ECS instance or resource must also be in the China (Shanghai) region to access the Image Search service using a VPC endpoint. Otherwise, the call will fail. If a call fails, check whether your ECS instance or resource is in the same region as the Image Search instance. # config.endpointType = 'internal' // If you access the Image Search service over an internal network, this parameter is required and must be set to 'internal'. # config.endpoint = 'imagesearch-vpc.<regionId>.aliyuncs.com' // This is the VPC endpoint. Replace with the region of your instance. For example, if your instance is in the China (Hangzhou) region, set the endpoint to 'imagesearch-vpc.cn-hangzhou.aliyuncs.com'. # Replace with the region of your instance. For example, if your instance is in the China (Hangzhou) region, set regionId to 'cn-hangzhou'. config.region_id = '<regionId>' config.type = 'access_key' client = Client(config) request = DumpMetaRequest() # Required. The name of the Image Search instance. Note that this is the instance name, not the instance ID. You can view the instance name in the instance information on the console after purchase: 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
-
Code example
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, see https://www.alibabacloud.com/help/en/ram/latest/create-an-accesskey-pair. # An AccessKey pair of an Alibaba Cloud account has full access permissions to all APIs. We recommend using a RAM user for API access and daily O&M. # We strongly recommend that you do not hard-code your AccessKey ID and AccessKey secret in your project code. Otherwise, your AccessKey pair may be leaked, which threatens the security of all your resources. # This example shows how to store the AccessKey ID and AccessKey secret in environment variables. You can also store them in a configuration file as needed. config.access_key_id = os.environ['CC_AK_ENV'] config.access_key_secret = os.environ['CC_SK_ENV'] # Replace with the region of your instance. For example, if your instance is in the China (Hangzhou) region, set the endpoint to 'imagesearch.cn-hangzhou.aliyuncs.com'. config.endpoint = 'imagesearch.<regionId>.aliyuncs.com' # The following code shows how to access the service over an internal network (VPC). # Note: You can access the service over an internal network (VPC) only from an ECS instance or resource in the same region. For example, if your Image Search instance is in the China (Shanghai) region, your ECS instance or resource must also be in the China (Shanghai) region to access the Image Search service using a VPC endpoint. Otherwise, the call will fail. If a call fails, check whether your ECS instance or resource is in the same region as the Image Search instance. # config.endpointType = 'internal' // If you access the Image Search service over an internal network, this parameter is required and must be set to 'internal'. # config.endpoint = 'imagesearch-vpc.<regionId>.aliyuncs.com' // This is the VPC endpoint. Replace with the region of your instance. For example, if your instance is in the China (Hangzhou) region, set the endpoint to 'imagesearch-vpc.cn-hangzhou.aliyuncs.com'. # Replace with the region of your instance. For example, if your instance is in the China (Hangzhou) region, set regionId to 'cn-hangzhou'. config.region_id = '<regionId>' config.type = 'access_key' client = Client(config) request = DumpMetaListRequest() # Required. The name of the Image Search instance. Note that this is the instance name, not the instance ID. You can view the instance name in the instance information on the console after purchase: https://imagesearch.console.aliyun.com/overview request.instance_name = "xxxxxx" # Optional. The ID of the metadata export task. request.id = 567 # Optional. The starting position of the results. Default value: 1. request.page_number = 1 # Optional. The number of results to return. 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
-
Code example
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, see https://www.alibabacloud.com/help/en/ram/latest/create-an-accesskey-pair. # An AccessKey pair of an Alibaba Cloud account has full access permissions to all APIs. We recommend using a RAM user for API access and daily O&M. # We strongly recommend that you do not hard-code your AccessKey ID and AccessKey secret in your project code. Otherwise, your AccessKey pair may be leaked, which threatens the security of all your resources. # This example shows how to store the AccessKey ID and AccessKey secret in environment variables. You can also store them in a configuration file as needed. config.access_key_id = os.environ['CC_AK_ENV'] config.access_key_secret = os.environ['CC_SK_ENV'] # Replace with the region of your instance. For example, if your instance is in the China (Hangzhou) region, set the endpoint to 'imagesearch.cn-hangzhou.aliyuncs.com'. config.endpoint = 'imagesearch.<regionId>.aliyuncs.com' # The following code shows how to access the service over an internal network (VPC). # Note: You can access the service over an internal network (VPC) only from an ECS instance or resource in the same region. For example, if your Image Search instance is in the China (Shanghai) region, your ECS instance or resource must also be in the China (Shanghai) region to access the Image Search service using a VPC endpoint. Otherwise, the call will fail. If a call fails, check whether your ECS instance or resource is in the same region as the Image Search instance. # config.endpointType = 'internal' // If you access the Image Search service over an internal network, this parameter is required and must be set to 'internal'. # config.endpoint = 'imagesearch-vpc.<regionId>.aliyuncs.com' // This is the VPC endpoint. Replace with the region of your instance. For example, if your instance is in the China (Hangzhou) region, set the endpoint to 'imagesearch-vpc.cn-hangzhou.aliyuncs.com'. # Replace with the region of your instance. For example, if your instance is in the China (Hangzhou) region, set regionId to 'cn-hangzhou'. config.region_id = '<regionId>' config.type = 'access_key' client = Client(config) request = IncreaseInstanceRequest() # Required. The name of the Image Search instance. Note that this is the instance name, not the instance ID. You can view the instance name in the instance information on the console after purchase: https://imagesearch.console.aliyun.com/overview request.instance_name = "xxxxxx" # Required. The name of the OSS bucket. request.bucket_name = "bucketName" # Required. The path. It must start with a forward slash (/) and not end with one. # The increment.meta file must be prepared in this path in advance. For more information, see the Batch Operations document in the User Guide. request.path = "/public/xxx" # Optional. The webhook address for successful requests. It must start with 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
-
Code example
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, see https://www.alibabacloud.com/help/en/ram/latest/create-an-accesskey-pair. # An AccessKey pair of an Alibaba Cloud account has full access permissions to all APIs. We recommend using a RAM user for API access and daily O&M. # We strongly recommend that you do not hard-code your AccessKey ID and AccessKey secret in your project code. Otherwise, your AccessKey pair may be leaked, which threatens the security of all your resources. # This example shows how to store the AccessKey ID and AccessKey secret in environment variables. You can also store them in a configuration file as needed. config.access_key_id = os.environ['CC_AK_ENV'] config.access_key_secret = os.environ['CC_SK_ENV'] # Replace with the region of your instance. For example, if your instance is in the China (Hangzhou) region, set the endpoint to 'imagesearch.cn-hangzhou.aliyuncs.com'. config.endpoint = 'imagesearch.<regionId>.aliyuncs.com' # The following code shows how to access the service over an internal network (VPC). # Note: You can access the service over an internal network (VPC) only from an ECS instance or resource in the same region. For example, if your Image Search instance is in the China (Shanghai) region, your ECS instance or resource must also be in the China (Shanghai) region to access the Image Search service using a VPC endpoint. Otherwise, the call will fail. If a call fails, check whether your ECS instance or resource is in the same region as the Image Search instance. # config.endpointType = 'internal' // If you access the Image Search service over an internal network, this parameter is required and must be set to 'internal'. # config.endpoint = 'imagesearch-vpc.<regionId>.aliyuncs.com' // This is the VPC endpoint. Replace with the region of your instance. For example, if your instance is in the China (Hangzhou) region, set the endpoint to 'imagesearch-vpc.cn-hangzhou.aliyuncs.com'. # Replace with the region of your instance. For example, if your instance is in the China (Hangzhou) region, set regionId to 'cn-hangzhou'. config.region_id = '<regionId>' config.type = 'access_key' client = Client(config) request = IncreaseListRequest() # Required. The name of the Image Search instance. Note that this is the instance name, not the instance ID. You can view the instance name in the instance information on the console after purchase: https://imagesearch.console.aliyun.com/overview request.instance_name = "xxxxxx" # Optional. The task ID. request.id = 567 # Optional. The OSS BucketName to query. request.bucket_name = "BucketName" # Optional. The OSS path to query. request.path = "/localization/xxxx" # Optional. The starting position of the results. Default value: 1. request.page_number = 1 # Optional. The number of results to return. 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' }
CompareSimilarByImage
-
Code example
from alibabacloud_imagesearch20201214.client import Client from alibabacloud_imagesearch20201214.models import CompareSimilarByImageAdvanceRequest from alibabacloud_tea_openapi.models import Config from alibabacloud_tea_util.models import RuntimeOptions def CompareSimilarByImage() : config = Config() # For information about how to create an AccessKey pair, see https://www.alibabacloud.com/help/en/ram/latest/create-an-accesskey-pair. # An AccessKey pair of an Alibaba Cloud account has full access permissions to all APIs. We recommend using a RAM user for API access and daily O&M. # We strongly recommend that you do not hard-code your AccessKey ID and AccessKey secret in your project code. Otherwise, your AccessKey pair may be leaked, which threatens the security of all your resources. # This example shows how to store the AccessKey ID and AccessKey secret in environment variables. You can also store them in a configuration file as needed. config.access_key_id = os.environ['CC_AK_ENV'] config.access_key_secret = os.environ['CC_SK_ENV'] # Replace with the region of your instance. For example, if your instance is in the China (Hangzhou) region, set the endpoint to 'imagesearch.cn-hangzhou.aliyuncs.com'. config.endpoint = 'imagesearch.<regionId>.aliyuncs.com' # The following code shows how to access the service over an internal network (VPC). # Note: You can access the service over an internal network (VPC) only from an ECS instance or resource in the same region. For example, if your Image Search instance is in the China (Shanghai) region, your ECS instance or resource must also be in the China (Shanghai) region to access the Image Search service using a VPC endpoint. Otherwise, the call will fail. If a call fails, check whether your ECS instance or resource is in the same region as the Image Search instance. # config.endpointType = 'internal' // If you access the Image Search service over an internal network, this parameter is required and must be set to 'internal'. # config.endpoint = 'imagesearch-vpc.<regionId>.aliyuncs.com' // This is the VPC endpoint. Replace with the region of your instance. For example, if your instance is in the China (Hangzhou) region, set the endpoint to 'imagesearch-vpc.cn-hangzhou.aliyuncs.com'. # Replace with the region of your instance. For example, if your instance is in the China (Hangzhou) region, set regionId to 'cn-hangzhou'. config.region_id = '<regionId>' config.type = 'access_key' client = Client(config) request = CompareSimilarByImageAdvanceRequest() # To use a URL, uncomment the following lines. # url1 = '<fileUrl1>' # f1 = BytesIO(requests.get(url1).content) # url2 = '<fileUrl2>' # f2 = BytesIO(requests.get(url2).content) f1 = open('D:/1.jpg', 'rb') f2 = open('D:/2.jpg', 'rb') request.primary_pic_content_object = f1 request.secondary_pic_content_object = f2 # Required. The name of the Image Search instance. Note that this is the instance name, not the instance ID. You can view the instance name in the instance information on the console after purchase: https://imagesearch.console.aliyun.com/overview request.instance_name = "xxxxxx" response = client.compare_similar_by_image_advance(request) print(response.body.to_map()) if __name__ == '__main__': CompareSimilarByImage() -
Sample response
{ "headers": { "date": "Fri, 14 Feb 2025 08:02:22 GMT", "content-type": "application/json;charset=utf-8", "content-length": "104", "connection": "keep-alive", "keep-alive": "timeout=25", "access-control-allow-origin": "*", "access-control-expose-headers": "*", "x-acs-request-id": "B278B248-A140-5277-8318-37D972B56AA2", "x-acs-trace-id": "eb8cfd86c431ad06a1853cdb4fd54dad", "etag": "1+z5NVLh9r/ubmCpqKfjPHw4" }, "statusCode": 200, "body": { "Code": 0, "Msg": "success", "RequestId": "B278B248-A140-5277-8318-37D972B56AA2", "Score": 1.0, "Success": true } }
CheckImageExists
-
Code example
from alibabacloud_imagesearch20201214.client import Client from alibabacloud_imagesearch20201214.models import CheckImageExistsRequest from alibabacloud_tea_openapi.models import Config import os def checkImageExists(): request = CheckImageExistsRequest() # Required. The name of the Image Search instance. Note that this is the instance name, not the instance ID. You can view the instance name in the instance information on the console after purchase: https://imagesearch.console.aliyun.com/overview request.instance_name = '<instanceName>' # Required. The product ID. The ID can be up to 256 characters long. # A product can have multiple images. request.product_id = '1' # Required. The image name. The name can be up to 256 characters long. # 1. The combination of ProductId and PicName uniquely identifies an image. # 2. If you add an image with the same ProductId and PicName multiple times, the last added image overwrites the previous ones. request.pic_name = '1' config = Config() # For information about how to create an AccessKey pair, see https://www.alibabacloud.com/help/en/ram/latest/create-an-accesskey-pair. # An AccessKey pair of an Alibaba Cloud account has full access permissions to all APIs. We recommend using a RAM user for API access and daily O&M. # We strongly recommend that you do not hard-code your AccessKey ID and AccessKey secret in your project code. Otherwise, your AccessKey pair may be leaked, which threatens the security of all your resources. # This example shows how to store the AccessKey ID and AccessKey secret in environment variables. You can also store them in a configuration file as needed. config.access_key_id = os.environ['CC_AK_ENV'] config.access_key_secret = os.environ['CC_SK_ENV'] # Replace with the region of your instance. For example, if your instance is in the China (Hangzhou) region, set the endpoint to 'imagesearch.cn-hangzhou.aliyuncs.com'. config.endpoint = 'imagesearch.<regionId>.aliyuncs.com' # The following code shows how to access the service over an internal network (VPC). # Note: You can access the service over an internal network (VPC) only from an ECS instance or resource in the same region. For example, if your Image Search instance is in the China (Shanghai) region, your ECS instance or resource must also be in the China (Shanghai) region to access the Image Search service using a VPC endpoint. Otherwise, the call will fail. If a call fails, check whether your ECS instance or resource is in the same region as the Image Search instance. # config.endpointType = 'internal' // If you access the Image Search service over an internal network, this parameter is required and must be set to 'internal'. # This is the VPC endpoint. Replace with the region of your instance. For example, if your instance is in the China (Hangzhou) region, set the endpoint to 'imagesearch-vpc.cn-hangzhou.aliyuncs.com'. # config.endpoint = 'imagesearch-vpc.<regionId>.aliyuncs.com' # Replace with the region of your instance. For example, if your instance is in the China (Hangzhou) region, set regionId to 'cn-hangzhou'. config.region_id = '<regionId>' config.type = 'access_key' client = Client(config) response = client.check_image_exists(request) print(response.to_map()) if __name__ == '__main__': checkImageExists() -
Sample response
{ 'statusCode': 200, 'body': { 'Auctions': { 'CategoryId': 4, 'PicName': '1', 'ProductId': '1' }, 'Code': 0, 'Exists': True, 'Msg': 'success', 'RequestId': 'xxx-7901-13E5-A84F-xxxx', 'Success': True } }