On January 1, 2020 this library will no longer support Python 2 on the latest released version. Previously released library versions will continue to be available. For more information please visit Python 2 support on Google Cloud.

Client for Cloud Vision API

class google.cloud.vision_v1.ImageAnnotatorClient(transport=None, channel=None, credentials=None, client_config=None, client_info=None, client_options=None)[source]

Service that performs Google Cloud Vision API detection tasks over client images, such as face, landmark, logo, label, and text detection. The ImageAnnotator service returns detected entities from the images.

Constructor.

Parameters
  • (Union[ImageAnnotatorGrpcTransport, (transport) – Callable[[~.Credentials, type], ~.ImageAnnotatorGrpcTransport]): A transport instance, responsible for actually making the API calls. The default transport uses the gRPC protocol. This argument may also be a callable which returns a transport instance. Callables will be sent the credentials as the first argument and the default transport class as the second argument.

  • channel (grpc.Channel) – DEPRECATED. A Channel instance through which to make calls. This argument is mutually exclusive with credentials; providing both will raise an exception.

  • credentials (google.auth.credentials.Credentials) – The authorization credentials to attach to requests. These credentials identify this application to the service. If none are specified, the client will attempt to ascertain the credentials from the environment. This argument is mutually exclusive with providing a transport instance to transport; doing so will raise an exception.

  • client_config (dict) – DEPRECATED. A dictionary of call options for each method. If not specified, the default configuration is used.

  • client_info (google.api_core.gapic_v1.client_info.ClientInfo) – The client info used to send a user-agent string along with API requests. If None, then default info will be used. Generally, you only need to set this if you’re developing your own client library.

  • client_options (Union[dict, google.api_core.client_options.ClientOptions]) – Client options used to set user options on the client. API Endpoint should be set through client_options.

annotate_image(request, retry=None, timeout=None)

Run image detection and annotation for an image.

Example

>>> from google.cloud.vision_v1 import ImageAnnotatorClient
>>> client = ImageAnnotatorClient()
>>> request = {
...     'image': {
...         'source': {'image_uri': 'https://foo.com/image.jpg'},
...     },
... }
>>> response = client.annotate_image(request)
Parameters
  • request (AnnotateImageRequest) –

  • retry (Optional[google.api_core.retry.Retry]) – A retry object used to retry requests. If None is specified, requests will not be retried.

  • timeout (Optional[float]) – The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.

Returns

AnnotateImageResponse The API response.

async_batch_annotate_files(requests, parent=None, retry=<object object>, timeout=<object object>, metadata=None)[source]

Run asynchronous image detection and annotation for a list of generic files, such as PDF files, which may contain multiple pages and multiple images per page. Progress and results can be retrieved through the google.longrunning.Operations interface. Operation.metadata contains OperationMetadata (metadata). Operation.response contains AsyncBatchAnnotateFilesResponse (results).

Example

>>> from google.cloud import vision_v1
>>>
>>> client = vision_v1.ImageAnnotatorClient()
>>>
>>> # TODO: Initialize `requests`:
>>> requests = []
>>>
>>> response = client.async_batch_annotate_files(requests)
>>>
>>> def callback(operation_future):
...     # Handle result.
...     result = operation_future.result()
>>>
>>> response.add_done_callback(callback)
>>>
>>> # Handle metadata.
>>> metadata = response.metadata()
Parameters
  • requests (list[Union[dict, AsyncAnnotateFileRequest]]) –

    Required. Individual async file annotation requests for this batch.

    If a dict is provided, it must be of the same form as the protobuf message AsyncAnnotateFileRequest

  • parent (str) –

    Optional. Target project and location to make a call.

    Format: projects/{project-id}/locations/{location-id}.

    If no parent is specified, a region will be chosen automatically.

    Supported location-ids: us: USA country only, asia: East asia areas, like Japan, Taiwan, eu: The European Union.

    Example: projects/project-A/locations/eu.

  • retry (Optional[google.api_core.retry.Retry]) – A retry object used to retry requests. If None is specified, requests will be retried using a default configuration.

  • timeout (Optional[float]) – The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.

  • metadata (Optional[Sequence[Tuple[str, str]]]) – Additional metadata that is provided to the method.

Returns

A _OperationFuture instance.

Raises
async_batch_annotate_images(requests, output_config, parent=None, retry=<object object>, timeout=<object object>, metadata=None)[source]

Run asynchronous image detection and annotation for a list of images.

Progress and results can be retrieved through the google.longrunning.Operations interface. Operation.metadata contains OperationMetadata (metadata). Operation.response contains AsyncBatchAnnotateImagesResponse (results).

This service will write image annotation outputs to json files in customer GCS bucket, each json file containing BatchAnnotateImagesResponse proto.

Example

>>> from google.cloud import vision_v1
>>>
>>> client = vision_v1.ImageAnnotatorClient()
>>>
>>> # TODO: Initialize `requests`:
>>> requests = []
>>>
>>> # TODO: Initialize `output_config`:
>>> output_config = {}
>>>
>>> response = client.async_batch_annotate_images(requests, output_config)
>>>
>>> def callback(operation_future):
...     # Handle result.
...     result = operation_future.result()
>>>
>>> response.add_done_callback(callback)
>>>
>>> # Handle metadata.
>>> metadata = response.metadata()
Parameters
  • requests (list[Union[dict, AnnotateImageRequest]]) –

    Required. Individual image annotation requests for this batch.

    If a dict is provided, it must be of the same form as the protobuf message AnnotateImageRequest

  • output_config (Union[dict, OutputConfig]) –

    Required. The desired output location and metadata (e.g. format).

    If a dict is provided, it must be of the same form as the protobuf message OutputConfig

  • parent (str) –

    Optional. Target project and location to make a call.

    Format: projects/{project-id}/locations/{location-id}.

    If no parent is specified, a region will be chosen automatically.

    Supported location-ids: us: USA country only, asia: East asia areas, like Japan, Taiwan, eu: The European Union.

    Example: projects/project-A/locations/eu.

  • retry (Optional[google.api_core.retry.Retry]) – A retry object used to retry requests. If None is specified, requests will be retried using a default configuration.

  • timeout (Optional[float]) – The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.

  • metadata (Optional[Sequence[Tuple[str, str]]]) – Additional metadata that is provided to the method.

Returns

A _OperationFuture instance.

Raises
batch_annotate_files(requests, parent=None, retry=<object object>, timeout=<object object>, metadata=None)[source]

Service that performs image detection and annotation for a batch of files. Now only “application/pdf”, “image/tiff” and “image/gif” are supported.

This service will extract at most 5 (customers can specify which 5 in AnnotateFileRequest.pages) frames (gif) or pages (pdf or tiff) from each file provided and perform detection and annotation for each image extracted.

Example

>>> from google.cloud import vision_v1
>>>
>>> client = vision_v1.ImageAnnotatorClient()
>>>
>>> # TODO: Initialize `requests`:
>>> requests = []
>>>
>>> response = client.batch_annotate_files(requests)
Parameters
  • requests (list[Union[dict, AnnotateFileRequest]]) –

    Required. The list of file annotation requests. Right now we support only one AnnotateFileRequest in BatchAnnotateFilesRequest.

    If a dict is provided, it must be of the same form as the protobuf message AnnotateFileRequest

  • parent (str) –

    Optional. Target project and location to make a call.

    Format: projects/{project-id}/locations/{location-id}.

    If no parent is specified, a region will be chosen automatically.

    Supported location-ids: us: USA country only, asia: East asia areas, like Japan, Taiwan, eu: The European Union.

    Example: projects/project-A/locations/eu.

  • retry (Optional[google.api_core.retry.Retry]) – A retry object used to retry requests. If None is specified, requests will be retried using a default configuration.

  • timeout (Optional[float]) – The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.

  • metadata (Optional[Sequence[Tuple[str, str]]]) – Additional metadata that is provided to the method.

Returns

A BatchAnnotateFilesResponse instance.

Raises
batch_annotate_images(requests, parent=None, retry=<object object>, timeout=<object object>, metadata=None)[source]

Run image detection and annotation for a batch of images.

Example

>>> from google.cloud import vision_v1
>>>
>>> client = vision_v1.ImageAnnotatorClient()
>>>
>>> # TODO: Initialize `requests`:
>>> requests = []
>>>
>>> response = client.batch_annotate_images(requests)
Parameters
  • requests (list[Union[dict, AnnotateImageRequest]]) –

    Required. Individual image annotation requests for this batch.

    If a dict is provided, it must be of the same form as the protobuf message AnnotateImageRequest

  • parent (str) –

    Optional. Target project and location to make a call.

    Format: projects/{project-id}/locations/{location-id}.

    If no parent is specified, a region will be chosen automatically.

    Supported location-ids: us: USA country only, asia: East asia areas, like Japan, Taiwan, eu: The European Union.

    Example: projects/project-A/locations/eu.

  • retry (Optional[google.api_core.retry.Retry]) – A retry object used to retry requests. If None is specified, requests will be retried using a default configuration.

  • timeout (Optional[float]) – The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.

  • metadata (Optional[Sequence[Tuple[str, str]]]) – Additional metadata that is provided to the method.

Returns

A BatchAnnotateImagesResponse instance.

Raises
crop_hints(image, max_results=None, retry=None, timeout=None, **kwargs)

Return crop hints information.

Parameters
  • image (Image) – The image to analyze.

  • max_results (int) – Number of results to return, does not apply for TEXT_DETECTION, DOCUMENT_TEXT_DETECTION, or CROP_HINTS.

  • retry (int) – Number of retries to do before giving up.

  • timeout (int) – Number of seconds before timing out.

  • kwargs (dict) – Additional properties to be set on the AnnotateImageRequest.

Returns

The API response.

Return type

AnnotateImageResponse

document_text_detection(image, max_results=None, retry=None, timeout=None, **kwargs)

Perform document text detection.

Parameters
  • image (Image) – The image to analyze.

  • max_results (int) – Number of results to return, does not apply for TEXT_DETECTION, DOCUMENT_TEXT_DETECTION, or CROP_HINTS.

  • retry (int) – Number of retries to do before giving up.

  • timeout (int) – Number of seconds before timing out.

  • kwargs (dict) – Additional properties to be set on the AnnotateImageRequest.

Returns

The API response.

Return type

AnnotateImageResponse

enums = <module 'google.cloud.vision_v1.gapic.enums' from '/tmpfs/src/github/google-cloud-python/vision/google/cloud/vision_v1/gapic/enums.py'>
face_detection(image, max_results=None, retry=None, timeout=None, **kwargs)

Perform face detection.

Parameters
  • image (Image) – The image to analyze.

  • max_results (int) – Number of results to return, does not apply for TEXT_DETECTION, DOCUMENT_TEXT_DETECTION, or CROP_HINTS.

  • retry (int) – Number of retries to do before giving up.

  • timeout (int) – Number of seconds before timing out.

  • kwargs (dict) – Additional properties to be set on the AnnotateImageRequest.

Returns

The API response.

Return type

AnnotateImageResponse

classmethod from_service_account_file(filename, *args, **kwargs)[source]

Creates an instance of this client using the provided credentials file.

Parameters
  • filename (str) – The path to the service account private key json file.

  • args – Additional arguments to pass to the constructor.

  • kwargs – Additional arguments to pass to the constructor.

Returns

The constructed client.

Return type

ImageAnnotatorClient

classmethod from_service_account_json(filename, *args, **kwargs)

Creates an instance of this client using the provided credentials file.

Parameters
  • filename (str) – The path to the service account private key json file.

  • args – Additional arguments to pass to the constructor.

  • kwargs – Additional arguments to pass to the constructor.

Returns

The constructed client.

Return type

ImageAnnotatorClient

image_properties(image, max_results=None, retry=None, timeout=None, **kwargs)

Return image properties information.

Parameters
  • image (Image) – The image to analyze.

  • max_results (int) – Number of results to return, does not apply for TEXT_DETECTION, DOCUMENT_TEXT_DETECTION, or CROP_HINTS.

  • retry (int) – Number of retries to do before giving up.

  • timeout (int) – Number of seconds before timing out.

  • kwargs (dict) – Additional properties to be set on the AnnotateImageRequest.

Returns

The API response.

Return type

AnnotateImageResponse

label_detection(image, max_results=None, retry=None, timeout=None, **kwargs)

Perform label detection.

Parameters
  • image (Image) – The image to analyze.

  • max_results (int) – Number of results to return, does not apply for TEXT_DETECTION, DOCUMENT_TEXT_DETECTION, or CROP_HINTS.

  • retry (int) – Number of retries to do before giving up.

  • timeout (int) – Number of seconds before timing out.

  • kwargs (dict) – Additional properties to be set on the AnnotateImageRequest.

Returns

The API response.

Return type

AnnotateImageResponse

landmark_detection(image, max_results=None, retry=None, timeout=None, **kwargs)

Perform landmark detection.

Parameters
  • image (Image) – The image to analyze.

  • max_results (int) – Number of results to return, does not apply for TEXT_DETECTION, DOCUMENT_TEXT_DETECTION, or CROP_HINTS.

  • retry (int) – Number of retries to do before giving up.

  • timeout (int) – Number of seconds before timing out.

  • kwargs (dict) – Additional properties to be set on the AnnotateImageRequest.

Returns

The API response.

Return type

AnnotateImageResponse

logo_detection(image, max_results=None, retry=None, timeout=None, **kwargs)

Perform logo detection.

Parameters
  • image (Image) – The image to analyze.

  • max_results (int) – Number of results to return, does not apply for TEXT_DETECTION, DOCUMENT_TEXT_DETECTION, or CROP_HINTS.

  • retry (int) – Number of retries to do before giving up.

  • timeout (int) – Number of seconds before timing out.

  • kwargs (dict) – Additional properties to be set on the AnnotateImageRequest.

Returns

The API response.

Return type

AnnotateImageResponse

object_localization(image, max_results=None, retry=None, timeout=None, **kwargs)

Return object localization information.

Parameters
  • image (Image) – The image to analyze.

  • max_results (int) – Number of results to return, does not apply for TEXT_DETECTION, DOCUMENT_TEXT_DETECTION, or CROP_HINTS.

  • retry (int) – Number of retries to do before giving up.

  • timeout (int) – Number of seconds before timing out.

  • kwargs (dict) – Additional properties to be set on the AnnotateImageRequest.

Returns

The API response.

Return type

AnnotateImageResponse

Return product search information.

Parameters
  • image (Image) – The image to analyze.

  • max_results (int) – Number of results to return, does not apply for TEXT_DETECTION, DOCUMENT_TEXT_DETECTION, or CROP_HINTS.

  • retry (int) – Number of retries to do before giving up.

  • timeout (int) – Number of seconds before timing out.

  • kwargs (dict) – Additional properties to be set on the AnnotateImageRequest.

Returns

The API response.

Return type

AnnotateImageResponse

safe_search_detection(image, max_results=None, retry=None, timeout=None, **kwargs)

Perform safe search detection.

Parameters
  • image (Image) – The image to analyze.

  • max_results (int) – Number of results to return, does not apply for TEXT_DETECTION, DOCUMENT_TEXT_DETECTION, or CROP_HINTS.

  • retry (int) – Number of retries to do before giving up.

  • timeout (int) – Number of seconds before timing out.

  • kwargs (dict) – Additional properties to be set on the AnnotateImageRequest.

Returns

The API response.

Return type

AnnotateImageResponse

text_detection(image, max_results=None, retry=None, timeout=None, **kwargs)

Perform text detection.

Parameters
  • image (Image) – The image to analyze.

  • max_results (int) – Number of results to return, does not apply for TEXT_DETECTION, DOCUMENT_TEXT_DETECTION, or CROP_HINTS.

  • retry (int) – Number of retries to do before giving up.

  • timeout (int) – Number of seconds before timing out.

  • kwargs (dict) – Additional properties to be set on the AnnotateImageRequest.

Returns

The API response.

Return type

AnnotateImageResponse

web_detection(image, max_results=None, retry=None, timeout=None, **kwargs)

Perform web detection.

Parameters
  • image (Image) – The image to analyze.

  • max_results (int) – Number of results to return, does not apply for TEXT_DETECTION, DOCUMENT_TEXT_DETECTION, or CROP_HINTS.

  • retry (int) – Number of retries to do before giving up.

  • timeout (int) – Number of seconds before timing out.

  • kwargs (dict) – Additional properties to be set on the AnnotateImageRequest.

Returns

The API response.

Return type

AnnotateImageResponse

class google.cloud.vision_v1.ProductSearchClient(transport=None, channel=None, credentials=None, client_config=None, client_info=None, client_options=None)[source]

Manages Products and ProductSets of reference images for use in product search. It uses the following resource model:

  • The API has a collection of ProductSet resources, named projects/*/locations/*/productSets/*, which acts as a way to put different products into groups to limit identification.

In parallel,

  • The API has a collection of Product resources, named projects/*/locations/*/products/*

  • Each Product has a collection of ReferenceImage resources, named projects/*/locations/*/products/*/referenceImages/*

Constructor.

Parameters
  • (Union[ProductSearchGrpcTransport, (transport) – Callable[[~.Credentials, type], ~.ProductSearchGrpcTransport]): A transport instance, responsible for actually making the API calls. The default transport uses the gRPC protocol. This argument may also be a callable which returns a transport instance. Callables will be sent the credentials as the first argument and the default transport class as the second argument.

  • channel (grpc.Channel) – DEPRECATED. A Channel instance through which to make calls. This argument is mutually exclusive with credentials; providing both will raise an exception.

  • credentials (google.auth.credentials.Credentials) – The authorization credentials to attach to requests. These credentials identify this application to the service. If none are specified, the client will attempt to ascertain the credentials from the environment. This argument is mutually exclusive with providing a transport instance to transport; doing so will raise an exception.

  • client_config (dict) – DEPRECATED. A dictionary of call options for each method. If not specified, the default configuration is used.

  • client_info (google.api_core.gapic_v1.client_info.ClientInfo) – The client info used to send a user-agent string along with API requests. If None, then default info will be used. Generally, you only need to set this if you’re developing your own client library.

  • client_options (Union[dict, google.api_core.client_options.ClientOptions]) – Client options used to set user options on the client. API Endpoint should be set through client_options.

add_product_to_product_set(name, product, retry=<object object>, timeout=<object object>, metadata=None)[source]

Adds a Product to the specified ProductSet. If the Product is already present, no change is made.

One Product can be added to at most 100 ProductSets.

Possible errors:

  • Returns NOT_FOUND if the Product or the ProductSet doesn’t exist.

Example

>>> from google.cloud import vision_v1
>>>
>>> client = vision_v1.ProductSearchClient()
>>>
>>> name = client.product_set_path('[PROJECT]', '[LOCATION]', '[PRODUCT_SET]')
>>> product = client.product_path('[PROJECT]', '[LOCATION]', '[PRODUCT]')
>>>
>>> client.add_product_to_product_set(name, product)
Parameters
  • name (str) –

    Required. The resource name for the ProductSet to modify.

    Format is: projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID

  • product (str) –

    Required. The resource name for the Product to be added to this ProductSet.

    Format is: projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID

  • retry (Optional[google.api_core.retry.Retry]) – A retry object used to retry requests. If None is specified, requests will be retried using a default configuration.

  • timeout (Optional[float]) – The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.

  • metadata (Optional[Sequence[Tuple[str, str]]]) – Additional metadata that is provided to the method.

Raises
create_product(parent, product, product_id=None, retry=<object object>, timeout=<object object>, metadata=None)[source]

Creates and returns a new product resource.

Possible errors:

  • Returns INVALID_ARGUMENT if display_name is missing or longer than 4096 characters.

  • Returns INVALID_ARGUMENT if description is longer than 4096 characters.

  • Returns INVALID_ARGUMENT if product_category is missing or invalid.

Example

>>> from google.cloud import vision_v1
>>>
>>> client = vision_v1.ProductSearchClient()
>>>
>>> parent = client.location_path('[PROJECT]', '[LOCATION]')
>>>
>>> # TODO: Initialize `product`:
>>> product = {}
>>>
>>> response = client.create_product(parent, product)
Parameters
  • parent (str) –

    Required. The project in which the Product should be created.

    Format is projects/PROJECT_ID/locations/LOC_ID.

  • product (Union[dict, Product]) –

    Required. The product to create.

    If a dict is provided, it must be of the same form as the protobuf message Product

  • product_id (str) – A user-supplied resource id for this Product. If set, the server will attempt to use this value as the resource id. If it is already in use, an error is returned with code ALREADY_EXISTS. Must be at most 128 characters long. It cannot contain the character /.

  • retry (Optional[google.api_core.retry.Retry]) – A retry object used to retry requests. If None is specified, requests will be retried using a default configuration.

  • timeout (Optional[float]) – The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.

  • metadata (Optional[Sequence[Tuple[str, str]]]) – Additional metadata that is provided to the method.

Returns

A Product instance.

Raises
create_product_set(parent, product_set, product_set_id=None, retry=<object object>, timeout=<object object>, metadata=None)[source]

Creates and returns a new ProductSet resource.

Possible errors:

  • Returns INVALID_ARGUMENT if display_name is missing, or is longer than 4096 characters.

Example

>>> from google.cloud import vision_v1
>>>
>>> client = vision_v1.ProductSearchClient()
>>>
>>> parent = client.location_path('[PROJECT]', '[LOCATION]')
>>>
>>> # TODO: Initialize `product_set`:
>>> product_set = {}
>>>
>>> response = client.create_product_set(parent, product_set)
Parameters
  • parent (str) –

    Required. The project in which the ProductSet should be created.

    Format is projects/PROJECT_ID/locations/LOC_ID.

  • product_set (Union[dict, ProductSet]) –

    Required. The ProductSet to create.

    If a dict is provided, it must be of the same form as the protobuf message ProductSet

  • product_set_id (str) – A user-supplied resource id for this ProductSet. If set, the server will attempt to use this value as the resource id. If it is already in use, an error is returned with code ALREADY_EXISTS. Must be at most 128 characters long. It cannot contain the character /.

  • retry (Optional[google.api_core.retry.Retry]) – A retry object used to retry requests. If None is specified, requests will be retried using a default configuration.

  • timeout (Optional[float]) – The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.

  • metadata (Optional[Sequence[Tuple[str, str]]]) – Additional metadata that is provided to the method.

Returns

A ProductSet instance.

Raises
create_reference_image(parent, reference_image, reference_image_id=None, retry=<object object>, timeout=<object object>, metadata=None)[source]

Creates and returns a new ReferenceImage resource.

The bounding_poly field is optional. If bounding_poly is not specified, the system will try to detect regions of interest in the image that are compatible with the product_category on the parent product. If it is specified, detection is ALWAYS skipped. The system converts polygons into non-rotated rectangles.

Note that the pipeline will resize the image if the image resolution is too large to process (above 50MP).

Possible errors:

  • Returns INVALID_ARGUMENT if the image_uri is missing or longer than 4096 characters.

  • Returns INVALID_ARGUMENT if the product does not exist.

  • Returns INVALID_ARGUMENT if bounding_poly is not provided, and nothing compatible with the parent product’s product_category is detected.

  • Returns INVALID_ARGUMENT if bounding_poly contains more than 10 polygons.

Example

>>> from google.cloud import vision_v1
>>>
>>> client = vision_v1.ProductSearchClient()
>>>
>>> parent = client.product_path('[PROJECT]', '[LOCATION]', '[PRODUCT]')
>>>
>>> # TODO: Initialize `reference_image`:
>>> reference_image = {}
>>>
>>> response = client.create_reference_image(parent, reference_image)
Parameters
  • parent (str) –

    Required. Resource name of the product in which to create the reference image.

    Format is projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID.

  • reference_image (Union[dict, ReferenceImage]) –

    Required. The reference image to create. If an image ID is specified, it is ignored.

    If a dict is provided, it must be of the same form as the protobuf message ReferenceImage

  • reference_image_id (str) – A user-supplied resource id for the ReferenceImage to be added. If set, the server will attempt to use this value as the resource id. If it is already in use, an error is returned with code ALREADY_EXISTS. Must be at most 128 characters long. It cannot contain the character /.

  • retry (Optional[google.api_core.retry.Retry]) – A retry object used to retry requests. If None is specified, requests will be retried using a default configuration.

  • timeout (Optional[float]) – The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.

  • metadata (Optional[Sequence[Tuple[str, str]]]) – Additional metadata that is provided to the method.

Returns

A ReferenceImage instance.

Raises
delete_product(name, retry=<object object>, timeout=<object object>, metadata=None)[source]

Permanently deletes a product and its reference images.

Metadata of the product and all its images will be deleted right away, but search queries against ProductSets containing the product may still work until all related caches are refreshed.

Example

>>> from google.cloud import vision_v1
>>>
>>> client = vision_v1.ProductSearchClient()
>>>
>>> name = client.product_path('[PROJECT]', '[LOCATION]', '[PRODUCT]')
>>>
>>> client.delete_product(name)
Parameters
  • name (str) –

    Required. Resource name of product to delete.

    Format is: projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID

  • retry (Optional[google.api_core.retry.Retry]) – A retry object used to retry requests. If None is specified, requests will be retried using a default configuration.

  • timeout (Optional[float]) – The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.

  • metadata (Optional[Sequence[Tuple[str, str]]]) – Additional metadata that is provided to the method.

Raises
delete_product_set(name, retry=<object object>, timeout=<object object>, metadata=None)[source]

Permanently deletes a ProductSet. Products and ReferenceImages in the ProductSet are not deleted.

The actual image files are not deleted from Google Cloud Storage.

Example

>>> from google.cloud import vision_v1
>>>
>>> client = vision_v1.ProductSearchClient()
>>>
>>> name = client.product_set_path('[PROJECT]', '[LOCATION]', '[PRODUCT_SET]')
>>>
>>> client.delete_product_set(name)
Parameters
  • name (str) –

    Required. Resource name of the ProductSet to delete.

    Format is: projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID

  • retry (Optional[google.api_core.retry.Retry]) – A retry object used to retry requests. If None is specified, requests will be retried using a default configuration.

  • timeout (Optional[float]) – The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.

  • metadata (Optional[Sequence[Tuple[str, str]]]) – Additional metadata that is provided to the method.

Raises
delete_reference_image(name, retry=<object object>, timeout=<object object>, metadata=None)[source]

Permanently deletes a reference image.

The image metadata will be deleted right away, but search queries against ProductSets containing the image may still work until all related caches are refreshed.

The actual image files are not deleted from Google Cloud Storage.

Example

>>> from google.cloud import vision_v1
>>>
>>> client = vision_v1.ProductSearchClient()
>>>
>>> name = client.reference_image_path('[PROJECT]', '[LOCATION]', '[PRODUCT]', '[REFERENCE_IMAGE]')
>>>
>>> client.delete_reference_image(name)
Parameters
  • name (str) –

    Required. The resource name of the reference image to delete.

    Format is:

    projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID/referenceImages/IMAGE_ID

  • retry (Optional[google.api_core.retry.Retry]) – A retry object used to retry requests. If None is specified, requests will be retried using a default configuration.

  • timeout (Optional[float]) – The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.

  • metadata (Optional[Sequence[Tuple[str, str]]]) – Additional metadata that is provided to the method.

Raises
enums = <module 'google.cloud.vision_v1.gapic.enums' from '/tmpfs/src/github/google-cloud-python/vision/google/cloud/vision_v1/gapic/enums.py'>
classmethod from_service_account_file(filename, *args, **kwargs)[source]

Creates an instance of this client using the provided credentials file.

Parameters
  • filename (str) – The path to the service account private key json file.

  • args – Additional arguments to pass to the constructor.

  • kwargs – Additional arguments to pass to the constructor.

Returns

The constructed client.

Return type

ProductSearchClient

classmethod from_service_account_json(filename, *args, **kwargs)

Creates an instance of this client using the provided credentials file.

Parameters
  • filename (str) – The path to the service account private key json file.

  • args – Additional arguments to pass to the constructor.

  • kwargs – Additional arguments to pass to the constructor.

Returns

The constructed client.

Return type

ProductSearchClient

get_product(name, retry=<object object>, timeout=<object object>, metadata=None)[source]

Gets information associated with a Product.

Possible errors:

  • Returns NOT_FOUND if the Product does not exist.

Example

>>> from google.cloud import vision_v1
>>>
>>> client = vision_v1.ProductSearchClient()
>>>
>>> name = client.product_path('[PROJECT]', '[LOCATION]', '[PRODUCT]')
>>>
>>> response = client.get_product(name)
Parameters
  • name (str) –

    Required. Resource name of the Product to get.

    Format is: projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID

  • retry (Optional[google.api_core.retry.Retry]) – A retry object used to retry requests. If None is specified, requests will be retried using a default configuration.

  • timeout (Optional[float]) – The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.

  • metadata (Optional[Sequence[Tuple[str, str]]]) – Additional metadata that is provided to the method.

Returns

A Product instance.

Raises
get_product_set(name, retry=<object object>, timeout=<object object>, metadata=None)[source]

Gets information associated with a ProductSet.

Possible errors:

  • Returns NOT_FOUND if the ProductSet does not exist.

Example

>>> from google.cloud import vision_v1
>>>
>>> client = vision_v1.ProductSearchClient()
>>>
>>> name = client.product_set_path('[PROJECT]', '[LOCATION]', '[PRODUCT_SET]')
>>>
>>> response = client.get_product_set(name)
Parameters
  • name (str) –

    Required. Resource name of the ProductSet to get.

    Format is: projects/PROJECT_ID/locations/LOG_ID/productSets/PRODUCT_SET_ID

  • retry (Optional[google.api_core.retry.Retry]) – A retry object used to retry requests. If None is specified, requests will be retried using a default configuration.

  • timeout (Optional[float]) – The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.

  • metadata (Optional[Sequence[Tuple[str, str]]]) – Additional metadata that is provided to the method.

Returns

A ProductSet instance.

Raises
get_reference_image(name, retry=<object object>, timeout=<object object>, metadata=None)[source]

Gets information associated with a ReferenceImage.

Possible errors:

  • Returns NOT_FOUND if the specified image does not exist.

Example

>>> from google.cloud import vision_v1
>>>
>>> client = vision_v1.ProductSearchClient()
>>>
>>> name = client.reference_image_path('[PROJECT]', '[LOCATION]', '[PRODUCT]', '[REFERENCE_IMAGE]')
>>>
>>> response = client.get_reference_image(name)
Parameters
  • name (str) –

    Required. The resource name of the ReferenceImage to get.

    Format is:

    projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID/referenceImages/IMAGE_ID.

  • retry (Optional[google.api_core.retry.Retry]) – A retry object used to retry requests. If None is specified, requests will be retried using a default configuration.

  • timeout (Optional[float]) – The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.

  • metadata (Optional[Sequence[Tuple[str, str]]]) – Additional metadata that is provided to the method.

Returns

A ReferenceImage instance.

Raises
import_product_sets(parent, input_config, retry=<object object>, timeout=<object object>, metadata=None)[source]

Asynchronous API that imports a list of reference images to specified product sets based on a list of image information.

The google.longrunning.Operation API can be used to keep track of the progress and results of the request. Operation.metadata contains BatchOperationMetadata. (progress) Operation.response contains ImportProductSetsResponse. (results)

The input source of this method is a csv file on Google Cloud Storage. For the format of the csv file please see ImportProductSetsGcsSource.csv_file_uri.

Example

>>> from google.cloud import vision_v1
>>>
>>> client = vision_v1.ProductSearchClient()
>>>
>>> parent = client.location_path('[PROJECT]', '[LOCATION]')
>>>
>>> # TODO: Initialize `input_config`:
>>> input_config = {}
>>>
>>> response = client.import_product_sets(parent, input_config)
>>>
>>> def callback(operation_future):
...     # Handle result.
...     result = operation_future.result()
>>>
>>> response.add_done_callback(callback)
>>>
>>> # Handle metadata.
>>> metadata = response.metadata()
Parameters
  • parent (str) –

    Required. The project in which the ProductSets should be imported.

    Format is projects/PROJECT_ID/locations/LOC_ID.

  • input_config (Union[dict, ImportProductSetsInputConfig]) –

    Required. The input content for the list of requests.

    If a dict is provided, it must be of the same form as the protobuf message ImportProductSetsInputConfig

  • retry (Optional[google.api_core.retry.Retry]) – A retry object used to retry requests. If None is specified, requests will be retried using a default configuration.

  • timeout (Optional[float]) – The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.

  • metadata (Optional[Sequence[Tuple[str, str]]]) – Additional metadata that is provided to the method.

Returns

A _OperationFuture instance.

Raises
list_product_sets(parent, page_size=None, retry=<object object>, timeout=<object object>, metadata=None)[source]

Lists ProductSets in an unspecified order.

Possible errors:

  • Returns INVALID_ARGUMENT if page_size is greater than 100, or less than 1.

Example

>>> from google.cloud import vision_v1
>>>
>>> client = vision_v1.ProductSearchClient()
>>>
>>> parent = client.location_path('[PROJECT]', '[LOCATION]')
>>>
>>> # Iterate over all results
>>> for element in client.list_product_sets(parent):
...     # process element
...     pass
>>>
>>>
>>> # Alternatively:
>>>
>>> # Iterate over results one page at a time
>>> for page in client.list_product_sets(parent).pages:
...     for element in page:
...         # process element
...         pass
Parameters
  • parent (str) –

    Required. The project from which ProductSets should be listed.

    Format is projects/PROJECT_ID/locations/LOC_ID.

  • page_size (int) – The maximum number of resources contained in the underlying API response. If page streaming is performed per- resource, this parameter does not affect the return value. If page streaming is performed per-page, this determines the maximum number of resources in a page.

  • retry (Optional[google.api_core.retry.Retry]) – A retry object used to retry requests. If None is specified, requests will be retried using a default configuration.

  • timeout (Optional[float]) – The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.

  • metadata (Optional[Sequence[Tuple[str, str]]]) – Additional metadata that is provided to the method.

Returns

A PageIterator instance. An iterable of ProductSet instances. You can also iterate over the pages of the response using its pages property.

Raises
list_products(parent, page_size=None, retry=<object object>, timeout=<object object>, metadata=None)[source]

Lists products in an unspecified order.

Possible errors:

  • Returns INVALID_ARGUMENT if page_size is greater than 100 or less than 1.

Example

>>> from google.cloud import vision_v1
>>>
>>> client = vision_v1.ProductSearchClient()
>>>
>>> parent = client.location_path('[PROJECT]', '[LOCATION]')
>>>
>>> # Iterate over all results
>>> for element in client.list_products(parent):
...     # process element
...     pass
>>>
>>>
>>> # Alternatively:
>>>
>>> # Iterate over results one page at a time
>>> for page in client.list_products(parent).pages:
...     for element in page:
...         # process element
...         pass
Parameters
  • parent (str) –

    Required. The project OR ProductSet from which Products should be listed.

    Format: projects/PROJECT_ID/locations/LOC_ID

  • page_size (int) – The maximum number of resources contained in the underlying API response. If page streaming is performed per- resource, this parameter does not affect the return value. If page streaming is performed per-page, this determines the maximum number of resources in a page.

  • retry (Optional[google.api_core.retry.Retry]) – A retry object used to retry requests. If None is specified, requests will be retried using a default configuration.

  • timeout (Optional[float]) – The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.

  • metadata (Optional[Sequence[Tuple[str, str]]]) – Additional metadata that is provided to the method.

Returns

A PageIterator instance. An iterable of Product instances. You can also iterate over the pages of the response using its pages property.

Raises
list_products_in_product_set(name, page_size=None, retry=<object object>, timeout=<object object>, metadata=None)[source]

Lists the Products in a ProductSet, in an unspecified order. If the ProductSet does not exist, the products field of the response will be empty.

Possible errors:

  • Returns INVALID_ARGUMENT if page_size is greater than 100 or less than 1.

Example

>>> from google.cloud import vision_v1
>>>
>>> client = vision_v1.ProductSearchClient()
>>>
>>> name = client.product_set_path('[PROJECT]', '[LOCATION]', '[PRODUCT_SET]')
>>>
>>> # Iterate over all results
>>> for element in client.list_products_in_product_set(name):
...     # process element
...     pass
>>>
>>>
>>> # Alternatively:
>>>
>>> # Iterate over results one page at a time
>>> for page in client.list_products_in_product_set(name).pages:
...     for element in page:
...         # process element
...         pass
Parameters
  • name (str) –

    Required. The ProductSet resource for which to retrieve Products.

    Format is: projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID

  • page_size (int) – The maximum number of resources contained in the underlying API response. If page streaming is performed per- resource, this parameter does not affect the return value. If page streaming is performed per-page, this determines the maximum number of resources in a page.

  • retry (Optional[google.api_core.retry.Retry]) – A retry object used to retry requests. If None is specified, requests will be retried using a default configuration.

  • timeout (Optional[float]) – The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.

  • metadata (Optional[Sequence[Tuple[str, str]]]) – Additional metadata that is provided to the method.

Returns

A PageIterator instance. An iterable of Product instances. You can also iterate over the pages of the response using its pages property.

Raises
list_reference_images(parent, page_size=None, retry=<object object>, timeout=<object object>, metadata=None)[source]

Lists reference images.

Possible errors:

  • Returns NOT_FOUND if the parent product does not exist.

  • Returns INVALID_ARGUMENT if the page_size is greater than 100, or less than 1.

Example

>>> from google.cloud import vision_v1
>>>
>>> client = vision_v1.ProductSearchClient()
>>>
>>> parent = client.product_path('[PROJECT]', '[LOCATION]', '[PRODUCT]')
>>>
>>> # Iterate over all results
>>> for element in client.list_reference_images(parent):
...     # process element
...     pass
>>>
>>>
>>> # Alternatively:
>>>
>>> # Iterate over results one page at a time
>>> for page in client.list_reference_images(parent).pages:
...     for element in page:
...         # process element
...         pass
Parameters
  • parent (str) –

    Required. Resource name of the product containing the reference images.

    Format is projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID.

  • page_size (int) – The maximum number of resources contained in the underlying API response. If page streaming is performed per- resource, this parameter does not affect the return value. If page streaming is performed per-page, this determines the maximum number of resources in a page.

  • retry (Optional[google.api_core.retry.Retry]) – A retry object used to retry requests. If None is specified, requests will be retried using a default configuration.

  • timeout (Optional[float]) – The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.

  • metadata (Optional[Sequence[Tuple[str, str]]]) – Additional metadata that is provided to the method.

Returns

A PageIterator instance. An iterable of ReferenceImage instances. You can also iterate over the pages of the response using its pages property.

Raises
classmethod location_path(project, location)[source]

DEPRECATED. Return a fully-qualified location string.

classmethod product_path(project, location, product)[source]

DEPRECATED. Return a fully-qualified product string.

classmethod product_set_path(project, location, product_set)[source]

DEPRECATED. Return a fully-qualified product_set string.

purge_products(parent, product_set_purge_config=None, delete_orphan_products=None, force=None, retry=<object object>, timeout=<object object>, metadata=None)[source]

Asynchronous API to delete all Products in a ProductSet or all Products that are in no ProductSet.

If a Product is a member of the specified ProductSet in addition to other ProductSets, the Product will still be deleted.

It is recommended to not delete the specified ProductSet until after this operation has completed. It is also recommended to not add any of the Products involved in the batch delete to a new ProductSet while this operation is running because those Products may still end up deleted.

It’s not possible to undo the PurgeProducts operation. Therefore, it is recommended to keep the csv files used in ImportProductSets (if that was how you originally built the Product Set) before starting PurgeProducts, in case you need to re-import the data after deletion.

If the plan is to purge all of the Products from a ProductSet and then re-use the empty ProductSet to re-import new Products into the empty ProductSet, you must wait until the PurgeProducts operation has finished for that ProductSet.

The google.longrunning.Operation API can be used to keep track of the progress and results of the request. Operation.metadata contains BatchOperationMetadata. (progress)

Example

>>> from google.cloud import vision_v1
>>>
>>> client = vision_v1.ProductSearchClient()
>>>
>>> parent = client.location_path('[PROJECT]', '[LOCATION]')
>>>
>>> response = client.purge_products(parent)
>>>
>>> def callback(operation_future):
...     # Handle result.
...     result = operation_future.result()
>>>
>>> response.add_done_callback(callback)
>>>
>>> # Handle metadata.
>>> metadata = response.metadata()
Parameters
  • parent (str) –

    Required. The project and location in which the Products should be deleted.

    Format is projects/PROJECT_ID/locations/LOC_ID.

  • product_set_purge_config (Union[dict, ProductSetPurgeConfig]) –

    Specify which ProductSet contains the Products to be deleted.

    If a dict is provided, it must be of the same form as the protobuf message ProductSetPurgeConfig

  • delete_orphan_products (bool) – If delete_orphan_products is true, all Products that are not in any ProductSet will be deleted.

  • force (bool) – The default value is false. Override this value to true to actually perform the purge.

  • retry (Optional[google.api_core.retry.Retry]) – A retry object used to retry requests. If None is specified, requests will be retried using a default configuration.

  • timeout (Optional[float]) – The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.

  • metadata (Optional[Sequence[Tuple[str, str]]]) – Additional metadata that is provided to the method.

Returns

A _OperationFuture instance.

Raises
classmethod reference_image_path(project, location, product, reference_image)[source]

DEPRECATED. Return a fully-qualified reference_image string.

remove_product_from_product_set(name, product, retry=<object object>, timeout=<object object>, metadata=None)[source]

Removes a Product from the specified ProductSet.

Example

>>> from google.cloud import vision_v1
>>>
>>> client = vision_v1.ProductSearchClient()
>>>
>>> name = client.product_set_path('[PROJECT]', '[LOCATION]', '[PRODUCT_SET]')
>>> product = client.product_path('[PROJECT]', '[LOCATION]', '[PRODUCT]')
>>>
>>> client.remove_product_from_product_set(name, product)
Parameters
  • name (str) –

    Required. The resource name for the ProductSet to modify.

    Format is: projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID

  • product (str) –

    Required. The resource name for the Product to be removed from this ProductSet.

    Format is: projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID

  • retry (Optional[google.api_core.retry.Retry]) – A retry object used to retry requests. If None is specified, requests will be retried using a default configuration.

  • timeout (Optional[float]) – The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.

  • metadata (Optional[Sequence[Tuple[str, str]]]) – Additional metadata that is provided to the method.

Raises
update_product(product, update_mask=None, retry=<object object>, timeout=<object object>, metadata=None)[source]

Makes changes to a Product resource. Only the display_name, description, and labels fields can be updated right now.

If labels are updated, the change will not be reflected in queries until the next index time.

Possible errors:

  • Returns NOT_FOUND if the Product does not exist.

  • Returns INVALID_ARGUMENT if display_name is present in update_mask but is missing from the request or longer than 4096 characters.

  • Returns INVALID_ARGUMENT if description is present in update_mask but is longer than 4096 characters.

  • Returns INVALID_ARGUMENT if product_category is present in update_mask.

Example

>>> from google.cloud import vision_v1
>>>
>>> client = vision_v1.ProductSearchClient()
>>>
>>> # TODO: Initialize `product`:
>>> product = {}
>>>
>>> response = client.update_product(product)
Parameters
  • product (Union[dict, Product]) –

    Required. The Product resource which replaces the one on the server. product.name is immutable.

    If a dict is provided, it must be of the same form as the protobuf message Product

  • update_mask (Union[dict, FieldMask]) –

    The FieldMask that specifies which fields to update. If update_mask isn’t specified, all mutable fields are to be updated. Valid mask paths include product_labels, display_name, and description.

    If a dict is provided, it must be of the same form as the protobuf message FieldMask

  • retry (Optional[google.api_core.retry.Retry]) – A retry object used to retry requests. If None is specified, requests will be retried using a default configuration.

  • timeout (Optional[float]) – The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.

  • metadata (Optional[Sequence[Tuple[str, str]]]) – Additional metadata that is provided to the method.

Returns

A Product instance.

Raises
update_product_set(product_set, update_mask=None, retry=<object object>, timeout=<object object>, metadata=None)[source]

Makes changes to a ProductSet resource. Only display_name can be updated currently.

Possible errors:

  • Returns NOT_FOUND if the ProductSet does not exist.

  • Returns INVALID_ARGUMENT if display_name is present in update_mask but missing from the request or longer than 4096 characters.

Example

>>> from google.cloud import vision_v1
>>>
>>> client = vision_v1.ProductSearchClient()
>>>
>>> # TODO: Initialize `product_set`:
>>> product_set = {}
>>>
>>> response = client.update_product_set(product_set)
Parameters
  • product_set (Union[dict, ProductSet]) –

    Required. The ProductSet resource which replaces the one on the server.

    If a dict is provided, it must be of the same form as the protobuf message ProductSet

  • update_mask (Union[dict, FieldMask]) –

    The FieldMask that specifies which fields to update. If update_mask isn’t specified, all mutable fields are to be updated. Valid mask path is display_name.

    If a dict is provided, it must be of the same form as the protobuf message FieldMask

  • retry (Optional[google.api_core.retry.Retry]) – A retry object used to retry requests. If None is specified, requests will be retried using a default configuration.

  • timeout (Optional[float]) – The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.

  • metadata (Optional[Sequence[Tuple[str, str]]]) – Additional metadata that is provided to the method.

Returns

A ProductSet instance.

Raises