1# -*- coding: utf-8 -*- 2# Copyright 2020 Google LLC 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15# 16from collections import OrderedDict 17import functools 18import re 19from typing import Dict, Sequence, Tuple, Type, Union 20import pkg_resources 21 22from google.api_core.client_options import ClientOptions # type: ignore 23from google.api_core import exceptions as core_exceptions # type: ignore 24from google.api_core import gapic_v1 # type: ignore 25from google.api_core import retry as retries # type: ignore 26from google.auth import credentials as ga_credentials # type: ignore 27from google.oauth2 import service_account # type: ignore 28 29OptionalRetry = Union[retries.Retry, object] 30 31from google.api_core import operation # type: ignore 32from google.api_core import operation_async # type: ignore 33from google.cloud.vision_v1p3beta1.services.product_search import pagers 34from google.cloud.vision_v1p3beta1.types import geometry 35from google.cloud.vision_v1p3beta1.types import product_search_service 36from google.protobuf import field_mask_pb2 # type: ignore 37from google.protobuf import timestamp_pb2 # type: ignore 38from google.rpc import status_pb2 # type: ignore 39from .transports.base import ProductSearchTransport, DEFAULT_CLIENT_INFO 40from .transports.grpc_asyncio import ProductSearchGrpcAsyncIOTransport 41from .client import ProductSearchClient 42 43 44class ProductSearchAsyncClient: 45 """Manages Products and ProductSets of reference images for use in 46 product search. It uses the following resource model: 47 48 - The API has a collection of 49 [ProductSet][google.cloud.vision.v1p3beta1.ProductSet] resources, 50 named ``projects/*/locations/*/productSets/*``, which acts as a 51 way to put different products into groups to limit 52 identification. 53 54 In parallel, 55 56 - The API has a collection of 57 [Product][google.cloud.vision.v1p3beta1.Product] resources, named 58 ``projects/*/locations/*/products/*`` 59 60 - Each [Product][google.cloud.vision.v1p3beta1.Product] has a 61 collection of 62 [ReferenceImage][google.cloud.vision.v1p3beta1.ReferenceImage] 63 resources, named 64 ``projects/*/locations/*/products/*/referenceImages/*`` 65 """ 66 67 _client: ProductSearchClient 68 69 DEFAULT_ENDPOINT = ProductSearchClient.DEFAULT_ENDPOINT 70 DEFAULT_MTLS_ENDPOINT = ProductSearchClient.DEFAULT_MTLS_ENDPOINT 71 72 product_path = staticmethod(ProductSearchClient.product_path) 73 parse_product_path = staticmethod(ProductSearchClient.parse_product_path) 74 product_set_path = staticmethod(ProductSearchClient.product_set_path) 75 parse_product_set_path = staticmethod(ProductSearchClient.parse_product_set_path) 76 reference_image_path = staticmethod(ProductSearchClient.reference_image_path) 77 parse_reference_image_path = staticmethod( 78 ProductSearchClient.parse_reference_image_path 79 ) 80 common_billing_account_path = staticmethod( 81 ProductSearchClient.common_billing_account_path 82 ) 83 parse_common_billing_account_path = staticmethod( 84 ProductSearchClient.parse_common_billing_account_path 85 ) 86 common_folder_path = staticmethod(ProductSearchClient.common_folder_path) 87 parse_common_folder_path = staticmethod( 88 ProductSearchClient.parse_common_folder_path 89 ) 90 common_organization_path = staticmethod( 91 ProductSearchClient.common_organization_path 92 ) 93 parse_common_organization_path = staticmethod( 94 ProductSearchClient.parse_common_organization_path 95 ) 96 common_project_path = staticmethod(ProductSearchClient.common_project_path) 97 parse_common_project_path = staticmethod( 98 ProductSearchClient.parse_common_project_path 99 ) 100 common_location_path = staticmethod(ProductSearchClient.common_location_path) 101 parse_common_location_path = staticmethod( 102 ProductSearchClient.parse_common_location_path 103 ) 104 105 @classmethod 106 def from_service_account_info(cls, info: dict, *args, **kwargs): 107 """Creates an instance of this client using the provided credentials 108 info. 109 110 Args: 111 info (dict): The service account private key info. 112 args: Additional arguments to pass to the constructor. 113 kwargs: Additional arguments to pass to the constructor. 114 115 Returns: 116 ProductSearchAsyncClient: The constructed client. 117 """ 118 return ProductSearchClient.from_service_account_info.__func__(ProductSearchAsyncClient, info, *args, **kwargs) # type: ignore 119 120 @classmethod 121 def from_service_account_file(cls, filename: str, *args, **kwargs): 122 """Creates an instance of this client using the provided credentials 123 file. 124 125 Args: 126 filename (str): The path to the service account private key json 127 file. 128 args: Additional arguments to pass to the constructor. 129 kwargs: Additional arguments to pass to the constructor. 130 131 Returns: 132 ProductSearchAsyncClient: The constructed client. 133 """ 134 return ProductSearchClient.from_service_account_file.__func__(ProductSearchAsyncClient, filename, *args, **kwargs) # type: ignore 135 136 from_service_account_json = from_service_account_file 137 138 @property 139 def transport(self) -> ProductSearchTransport: 140 """Returns the transport used by the client instance. 141 142 Returns: 143 ProductSearchTransport: The transport used by the client instance. 144 """ 145 return self._client.transport 146 147 get_transport_class = functools.partial( 148 type(ProductSearchClient).get_transport_class, type(ProductSearchClient) 149 ) 150 151 def __init__( 152 self, 153 *, 154 credentials: ga_credentials.Credentials = None, 155 transport: Union[str, ProductSearchTransport] = "grpc_asyncio", 156 client_options: ClientOptions = None, 157 client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, 158 ) -> None: 159 """Instantiates the product search client. 160 161 Args: 162 credentials (Optional[google.auth.credentials.Credentials]): The 163 authorization credentials to attach to requests. These 164 credentials identify the application to the service; if none 165 are specified, the client will attempt to ascertain the 166 credentials from the environment. 167 transport (Union[str, ~.ProductSearchTransport]): The 168 transport to use. If set to None, a transport is chosen 169 automatically. 170 client_options (ClientOptions): Custom options for the client. It 171 won't take effect if a ``transport`` instance is provided. 172 (1) The ``api_endpoint`` property can be used to override the 173 default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT 174 environment variable can also be used to override the endpoint: 175 "always" (always use the default mTLS endpoint), "never" (always 176 use the default regular endpoint) and "auto" (auto switch to the 177 default mTLS endpoint if client certificate is present, this is 178 the default value). However, the ``api_endpoint`` property takes 179 precedence if provided. 180 (2) If GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable 181 is "true", then the ``client_cert_source`` property can be used 182 to provide client certificate for mutual TLS transport. If 183 not provided, the default SSL client certificate will be used if 184 present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not 185 set, no client certificate will be used. 186 187 Raises: 188 google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport 189 creation failed for any reason. 190 """ 191 self._client = ProductSearchClient( 192 credentials=credentials, 193 transport=transport, 194 client_options=client_options, 195 client_info=client_info, 196 ) 197 198 async def create_product_set( 199 self, 200 request: Union[product_search_service.CreateProductSetRequest, dict] = None, 201 *, 202 parent: str = None, 203 product_set: product_search_service.ProductSet = None, 204 product_set_id: str = None, 205 retry: OptionalRetry = gapic_v1.method.DEFAULT, 206 timeout: float = None, 207 metadata: Sequence[Tuple[str, str]] = (), 208 ) -> product_search_service.ProductSet: 209 r"""Creates and returns a new ProductSet resource. 210 211 Possible errors: 212 213 - Returns INVALID_ARGUMENT if display_name is missing, or is 214 longer than 4096 characters. 215 216 Args: 217 request (Union[google.cloud.vision_v1p3beta1.types.CreateProductSetRequest, dict]): 218 The request object. Request message for the 219 `CreateProductSet` method. 220 parent (:class:`str`): 221 Required. The project in which the ProductSet should be 222 created. 223 224 Format is ``projects/PROJECT_ID/locations/LOC_ID``. 225 226 This corresponds to the ``parent`` field 227 on the ``request`` instance; if ``request`` is provided, this 228 should not be set. 229 product_set (:class:`google.cloud.vision_v1p3beta1.types.ProductSet`): 230 Required. The ProductSet to create. 231 This corresponds to the ``product_set`` field 232 on the ``request`` instance; if ``request`` is provided, this 233 should not be set. 234 product_set_id (:class:`str`): 235 A user-supplied resource id for this ProductSet. If set, 236 the server will attempt to use this value as the 237 resource id. If it is already in use, an error is 238 returned with code ALREADY_EXISTS. Must be at most 128 239 characters long. It cannot contain the character ``/``. 240 241 This corresponds to the ``product_set_id`` field 242 on the ``request`` instance; if ``request`` is provided, this 243 should not be set. 244 retry (google.api_core.retry.Retry): Designation of what errors, if any, 245 should be retried. 246 timeout (float): The timeout for this request. 247 metadata (Sequence[Tuple[str, str]]): Strings which should be 248 sent along with the request as metadata. 249 250 Returns: 251 google.cloud.vision_v1p3beta1.types.ProductSet: 252 A ProductSet contains Products. A 253 ProductSet can contain a maximum of 1 254 million reference images. If the limit 255 is exceeded, periodic indexing will 256 fail. 257 258 """ 259 # Create or coerce a protobuf request object. 260 # Sanity check: If we got a request object, we should *not* have 261 # gotten any keyword arguments that map to the request. 262 has_flattened_params = any([parent, product_set, product_set_id]) 263 if request is not None and has_flattened_params: 264 raise ValueError( 265 "If the `request` argument is set, then none of " 266 "the individual field arguments should be set." 267 ) 268 269 request = product_search_service.CreateProductSetRequest(request) 270 271 # If we have keyword arguments corresponding to fields on the 272 # request, apply these. 273 if parent is not None: 274 request.parent = parent 275 if product_set is not None: 276 request.product_set = product_set 277 if product_set_id is not None: 278 request.product_set_id = product_set_id 279 280 # Wrap the RPC method; this adds retry and timeout information, 281 # and friendly error handling. 282 rpc = gapic_v1.method_async.wrap_method( 283 self._client._transport.create_product_set, 284 default_retry=retries.Retry( 285 initial=0.1, 286 maximum=60.0, 287 multiplier=1.3, 288 predicate=retries.if_exception_type(), 289 deadline=600.0, 290 ), 291 default_timeout=600.0, 292 client_info=DEFAULT_CLIENT_INFO, 293 ) 294 295 # Certain fields should be provided within the metadata header; 296 # add these here. 297 metadata = tuple(metadata) + ( 298 gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), 299 ) 300 301 # Send the request. 302 response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) 303 304 # Done; return the response. 305 return response 306 307 async def list_product_sets( 308 self, 309 request: Union[product_search_service.ListProductSetsRequest, dict] = None, 310 *, 311 parent: str = None, 312 retry: OptionalRetry = gapic_v1.method.DEFAULT, 313 timeout: float = None, 314 metadata: Sequence[Tuple[str, str]] = (), 315 ) -> pagers.ListProductSetsAsyncPager: 316 r"""Lists ProductSets in an unspecified order. 317 318 Possible errors: 319 320 - Returns INVALID_ARGUMENT if page_size is greater than 100, or 321 less than 1. 322 323 Args: 324 request (Union[google.cloud.vision_v1p3beta1.types.ListProductSetsRequest, dict]): 325 The request object. Request message for the 326 `ListProductSets` method. 327 parent (:class:`str`): 328 Required. The project from which ProductSets should be 329 listed. 330 331 Format is ``projects/PROJECT_ID/locations/LOC_ID``. 332 333 This corresponds to the ``parent`` field 334 on the ``request`` instance; if ``request`` is provided, this 335 should not be set. 336 retry (google.api_core.retry.Retry): Designation of what errors, if any, 337 should be retried. 338 timeout (float): The timeout for this request. 339 metadata (Sequence[Tuple[str, str]]): Strings which should be 340 sent along with the request as metadata. 341 342 Returns: 343 google.cloud.vision_v1p3beta1.services.product_search.pagers.ListProductSetsAsyncPager: 344 Response message for the ListProductSets method. 345 346 Iterating over this object will yield results and 347 resolve additional pages automatically. 348 349 """ 350 # Create or coerce a protobuf request object. 351 # Sanity check: If we got a request object, we should *not* have 352 # gotten any keyword arguments that map to the request. 353 has_flattened_params = any([parent]) 354 if request is not None and has_flattened_params: 355 raise ValueError( 356 "If the `request` argument is set, then none of " 357 "the individual field arguments should be set." 358 ) 359 360 request = product_search_service.ListProductSetsRequest(request) 361 362 # If we have keyword arguments corresponding to fields on the 363 # request, apply these. 364 if parent is not None: 365 request.parent = parent 366 367 # Wrap the RPC method; this adds retry and timeout information, 368 # and friendly error handling. 369 rpc = gapic_v1.method_async.wrap_method( 370 self._client._transport.list_product_sets, 371 default_retry=retries.Retry( 372 initial=0.1, 373 maximum=60.0, 374 multiplier=1.3, 375 predicate=retries.if_exception_type( 376 core_exceptions.DeadlineExceeded, 377 core_exceptions.ServiceUnavailable, 378 ), 379 deadline=600.0, 380 ), 381 default_timeout=600.0, 382 client_info=DEFAULT_CLIENT_INFO, 383 ) 384 385 # Certain fields should be provided within the metadata header; 386 # add these here. 387 metadata = tuple(metadata) + ( 388 gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), 389 ) 390 391 # Send the request. 392 response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) 393 394 # This method is paged; wrap the response in a pager, which provides 395 # an `__aiter__` convenience method. 396 response = pagers.ListProductSetsAsyncPager( 397 method=rpc, request=request, response=response, metadata=metadata, 398 ) 399 400 # Done; return the response. 401 return response 402 403 async def get_product_set( 404 self, 405 request: Union[product_search_service.GetProductSetRequest, dict] = None, 406 *, 407 name: str = None, 408 retry: OptionalRetry = gapic_v1.method.DEFAULT, 409 timeout: float = None, 410 metadata: Sequence[Tuple[str, str]] = (), 411 ) -> product_search_service.ProductSet: 412 r"""Gets information associated with a ProductSet. 413 414 Possible errors: 415 416 - Returns NOT_FOUND if the ProductSet does not exist. 417 418 Args: 419 request (Union[google.cloud.vision_v1p3beta1.types.GetProductSetRequest, dict]): 420 The request object. Request message for the 421 `GetProductSet` method. 422 name (:class:`str`): 423 Required. Resource name of the ProductSet to get. 424 425 Format is: 426 ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` 427 428 This corresponds to the ``name`` field 429 on the ``request`` instance; if ``request`` is provided, this 430 should not be set. 431 retry (google.api_core.retry.Retry): Designation of what errors, if any, 432 should be retried. 433 timeout (float): The timeout for this request. 434 metadata (Sequence[Tuple[str, str]]): Strings which should be 435 sent along with the request as metadata. 436 437 Returns: 438 google.cloud.vision_v1p3beta1.types.ProductSet: 439 A ProductSet contains Products. A 440 ProductSet can contain a maximum of 1 441 million reference images. If the limit 442 is exceeded, periodic indexing will 443 fail. 444 445 """ 446 # Create or coerce a protobuf request object. 447 # Sanity check: If we got a request object, we should *not* have 448 # gotten any keyword arguments that map to the request. 449 has_flattened_params = any([name]) 450 if request is not None and has_flattened_params: 451 raise ValueError( 452 "If the `request` argument is set, then none of " 453 "the individual field arguments should be set." 454 ) 455 456 request = product_search_service.GetProductSetRequest(request) 457 458 # If we have keyword arguments corresponding to fields on the 459 # request, apply these. 460 if name is not None: 461 request.name = name 462 463 # Wrap the RPC method; this adds retry and timeout information, 464 # and friendly error handling. 465 rpc = gapic_v1.method_async.wrap_method( 466 self._client._transport.get_product_set, 467 default_retry=retries.Retry( 468 initial=0.1, 469 maximum=60.0, 470 multiplier=1.3, 471 predicate=retries.if_exception_type( 472 core_exceptions.DeadlineExceeded, 473 core_exceptions.ServiceUnavailable, 474 ), 475 deadline=600.0, 476 ), 477 default_timeout=600.0, 478 client_info=DEFAULT_CLIENT_INFO, 479 ) 480 481 # Certain fields should be provided within the metadata header; 482 # add these here. 483 metadata = tuple(metadata) + ( 484 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), 485 ) 486 487 # Send the request. 488 response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) 489 490 # Done; return the response. 491 return response 492 493 async def update_product_set( 494 self, 495 request: Union[product_search_service.UpdateProductSetRequest, dict] = None, 496 *, 497 product_set: product_search_service.ProductSet = None, 498 update_mask: field_mask_pb2.FieldMask = None, 499 retry: OptionalRetry = gapic_v1.method.DEFAULT, 500 timeout: float = None, 501 metadata: Sequence[Tuple[str, str]] = (), 502 ) -> product_search_service.ProductSet: 503 r"""Makes changes to a ProductSet resource. Only display_name can be 504 updated currently. 505 506 Possible errors: 507 508 - Returns NOT_FOUND if the ProductSet does not exist. 509 - Returns INVALID_ARGUMENT if display_name is present in 510 update_mask but missing from the request or longer than 4096 511 characters. 512 513 Args: 514 request (Union[google.cloud.vision_v1p3beta1.types.UpdateProductSetRequest, dict]): 515 The request object. Request message for the 516 `UpdateProductSet` method. 517 product_set (:class:`google.cloud.vision_v1p3beta1.types.ProductSet`): 518 Required. The ProductSet resource 519 which replaces the one on the server. 520 521 This corresponds to the ``product_set`` field 522 on the ``request`` instance; if ``request`` is provided, this 523 should not be set. 524 update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): 525 The [FieldMask][google.protobuf.FieldMask] that 526 specifies which fields to update. If update_mask isn't 527 specified, all mutable fields are to be updated. Valid 528 mask path is ``display_name``. 529 530 This corresponds to the ``update_mask`` field 531 on the ``request`` instance; if ``request`` is provided, this 532 should not be set. 533 retry (google.api_core.retry.Retry): Designation of what errors, if any, 534 should be retried. 535 timeout (float): The timeout for this request. 536 metadata (Sequence[Tuple[str, str]]): Strings which should be 537 sent along with the request as metadata. 538 539 Returns: 540 google.cloud.vision_v1p3beta1.types.ProductSet: 541 A ProductSet contains Products. A 542 ProductSet can contain a maximum of 1 543 million reference images. If the limit 544 is exceeded, periodic indexing will 545 fail. 546 547 """ 548 # Create or coerce a protobuf request object. 549 # Sanity check: If we got a request object, we should *not* have 550 # gotten any keyword arguments that map to the request. 551 has_flattened_params = any([product_set, update_mask]) 552 if request is not None and has_flattened_params: 553 raise ValueError( 554 "If the `request` argument is set, then none of " 555 "the individual field arguments should be set." 556 ) 557 558 request = product_search_service.UpdateProductSetRequest(request) 559 560 # If we have keyword arguments corresponding to fields on the 561 # request, apply these. 562 if product_set is not None: 563 request.product_set = product_set 564 if update_mask is not None: 565 request.update_mask = update_mask 566 567 # Wrap the RPC method; this adds retry and timeout information, 568 # and friendly error handling. 569 rpc = gapic_v1.method_async.wrap_method( 570 self._client._transport.update_product_set, 571 default_retry=retries.Retry( 572 initial=0.1, 573 maximum=60.0, 574 multiplier=1.3, 575 predicate=retries.if_exception_type(), 576 deadline=600.0, 577 ), 578 default_timeout=600.0, 579 client_info=DEFAULT_CLIENT_INFO, 580 ) 581 582 # Certain fields should be provided within the metadata header; 583 # add these here. 584 metadata = tuple(metadata) + ( 585 gapic_v1.routing_header.to_grpc_metadata( 586 (("product_set.name", request.product_set.name),) 587 ), 588 ) 589 590 # Send the request. 591 response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) 592 593 # Done; return the response. 594 return response 595 596 async def delete_product_set( 597 self, 598 request: Union[product_search_service.DeleteProductSetRequest, dict] = None, 599 *, 600 name: str = None, 601 retry: OptionalRetry = gapic_v1.method.DEFAULT, 602 timeout: float = None, 603 metadata: Sequence[Tuple[str, str]] = (), 604 ) -> None: 605 r"""Permanently deletes a ProductSet. All Products and 606 ReferenceImages in the ProductSet will be deleted. 607 608 The actual image files are not deleted from Google Cloud 609 Storage. 610 611 Possible errors: 612 613 - Returns NOT_FOUND if the ProductSet does not exist. 614 615 Args: 616 request (Union[google.cloud.vision_v1p3beta1.types.DeleteProductSetRequest, dict]): 617 The request object. Request message for the 618 `DeleteProductSet` method. 619 name (:class:`str`): 620 Required. Resource name of the ProductSet to delete. 621 622 Format is: 623 ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` 624 625 This corresponds to the ``name`` field 626 on the ``request`` instance; if ``request`` is provided, this 627 should not be set. 628 retry (google.api_core.retry.Retry): Designation of what errors, if any, 629 should be retried. 630 timeout (float): The timeout for this request. 631 metadata (Sequence[Tuple[str, str]]): Strings which should be 632 sent along with the request as metadata. 633 """ 634 # Create or coerce a protobuf request object. 635 # Sanity check: If we got a request object, we should *not* have 636 # gotten any keyword arguments that map to the request. 637 has_flattened_params = any([name]) 638 if request is not None and has_flattened_params: 639 raise ValueError( 640 "If the `request` argument is set, then none of " 641 "the individual field arguments should be set." 642 ) 643 644 request = product_search_service.DeleteProductSetRequest(request) 645 646 # If we have keyword arguments corresponding to fields on the 647 # request, apply these. 648 if name is not None: 649 request.name = name 650 651 # Wrap the RPC method; this adds retry and timeout information, 652 # and friendly error handling. 653 rpc = gapic_v1.method_async.wrap_method( 654 self._client._transport.delete_product_set, 655 default_retry=retries.Retry( 656 initial=0.1, 657 maximum=60.0, 658 multiplier=1.3, 659 predicate=retries.if_exception_type( 660 core_exceptions.DeadlineExceeded, 661 core_exceptions.ServiceUnavailable, 662 ), 663 deadline=600.0, 664 ), 665 default_timeout=600.0, 666 client_info=DEFAULT_CLIENT_INFO, 667 ) 668 669 # Certain fields should be provided within the metadata header; 670 # add these here. 671 metadata = tuple(metadata) + ( 672 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), 673 ) 674 675 # Send the request. 676 await rpc( 677 request, retry=retry, timeout=timeout, metadata=metadata, 678 ) 679 680 async def create_product( 681 self, 682 request: Union[product_search_service.CreateProductRequest, dict] = None, 683 *, 684 parent: str = None, 685 product: product_search_service.Product = None, 686 product_id: str = None, 687 retry: OptionalRetry = gapic_v1.method.DEFAULT, 688 timeout: float = None, 689 metadata: Sequence[Tuple[str, str]] = (), 690 ) -> product_search_service.Product: 691 r"""Creates and returns a new product resource. 692 693 Possible errors: 694 695 - Returns INVALID_ARGUMENT if display_name is missing or longer 696 than 4096 characters. 697 - Returns INVALID_ARGUMENT if description is longer than 4096 698 characters. 699 - Returns INVALID_ARGUMENT if product_category is missing or 700 invalid. 701 702 Args: 703 request (Union[google.cloud.vision_v1p3beta1.types.CreateProductRequest, dict]): 704 The request object. Request message for the 705 `CreateProduct` method. 706 parent (:class:`str`): 707 Required. The project in which the Product should be 708 created. 709 710 Format is ``projects/PROJECT_ID/locations/LOC_ID``. 711 712 This corresponds to the ``parent`` field 713 on the ``request`` instance; if ``request`` is provided, this 714 should not be set. 715 product (:class:`google.cloud.vision_v1p3beta1.types.Product`): 716 Required. The product to create. 717 This corresponds to the ``product`` field 718 on the ``request`` instance; if ``request`` is provided, this 719 should not be set. 720 product_id (:class:`str`): 721 A user-supplied resource id for this Product. If set, 722 the server will attempt to use this value as the 723 resource id. If it is already in use, an error is 724 returned with code ALREADY_EXISTS. Must be at most 128 725 characters long. It cannot contain the character ``/``. 726 727 This corresponds to the ``product_id`` field 728 on the ``request`` instance; if ``request`` is provided, this 729 should not be set. 730 retry (google.api_core.retry.Retry): Designation of what errors, if any, 731 should be retried. 732 timeout (float): The timeout for this request. 733 metadata (Sequence[Tuple[str, str]]): Strings which should be 734 sent along with the request as metadata. 735 736 Returns: 737 google.cloud.vision_v1p3beta1.types.Product: 738 A Product contains ReferenceImages. 739 """ 740 # Create or coerce a protobuf request object. 741 # Sanity check: If we got a request object, we should *not* have 742 # gotten any keyword arguments that map to the request. 743 has_flattened_params = any([parent, product, product_id]) 744 if request is not None and has_flattened_params: 745 raise ValueError( 746 "If the `request` argument is set, then none of " 747 "the individual field arguments should be set." 748 ) 749 750 request = product_search_service.CreateProductRequest(request) 751 752 # If we have keyword arguments corresponding to fields on the 753 # request, apply these. 754 if parent is not None: 755 request.parent = parent 756 if product is not None: 757 request.product = product 758 if product_id is not None: 759 request.product_id = product_id 760 761 # Wrap the RPC method; this adds retry and timeout information, 762 # and friendly error handling. 763 rpc = gapic_v1.method_async.wrap_method( 764 self._client._transport.create_product, 765 default_retry=retries.Retry( 766 initial=0.1, 767 maximum=60.0, 768 multiplier=1.3, 769 predicate=retries.if_exception_type(), 770 deadline=600.0, 771 ), 772 default_timeout=600.0, 773 client_info=DEFAULT_CLIENT_INFO, 774 ) 775 776 # Certain fields should be provided within the metadata header; 777 # add these here. 778 metadata = tuple(metadata) + ( 779 gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), 780 ) 781 782 # Send the request. 783 response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) 784 785 # Done; return the response. 786 return response 787 788 async def list_products( 789 self, 790 request: Union[product_search_service.ListProductsRequest, dict] = None, 791 *, 792 parent: str = None, 793 retry: OptionalRetry = gapic_v1.method.DEFAULT, 794 timeout: float = None, 795 metadata: Sequence[Tuple[str, str]] = (), 796 ) -> pagers.ListProductsAsyncPager: 797 r"""Lists products in an unspecified order. 798 799 Possible errors: 800 801 - Returns INVALID_ARGUMENT if page_size is greater than 100 or 802 less than 1. 803 804 Args: 805 request (Union[google.cloud.vision_v1p3beta1.types.ListProductsRequest, dict]): 806 The request object. Request message for the 807 `ListProducts` method. 808 parent (:class:`str`): 809 Required. The project OR ProductSet from which Products 810 should be listed. 811 812 Format: ``projects/PROJECT_ID/locations/LOC_ID`` 813 814 This corresponds to the ``parent`` field 815 on the ``request`` instance; if ``request`` is provided, this 816 should not be set. 817 retry (google.api_core.retry.Retry): Designation of what errors, if any, 818 should be retried. 819 timeout (float): The timeout for this request. 820 metadata (Sequence[Tuple[str, str]]): Strings which should be 821 sent along with the request as metadata. 822 823 Returns: 824 google.cloud.vision_v1p3beta1.services.product_search.pagers.ListProductsAsyncPager: 825 Response message for the ListProducts method. 826 827 Iterating over this object will yield results and 828 resolve additional pages automatically. 829 830 """ 831 # Create or coerce a protobuf request object. 832 # Sanity check: If we got a request object, we should *not* have 833 # gotten any keyword arguments that map to the request. 834 has_flattened_params = any([parent]) 835 if request is not None and has_flattened_params: 836 raise ValueError( 837 "If the `request` argument is set, then none of " 838 "the individual field arguments should be set." 839 ) 840 841 request = product_search_service.ListProductsRequest(request) 842 843 # If we have keyword arguments corresponding to fields on the 844 # request, apply these. 845 if parent is not None: 846 request.parent = parent 847 848 # Wrap the RPC method; this adds retry and timeout information, 849 # and friendly error handling. 850 rpc = gapic_v1.method_async.wrap_method( 851 self._client._transport.list_products, 852 default_retry=retries.Retry( 853 initial=0.1, 854 maximum=60.0, 855 multiplier=1.3, 856 predicate=retries.if_exception_type( 857 core_exceptions.DeadlineExceeded, 858 core_exceptions.ServiceUnavailable, 859 ), 860 deadline=600.0, 861 ), 862 default_timeout=600.0, 863 client_info=DEFAULT_CLIENT_INFO, 864 ) 865 866 # Certain fields should be provided within the metadata header; 867 # add these here. 868 metadata = tuple(metadata) + ( 869 gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), 870 ) 871 872 # Send the request. 873 response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) 874 875 # This method is paged; wrap the response in a pager, which provides 876 # an `__aiter__` convenience method. 877 response = pagers.ListProductsAsyncPager( 878 method=rpc, request=request, response=response, metadata=metadata, 879 ) 880 881 # Done; return the response. 882 return response 883 884 async def get_product( 885 self, 886 request: Union[product_search_service.GetProductRequest, dict] = None, 887 *, 888 name: str = None, 889 retry: OptionalRetry = gapic_v1.method.DEFAULT, 890 timeout: float = None, 891 metadata: Sequence[Tuple[str, str]] = (), 892 ) -> product_search_service.Product: 893 r"""Gets information associated with a Product. 894 895 Possible errors: 896 897 - Returns NOT_FOUND if the Product does not exist. 898 899 Args: 900 request (Union[google.cloud.vision_v1p3beta1.types.GetProductRequest, dict]): 901 The request object. Request message for the `GetProduct` 902 method. 903 name (:class:`str`): 904 Required. Resource name of the Product to get. 905 906 Format is: 907 ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` 908 909 This corresponds to the ``name`` field 910 on the ``request`` instance; if ``request`` is provided, this 911 should not be set. 912 retry (google.api_core.retry.Retry): Designation of what errors, if any, 913 should be retried. 914 timeout (float): The timeout for this request. 915 metadata (Sequence[Tuple[str, str]]): Strings which should be 916 sent along with the request as metadata. 917 918 Returns: 919 google.cloud.vision_v1p3beta1.types.Product: 920 A Product contains ReferenceImages. 921 """ 922 # Create or coerce a protobuf request object. 923 # Sanity check: If we got a request object, we should *not* have 924 # gotten any keyword arguments that map to the request. 925 has_flattened_params = any([name]) 926 if request is not None and has_flattened_params: 927 raise ValueError( 928 "If the `request` argument is set, then none of " 929 "the individual field arguments should be set." 930 ) 931 932 request = product_search_service.GetProductRequest(request) 933 934 # If we have keyword arguments corresponding to fields on the 935 # request, apply these. 936 if name is not None: 937 request.name = name 938 939 # Wrap the RPC method; this adds retry and timeout information, 940 # and friendly error handling. 941 rpc = gapic_v1.method_async.wrap_method( 942 self._client._transport.get_product, 943 default_retry=retries.Retry( 944 initial=0.1, 945 maximum=60.0, 946 multiplier=1.3, 947 predicate=retries.if_exception_type( 948 core_exceptions.DeadlineExceeded, 949 core_exceptions.ServiceUnavailable, 950 ), 951 deadline=600.0, 952 ), 953 default_timeout=600.0, 954 client_info=DEFAULT_CLIENT_INFO, 955 ) 956 957 # Certain fields should be provided within the metadata header; 958 # add these here. 959 metadata = tuple(metadata) + ( 960 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), 961 ) 962 963 # Send the request. 964 response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) 965 966 # Done; return the response. 967 return response 968 969 async def update_product( 970 self, 971 request: Union[product_search_service.UpdateProductRequest, dict] = None, 972 *, 973 product: product_search_service.Product = None, 974 update_mask: field_mask_pb2.FieldMask = None, 975 retry: OptionalRetry = gapic_v1.method.DEFAULT, 976 timeout: float = None, 977 metadata: Sequence[Tuple[str, str]] = (), 978 ) -> product_search_service.Product: 979 r"""Makes changes to a Product resource. Only display_name, 980 description and labels can be updated right now. 981 982 If labels are updated, the change will not be reflected in 983 queries until the next index time. 984 985 Possible errors: 986 987 - Returns NOT_FOUND if the Product does not exist. 988 - Returns INVALID_ARGUMENT if display_name is present in 989 update_mask but is missing from the request or longer than 990 4096 characters. 991 - Returns INVALID_ARGUMENT if description is present in 992 update_mask but is longer than 4096 characters. 993 - Returns INVALID_ARGUMENT if product_category is present in 994 update_mask. 995 996 Args: 997 request (Union[google.cloud.vision_v1p3beta1.types.UpdateProductRequest, dict]): 998 The request object. Request message for the 999 `UpdateProduct` method. 1000 product (:class:`google.cloud.vision_v1p3beta1.types.Product`): 1001 Required. The Product resource which 1002 replaces the one on the server. 1003 product.name is immutable. 1004 1005 This corresponds to the ``product`` field 1006 on the ``request`` instance; if ``request`` is provided, this 1007 should not be set. 1008 update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): 1009 The [FieldMask][google.protobuf.FieldMask] that 1010 specifies which fields to update. If update_mask isn't 1011 specified, all mutable fields are to be updated. Valid 1012 mask paths include ``product_labels``, ``display_name``, 1013 and ``description``. 1014 1015 This corresponds to the ``update_mask`` field 1016 on the ``request`` instance; if ``request`` is provided, this 1017 should not be set. 1018 retry (google.api_core.retry.Retry): Designation of what errors, if any, 1019 should be retried. 1020 timeout (float): The timeout for this request. 1021 metadata (Sequence[Tuple[str, str]]): Strings which should be 1022 sent along with the request as metadata. 1023 1024 Returns: 1025 google.cloud.vision_v1p3beta1.types.Product: 1026 A Product contains ReferenceImages. 1027 """ 1028 # Create or coerce a protobuf request object. 1029 # Sanity check: If we got a request object, we should *not* have 1030 # gotten any keyword arguments that map to the request. 1031 has_flattened_params = any([product, update_mask]) 1032 if request is not None and has_flattened_params: 1033 raise ValueError( 1034 "If the `request` argument is set, then none of " 1035 "the individual field arguments should be set." 1036 ) 1037 1038 request = product_search_service.UpdateProductRequest(request) 1039 1040 # If we have keyword arguments corresponding to fields on the 1041 # request, apply these. 1042 if product is not None: 1043 request.product = product 1044 if update_mask is not None: 1045 request.update_mask = update_mask 1046 1047 # Wrap the RPC method; this adds retry and timeout information, 1048 # and friendly error handling. 1049 rpc = gapic_v1.method_async.wrap_method( 1050 self._client._transport.update_product, 1051 default_retry=retries.Retry( 1052 initial=0.1, 1053 maximum=60.0, 1054 multiplier=1.3, 1055 predicate=retries.if_exception_type(), 1056 deadline=600.0, 1057 ), 1058 default_timeout=600.0, 1059 client_info=DEFAULT_CLIENT_INFO, 1060 ) 1061 1062 # Certain fields should be provided within the metadata header; 1063 # add these here. 1064 metadata = tuple(metadata) + ( 1065 gapic_v1.routing_header.to_grpc_metadata( 1066 (("product.name", request.product.name),) 1067 ), 1068 ) 1069 1070 # Send the request. 1071 response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) 1072 1073 # Done; return the response. 1074 return response 1075 1076 async def delete_product( 1077 self, 1078 request: Union[product_search_service.DeleteProductRequest, dict] = None, 1079 *, 1080 name: str = None, 1081 retry: OptionalRetry = gapic_v1.method.DEFAULT, 1082 timeout: float = None, 1083 metadata: Sequence[Tuple[str, str]] = (), 1084 ) -> None: 1085 r"""Permanently deletes a product and its reference images. 1086 1087 Metadata of the product and all its images will be deleted right 1088 away, but search queries against ProductSets containing the 1089 product may still work until all related caches are refreshed. 1090 1091 Possible errors: 1092 1093 - Returns NOT_FOUND if the product does not exist. 1094 1095 Args: 1096 request (Union[google.cloud.vision_v1p3beta1.types.DeleteProductRequest, dict]): 1097 The request object. Request message for the 1098 `DeleteProduct` method. 1099 name (:class:`str`): 1100 Required. Resource name of product to delete. 1101 1102 Format is: 1103 ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` 1104 1105 This corresponds to the ``name`` field 1106 on the ``request`` instance; if ``request`` is provided, this 1107 should not be set. 1108 retry (google.api_core.retry.Retry): Designation of what errors, if any, 1109 should be retried. 1110 timeout (float): The timeout for this request. 1111 metadata (Sequence[Tuple[str, str]]): Strings which should be 1112 sent along with the request as metadata. 1113 """ 1114 # Create or coerce a protobuf request object. 1115 # Sanity check: If we got a request object, we should *not* have 1116 # gotten any keyword arguments that map to the request. 1117 has_flattened_params = any([name]) 1118 if request is not None and has_flattened_params: 1119 raise ValueError( 1120 "If the `request` argument is set, then none of " 1121 "the individual field arguments should be set." 1122 ) 1123 1124 request = product_search_service.DeleteProductRequest(request) 1125 1126 # If we have keyword arguments corresponding to fields on the 1127 # request, apply these. 1128 if name is not None: 1129 request.name = name 1130 1131 # Wrap the RPC method; this adds retry and timeout information, 1132 # and friendly error handling. 1133 rpc = gapic_v1.method_async.wrap_method( 1134 self._client._transport.delete_product, 1135 default_retry=retries.Retry( 1136 initial=0.1, 1137 maximum=60.0, 1138 multiplier=1.3, 1139 predicate=retries.if_exception_type( 1140 core_exceptions.DeadlineExceeded, 1141 core_exceptions.ServiceUnavailable, 1142 ), 1143 deadline=600.0, 1144 ), 1145 default_timeout=600.0, 1146 client_info=DEFAULT_CLIENT_INFO, 1147 ) 1148 1149 # Certain fields should be provided within the metadata header; 1150 # add these here. 1151 metadata = tuple(metadata) + ( 1152 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), 1153 ) 1154 1155 # Send the request. 1156 await rpc( 1157 request, retry=retry, timeout=timeout, metadata=metadata, 1158 ) 1159 1160 async def create_reference_image( 1161 self, 1162 request: Union[product_search_service.CreateReferenceImageRequest, dict] = None, 1163 *, 1164 parent: str = None, 1165 reference_image: product_search_service.ReferenceImage = None, 1166 reference_image_id: str = None, 1167 retry: OptionalRetry = gapic_v1.method.DEFAULT, 1168 timeout: float = None, 1169 metadata: Sequence[Tuple[str, str]] = (), 1170 ) -> product_search_service.ReferenceImage: 1171 r"""Creates and returns a new ReferenceImage resource. 1172 1173 The ``bounding_poly`` field is optional. If ``bounding_poly`` is 1174 not specified, the system will try to detect regions of interest 1175 in the image that are compatible with the product_category on 1176 the parent product. If it is specified, detection is ALWAYS 1177 skipped. The system converts polygons into non-rotated 1178 rectangles. 1179 1180 Note that the pipeline will resize the image if the image 1181 resolution is too large to process (above 50MP). 1182 1183 Possible errors: 1184 1185 - Returns INVALID_ARGUMENT if the image_uri is missing or 1186 longer than 4096 characters. 1187 - Returns INVALID_ARGUMENT if the product does not exist. 1188 - Returns INVALID_ARGUMENT if bounding_poly is not provided, 1189 and nothing compatible with the parent product's 1190 product_category is detected. 1191 - Returns INVALID_ARGUMENT if bounding_poly contains more than 1192 10 polygons. 1193 1194 Args: 1195 request (Union[google.cloud.vision_v1p3beta1.types.CreateReferenceImageRequest, dict]): 1196 The request object. Request message for the 1197 `CreateReferenceImage` method. 1198 parent (:class:`str`): 1199 Required. Resource name of the product in which to 1200 create the reference image. 1201 1202 Format is 1203 ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID``. 1204 1205 This corresponds to the ``parent`` field 1206 on the ``request`` instance; if ``request`` is provided, this 1207 should not be set. 1208 reference_image (:class:`google.cloud.vision_v1p3beta1.types.ReferenceImage`): 1209 Required. The reference image to 1210 create. If an image ID is specified, it 1211 is ignored. 1212 1213 This corresponds to the ``reference_image`` field 1214 on the ``request`` instance; if ``request`` is provided, this 1215 should not be set. 1216 reference_image_id (:class:`str`): 1217 A user-supplied resource id for the ReferenceImage to be 1218 added. If set, the server will attempt to use this value 1219 as the resource id. If it is already in use, an error is 1220 returned with code ALREADY_EXISTS. Must be at most 128 1221 characters long. It cannot contain the character ``/``. 1222 1223 This corresponds to the ``reference_image_id`` field 1224 on the ``request`` instance; if ``request`` is provided, this 1225 should not be set. 1226 retry (google.api_core.retry.Retry): Designation of what errors, if any, 1227 should be retried. 1228 timeout (float): The timeout for this request. 1229 metadata (Sequence[Tuple[str, str]]): Strings which should be 1230 sent along with the request as metadata. 1231 1232 Returns: 1233 google.cloud.vision_v1p3beta1.types.ReferenceImage: 1234 A ReferenceImage represents a product image and its associated metadata, 1235 such as bounding boxes. 1236 1237 """ 1238 # Create or coerce a protobuf request object. 1239 # Sanity check: If we got a request object, we should *not* have 1240 # gotten any keyword arguments that map to the request. 1241 has_flattened_params = any([parent, reference_image, reference_image_id]) 1242 if request is not None and has_flattened_params: 1243 raise ValueError( 1244 "If the `request` argument is set, then none of " 1245 "the individual field arguments should be set." 1246 ) 1247 1248 request = product_search_service.CreateReferenceImageRequest(request) 1249 1250 # If we have keyword arguments corresponding to fields on the 1251 # request, apply these. 1252 if parent is not None: 1253 request.parent = parent 1254 if reference_image is not None: 1255 request.reference_image = reference_image 1256 if reference_image_id is not None: 1257 request.reference_image_id = reference_image_id 1258 1259 # Wrap the RPC method; this adds retry and timeout information, 1260 # and friendly error handling. 1261 rpc = gapic_v1.method_async.wrap_method( 1262 self._client._transport.create_reference_image, 1263 default_retry=retries.Retry( 1264 initial=0.1, 1265 maximum=60.0, 1266 multiplier=1.3, 1267 predicate=retries.if_exception_type(), 1268 deadline=600.0, 1269 ), 1270 default_timeout=600.0, 1271 client_info=DEFAULT_CLIENT_INFO, 1272 ) 1273 1274 # Certain fields should be provided within the metadata header; 1275 # add these here. 1276 metadata = tuple(metadata) + ( 1277 gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), 1278 ) 1279 1280 # Send the request. 1281 response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) 1282 1283 # Done; return the response. 1284 return response 1285 1286 async def delete_reference_image( 1287 self, 1288 request: Union[product_search_service.DeleteReferenceImageRequest, dict] = None, 1289 *, 1290 name: str = None, 1291 retry: OptionalRetry = gapic_v1.method.DEFAULT, 1292 timeout: float = None, 1293 metadata: Sequence[Tuple[str, str]] = (), 1294 ) -> None: 1295 r"""Permanently deletes a reference image. 1296 1297 The image metadata will be deleted right away, but search 1298 queries against ProductSets containing the image may still work 1299 until all related caches are refreshed. 1300 1301 The actual image files are not deleted from Google Cloud 1302 Storage. 1303 1304 Possible errors: 1305 1306 - Returns NOT_FOUND if the reference image does not exist. 1307 1308 Args: 1309 request (Union[google.cloud.vision_v1p3beta1.types.DeleteReferenceImageRequest, dict]): 1310 The request object. Request message for the 1311 `DeleteReferenceImage` method. 1312 name (:class:`str`): 1313 Required. The resource name of the reference image to 1314 delete. 1315 1316 Format is: 1317 1318 ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID/referenceImages/IMAGE_ID`` 1319 1320 This corresponds to the ``name`` field 1321 on the ``request`` instance; if ``request`` is provided, this 1322 should not be set. 1323 retry (google.api_core.retry.Retry): Designation of what errors, if any, 1324 should be retried. 1325 timeout (float): The timeout for this request. 1326 metadata (Sequence[Tuple[str, str]]): Strings which should be 1327 sent along with the request as metadata. 1328 """ 1329 # Create or coerce a protobuf request object. 1330 # Sanity check: If we got a request object, we should *not* have 1331 # gotten any keyword arguments that map to the request. 1332 has_flattened_params = any([name]) 1333 if request is not None and has_flattened_params: 1334 raise ValueError( 1335 "If the `request` argument is set, then none of " 1336 "the individual field arguments should be set." 1337 ) 1338 1339 request = product_search_service.DeleteReferenceImageRequest(request) 1340 1341 # If we have keyword arguments corresponding to fields on the 1342 # request, apply these. 1343 if name is not None: 1344 request.name = name 1345 1346 # Wrap the RPC method; this adds retry and timeout information, 1347 # and friendly error handling. 1348 rpc = gapic_v1.method_async.wrap_method( 1349 self._client._transport.delete_reference_image, 1350 default_retry=retries.Retry( 1351 initial=0.1, 1352 maximum=60.0, 1353 multiplier=1.3, 1354 predicate=retries.if_exception_type( 1355 core_exceptions.DeadlineExceeded, 1356 core_exceptions.ServiceUnavailable, 1357 ), 1358 deadline=600.0, 1359 ), 1360 default_timeout=600.0, 1361 client_info=DEFAULT_CLIENT_INFO, 1362 ) 1363 1364 # Certain fields should be provided within the metadata header; 1365 # add these here. 1366 metadata = tuple(metadata) + ( 1367 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), 1368 ) 1369 1370 # Send the request. 1371 await rpc( 1372 request, retry=retry, timeout=timeout, metadata=metadata, 1373 ) 1374 1375 async def list_reference_images( 1376 self, 1377 request: Union[product_search_service.ListReferenceImagesRequest, dict] = None, 1378 *, 1379 parent: str = None, 1380 retry: OptionalRetry = gapic_v1.method.DEFAULT, 1381 timeout: float = None, 1382 metadata: Sequence[Tuple[str, str]] = (), 1383 ) -> pagers.ListReferenceImagesAsyncPager: 1384 r"""Lists reference images. 1385 1386 Possible errors: 1387 1388 - Returns NOT_FOUND if the parent product does not exist. 1389 - Returns INVALID_ARGUMENT if the page_size is greater than 1390 100, or less than 1. 1391 1392 Args: 1393 request (Union[google.cloud.vision_v1p3beta1.types.ListReferenceImagesRequest, dict]): 1394 The request object. Request message for the 1395 `ListReferenceImages` method. 1396 parent (:class:`str`): 1397 Required. Resource name of the product containing the 1398 reference images. 1399 1400 Format is 1401 ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID``. 1402 1403 This corresponds to the ``parent`` field 1404 on the ``request`` instance; if ``request`` is provided, this 1405 should not be set. 1406 retry (google.api_core.retry.Retry): Designation of what errors, if any, 1407 should be retried. 1408 timeout (float): The timeout for this request. 1409 metadata (Sequence[Tuple[str, str]]): Strings which should be 1410 sent along with the request as metadata. 1411 1412 Returns: 1413 google.cloud.vision_v1p3beta1.services.product_search.pagers.ListReferenceImagesAsyncPager: 1414 Response message for the ListReferenceImages method. 1415 1416 Iterating over this object will yield results and 1417 resolve additional pages automatically. 1418 1419 """ 1420 # Create or coerce a protobuf request object. 1421 # Sanity check: If we got a request object, we should *not* have 1422 # gotten any keyword arguments that map to the request. 1423 has_flattened_params = any([parent]) 1424 if request is not None and has_flattened_params: 1425 raise ValueError( 1426 "If the `request` argument is set, then none of " 1427 "the individual field arguments should be set." 1428 ) 1429 1430 request = product_search_service.ListReferenceImagesRequest(request) 1431 1432 # If we have keyword arguments corresponding to fields on the 1433 # request, apply these. 1434 if parent is not None: 1435 request.parent = parent 1436 1437 # Wrap the RPC method; this adds retry and timeout information, 1438 # and friendly error handling. 1439 rpc = gapic_v1.method_async.wrap_method( 1440 self._client._transport.list_reference_images, 1441 default_retry=retries.Retry( 1442 initial=0.1, 1443 maximum=60.0, 1444 multiplier=1.3, 1445 predicate=retries.if_exception_type( 1446 core_exceptions.DeadlineExceeded, 1447 core_exceptions.ServiceUnavailable, 1448 ), 1449 deadline=600.0, 1450 ), 1451 default_timeout=600.0, 1452 client_info=DEFAULT_CLIENT_INFO, 1453 ) 1454 1455 # Certain fields should be provided within the metadata header; 1456 # add these here. 1457 metadata = tuple(metadata) + ( 1458 gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), 1459 ) 1460 1461 # Send the request. 1462 response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) 1463 1464 # This method is paged; wrap the response in a pager, which provides 1465 # an `__aiter__` convenience method. 1466 response = pagers.ListReferenceImagesAsyncPager( 1467 method=rpc, request=request, response=response, metadata=metadata, 1468 ) 1469 1470 # Done; return the response. 1471 return response 1472 1473 async def get_reference_image( 1474 self, 1475 request: Union[product_search_service.GetReferenceImageRequest, dict] = None, 1476 *, 1477 name: str = None, 1478 retry: OptionalRetry = gapic_v1.method.DEFAULT, 1479 timeout: float = None, 1480 metadata: Sequence[Tuple[str, str]] = (), 1481 ) -> product_search_service.ReferenceImage: 1482 r"""Gets information associated with a ReferenceImage. 1483 1484 Possible errors: 1485 1486 - Returns NOT_FOUND if the specified image does not exist. 1487 1488 Args: 1489 request (Union[google.cloud.vision_v1p3beta1.types.GetReferenceImageRequest, dict]): 1490 The request object. Request message for the 1491 `GetReferenceImage` method. 1492 name (:class:`str`): 1493 Required. The resource name of the ReferenceImage to 1494 get. 1495 1496 Format is: 1497 1498 ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID/referenceImages/IMAGE_ID``. 1499 1500 This corresponds to the ``name`` field 1501 on the ``request`` instance; if ``request`` is provided, this 1502 should not be set. 1503 retry (google.api_core.retry.Retry): Designation of what errors, if any, 1504 should be retried. 1505 timeout (float): The timeout for this request. 1506 metadata (Sequence[Tuple[str, str]]): Strings which should be 1507 sent along with the request as metadata. 1508 1509 Returns: 1510 google.cloud.vision_v1p3beta1.types.ReferenceImage: 1511 A ReferenceImage represents a product image and its associated metadata, 1512 such as bounding boxes. 1513 1514 """ 1515 # Create or coerce a protobuf request object. 1516 # Sanity check: If we got a request object, we should *not* have 1517 # gotten any keyword arguments that map to the request. 1518 has_flattened_params = any([name]) 1519 if request is not None and has_flattened_params: 1520 raise ValueError( 1521 "If the `request` argument is set, then none of " 1522 "the individual field arguments should be set." 1523 ) 1524 1525 request = product_search_service.GetReferenceImageRequest(request) 1526 1527 # If we have keyword arguments corresponding to fields on the 1528 # request, apply these. 1529 if name is not None: 1530 request.name = name 1531 1532 # Wrap the RPC method; this adds retry and timeout information, 1533 # and friendly error handling. 1534 rpc = gapic_v1.method_async.wrap_method( 1535 self._client._transport.get_reference_image, 1536 default_retry=retries.Retry( 1537 initial=0.1, 1538 maximum=60.0, 1539 multiplier=1.3, 1540 predicate=retries.if_exception_type( 1541 core_exceptions.DeadlineExceeded, 1542 core_exceptions.ServiceUnavailable, 1543 ), 1544 deadline=600.0, 1545 ), 1546 default_timeout=600.0, 1547 client_info=DEFAULT_CLIENT_INFO, 1548 ) 1549 1550 # Certain fields should be provided within the metadata header; 1551 # add these here. 1552 metadata = tuple(metadata) + ( 1553 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), 1554 ) 1555 1556 # Send the request. 1557 response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) 1558 1559 # Done; return the response. 1560 return response 1561 1562 async def add_product_to_product_set( 1563 self, 1564 request: Union[ 1565 product_search_service.AddProductToProductSetRequest, dict 1566 ] = None, 1567 *, 1568 name: str = None, 1569 product: str = None, 1570 retry: OptionalRetry = gapic_v1.method.DEFAULT, 1571 timeout: float = None, 1572 metadata: Sequence[Tuple[str, str]] = (), 1573 ) -> None: 1574 r"""Adds a Product to the specified ProductSet. If the Product is 1575 already present, no change is made. 1576 1577 One Product can be added to at most 100 ProductSets. 1578 1579 Possible errors: 1580 1581 - Returns NOT_FOUND if the Product or the ProductSet doesn't 1582 exist. 1583 1584 Args: 1585 request (Union[google.cloud.vision_v1p3beta1.types.AddProductToProductSetRequest, dict]): 1586 The request object. Request message for the 1587 `AddProductToProductSet` method. 1588 name (:class:`str`): 1589 Required. The resource name for the ProductSet to 1590 modify. 1591 1592 Format is: 1593 ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` 1594 1595 This corresponds to the ``name`` field 1596 on the ``request`` instance; if ``request`` is provided, this 1597 should not be set. 1598 product (:class:`str`): 1599 Required. The resource name for the Product to be added 1600 to this ProductSet. 1601 1602 Format is: 1603 ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` 1604 1605 This corresponds to the ``product`` field 1606 on the ``request`` instance; if ``request`` is provided, this 1607 should not be set. 1608 retry (google.api_core.retry.Retry): Designation of what errors, if any, 1609 should be retried. 1610 timeout (float): The timeout for this request. 1611 metadata (Sequence[Tuple[str, str]]): Strings which should be 1612 sent along with the request as metadata. 1613 """ 1614 # Create or coerce a protobuf request object. 1615 # Sanity check: If we got a request object, we should *not* have 1616 # gotten any keyword arguments that map to the request. 1617 has_flattened_params = any([name, product]) 1618 if request is not None and has_flattened_params: 1619 raise ValueError( 1620 "If the `request` argument is set, then none of " 1621 "the individual field arguments should be set." 1622 ) 1623 1624 request = product_search_service.AddProductToProductSetRequest(request) 1625 1626 # If we have keyword arguments corresponding to fields on the 1627 # request, apply these. 1628 if name is not None: 1629 request.name = name 1630 if product is not None: 1631 request.product = product 1632 1633 # Wrap the RPC method; this adds retry and timeout information, 1634 # and friendly error handling. 1635 rpc = gapic_v1.method_async.wrap_method( 1636 self._client._transport.add_product_to_product_set, 1637 default_retry=retries.Retry( 1638 initial=0.1, 1639 maximum=60.0, 1640 multiplier=1.3, 1641 predicate=retries.if_exception_type(), 1642 deadline=600.0, 1643 ), 1644 default_timeout=600.0, 1645 client_info=DEFAULT_CLIENT_INFO, 1646 ) 1647 1648 # Certain fields should be provided within the metadata header; 1649 # add these here. 1650 metadata = tuple(metadata) + ( 1651 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), 1652 ) 1653 1654 # Send the request. 1655 await rpc( 1656 request, retry=retry, timeout=timeout, metadata=metadata, 1657 ) 1658 1659 async def remove_product_from_product_set( 1660 self, 1661 request: Union[ 1662 product_search_service.RemoveProductFromProductSetRequest, dict 1663 ] = None, 1664 *, 1665 name: str = None, 1666 product: str = None, 1667 retry: OptionalRetry = gapic_v1.method.DEFAULT, 1668 timeout: float = None, 1669 metadata: Sequence[Tuple[str, str]] = (), 1670 ) -> None: 1671 r"""Removes a Product from the specified ProductSet. 1672 1673 Possible errors: 1674 1675 - Returns NOT_FOUND If the Product is not found under the 1676 ProductSet. 1677 1678 Args: 1679 request (Union[google.cloud.vision_v1p3beta1.types.RemoveProductFromProductSetRequest, dict]): 1680 The request object. Request message for the 1681 `RemoveProductFromProductSet` method. 1682 name (:class:`str`): 1683 Required. The resource name for the ProductSet to 1684 modify. 1685 1686 Format is: 1687 ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` 1688 1689 This corresponds to the ``name`` field 1690 on the ``request`` instance; if ``request`` is provided, this 1691 should not be set. 1692 product (:class:`str`): 1693 Required. The resource name for the Product to be 1694 removed from this ProductSet. 1695 1696 Format is: 1697 ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` 1698 1699 This corresponds to the ``product`` field 1700 on the ``request`` instance; if ``request`` is provided, this 1701 should not be set. 1702 retry (google.api_core.retry.Retry): Designation of what errors, if any, 1703 should be retried. 1704 timeout (float): The timeout for this request. 1705 metadata (Sequence[Tuple[str, str]]): Strings which should be 1706 sent along with the request as metadata. 1707 """ 1708 # Create or coerce a protobuf request object. 1709 # Sanity check: If we got a request object, we should *not* have 1710 # gotten any keyword arguments that map to the request. 1711 has_flattened_params = any([name, product]) 1712 if request is not None and has_flattened_params: 1713 raise ValueError( 1714 "If the `request` argument is set, then none of " 1715 "the individual field arguments should be set." 1716 ) 1717 1718 request = product_search_service.RemoveProductFromProductSetRequest(request) 1719 1720 # If we have keyword arguments corresponding to fields on the 1721 # request, apply these. 1722 if name is not None: 1723 request.name = name 1724 if product is not None: 1725 request.product = product 1726 1727 # Wrap the RPC method; this adds retry and timeout information, 1728 # and friendly error handling. 1729 rpc = gapic_v1.method_async.wrap_method( 1730 self._client._transport.remove_product_from_product_set, 1731 default_retry=retries.Retry( 1732 initial=0.1, 1733 maximum=60.0, 1734 multiplier=1.3, 1735 predicate=retries.if_exception_type(), 1736 deadline=600.0, 1737 ), 1738 default_timeout=600.0, 1739 client_info=DEFAULT_CLIENT_INFO, 1740 ) 1741 1742 # Certain fields should be provided within the metadata header; 1743 # add these here. 1744 metadata = tuple(metadata) + ( 1745 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), 1746 ) 1747 1748 # Send the request. 1749 await rpc( 1750 request, retry=retry, timeout=timeout, metadata=metadata, 1751 ) 1752 1753 async def list_products_in_product_set( 1754 self, 1755 request: Union[ 1756 product_search_service.ListProductsInProductSetRequest, dict 1757 ] = None, 1758 *, 1759 name: str = None, 1760 retry: OptionalRetry = gapic_v1.method.DEFAULT, 1761 timeout: float = None, 1762 metadata: Sequence[Tuple[str, str]] = (), 1763 ) -> pagers.ListProductsInProductSetAsyncPager: 1764 r"""Lists the Products in a ProductSet, in an unspecified order. If 1765 the ProductSet does not exist, the products field of the 1766 response will be empty. 1767 1768 Possible errors: 1769 1770 - Returns INVALID_ARGUMENT if page_size is greater than 100 or 1771 less than 1. 1772 1773 Args: 1774 request (Union[google.cloud.vision_v1p3beta1.types.ListProductsInProductSetRequest, dict]): 1775 The request object. Request message for the 1776 `ListProductsInProductSet` method. 1777 name (:class:`str`): 1778 Required. The ProductSet resource for which to retrieve 1779 Products. 1780 1781 Format is: 1782 ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` 1783 1784 This corresponds to the ``name`` field 1785 on the ``request`` instance; if ``request`` is provided, this 1786 should not be set. 1787 retry (google.api_core.retry.Retry): Designation of what errors, if any, 1788 should be retried. 1789 timeout (float): The timeout for this request. 1790 metadata (Sequence[Tuple[str, str]]): Strings which should be 1791 sent along with the request as metadata. 1792 1793 Returns: 1794 google.cloud.vision_v1p3beta1.services.product_search.pagers.ListProductsInProductSetAsyncPager: 1795 Response message for the ListProductsInProductSet 1796 method. 1797 1798 Iterating over this object will yield results and 1799 resolve additional pages automatically. 1800 1801 """ 1802 # Create or coerce a protobuf request object. 1803 # Sanity check: If we got a request object, we should *not* have 1804 # gotten any keyword arguments that map to the request. 1805 has_flattened_params = any([name]) 1806 if request is not None and has_flattened_params: 1807 raise ValueError( 1808 "If the `request` argument is set, then none of " 1809 "the individual field arguments should be set." 1810 ) 1811 1812 request = product_search_service.ListProductsInProductSetRequest(request) 1813 1814 # If we have keyword arguments corresponding to fields on the 1815 # request, apply these. 1816 if name is not None: 1817 request.name = name 1818 1819 # Wrap the RPC method; this adds retry and timeout information, 1820 # and friendly error handling. 1821 rpc = gapic_v1.method_async.wrap_method( 1822 self._client._transport.list_products_in_product_set, 1823 default_retry=retries.Retry( 1824 initial=0.1, 1825 maximum=60.0, 1826 multiplier=1.3, 1827 predicate=retries.if_exception_type( 1828 core_exceptions.DeadlineExceeded, 1829 core_exceptions.ServiceUnavailable, 1830 ), 1831 deadline=600.0, 1832 ), 1833 default_timeout=600.0, 1834 client_info=DEFAULT_CLIENT_INFO, 1835 ) 1836 1837 # Certain fields should be provided within the metadata header; 1838 # add these here. 1839 metadata = tuple(metadata) + ( 1840 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), 1841 ) 1842 1843 # Send the request. 1844 response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) 1845 1846 # This method is paged; wrap the response in a pager, which provides 1847 # an `__aiter__` convenience method. 1848 response = pagers.ListProductsInProductSetAsyncPager( 1849 method=rpc, request=request, response=response, metadata=metadata, 1850 ) 1851 1852 # Done; return the response. 1853 return response 1854 1855 async def import_product_sets( 1856 self, 1857 request: Union[product_search_service.ImportProductSetsRequest, dict] = None, 1858 *, 1859 parent: str = None, 1860 input_config: product_search_service.ImportProductSetsInputConfig = None, 1861 retry: OptionalRetry = gapic_v1.method.DEFAULT, 1862 timeout: float = None, 1863 metadata: Sequence[Tuple[str, str]] = (), 1864 ) -> operation_async.AsyncOperation: 1865 r"""Asynchronous API that imports a list of reference images to 1866 specified product sets based on a list of image information. 1867 1868 The [google.longrunning.Operation][google.longrunning.Operation] 1869 API can be used to keep track of the progress and results of the 1870 request. ``Operation.metadata`` contains 1871 ``BatchOperationMetadata``. (progress) ``Operation.response`` 1872 contains ``ImportProductSetsResponse``. (results) 1873 1874 The input source of this method is a csv file on Google Cloud 1875 Storage. For the format of the csv file please see 1876 [ImportProductSetsGcsSource.csv_file_uri][google.cloud.vision.v1p3beta1.ImportProductSetsGcsSource.csv_file_uri]. 1877 1878 Args: 1879 request (Union[google.cloud.vision_v1p3beta1.types.ImportProductSetsRequest, dict]): 1880 The request object. Request message for the 1881 `ImportProductSets` method. 1882 parent (:class:`str`): 1883 Required. The project in which the ProductSets should be 1884 imported. 1885 1886 Format is ``projects/PROJECT_ID/locations/LOC_ID``. 1887 1888 This corresponds to the ``parent`` field 1889 on the ``request`` instance; if ``request`` is provided, this 1890 should not be set. 1891 input_config (:class:`google.cloud.vision_v1p3beta1.types.ImportProductSetsInputConfig`): 1892 Required. The input content for the 1893 list of requests. 1894 1895 This corresponds to the ``input_config`` field 1896 on the ``request`` instance; if ``request`` is provided, this 1897 should not be set. 1898 retry (google.api_core.retry.Retry): Designation of what errors, if any, 1899 should be retried. 1900 timeout (float): The timeout for this request. 1901 metadata (Sequence[Tuple[str, str]]): Strings which should be 1902 sent along with the request as metadata. 1903 1904 Returns: 1905 google.api_core.operation_async.AsyncOperation: 1906 An object representing a long-running operation. 1907 1908 The result type for the operation will be 1909 :class:`google.cloud.vision_v1p3beta1.types.ImportProductSetsResponse` 1910 Response message for the ImportProductSets method. 1911 1912 This message is returned by the 1913 [google.longrunning.Operations.GetOperation][google.longrunning.Operations.GetOperation] 1914 method in the returned 1915 [google.longrunning.Operation.response][google.longrunning.Operation.response] 1916 field. 1917 1918 """ 1919 # Create or coerce a protobuf request object. 1920 # Sanity check: If we got a request object, we should *not* have 1921 # gotten any keyword arguments that map to the request. 1922 has_flattened_params = any([parent, input_config]) 1923 if request is not None and has_flattened_params: 1924 raise ValueError( 1925 "If the `request` argument is set, then none of " 1926 "the individual field arguments should be set." 1927 ) 1928 1929 request = product_search_service.ImportProductSetsRequest(request) 1930 1931 # If we have keyword arguments corresponding to fields on the 1932 # request, apply these. 1933 if parent is not None: 1934 request.parent = parent 1935 if input_config is not None: 1936 request.input_config = input_config 1937 1938 # Wrap the RPC method; this adds retry and timeout information, 1939 # and friendly error handling. 1940 rpc = gapic_v1.method_async.wrap_method( 1941 self._client._transport.import_product_sets, 1942 default_retry=retries.Retry( 1943 initial=0.1, 1944 maximum=60.0, 1945 multiplier=1.3, 1946 predicate=retries.if_exception_type(), 1947 deadline=600.0, 1948 ), 1949 default_timeout=600.0, 1950 client_info=DEFAULT_CLIENT_INFO, 1951 ) 1952 1953 # Certain fields should be provided within the metadata header; 1954 # add these here. 1955 metadata = tuple(metadata) + ( 1956 gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), 1957 ) 1958 1959 # Send the request. 1960 response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) 1961 1962 # Wrap the response in an operation future. 1963 response = operation_async.from_gapic( 1964 response, 1965 self._client._transport.operations_client, 1966 product_search_service.ImportProductSetsResponse, 1967 metadata_type=product_search_service.BatchOperationMetadata, 1968 ) 1969 1970 # Done; return the response. 1971 return response 1972 1973 async def __aenter__(self): 1974 return self 1975 1976 async def __aexit__(self, exc_type, exc, tb): 1977 await self.transport.close() 1978 1979 1980try: 1981 DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( 1982 gapic_version=pkg_resources.get_distribution("google-cloud-vision",).version, 1983 ) 1984except pkg_resources.DistributionNotFound: 1985 DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() 1986 1987 1988__all__ = ("ProductSearchAsyncClient",) 1989