Skip to content
This repository was archived by the owner on Sep 20, 2023. It is now read-only.

Commit 6c38227

Browse files
feat(v1): exposed GetProcessorType (#446)
* feat: exposed GetProcessorType to v1 PiperOrigin-RevId: 502624243 Source-Link: googleapis/googleapis@bd5f934 Source-Link: https://github.com/googleapis/googleapis-gen/commit/7ae8a3a9755f661ce8989e9dcb145d2dff77d864 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiN2FlOGEzYTk3NTVmNjYxY2U4OTg5ZTlkY2IxNDVkMmRmZjc3ZDg2NCJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 9fc84d2 commit 6c38227

17 files changed

+856
-3
lines changed

google/cloud/documentai/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
FetchProcessorTypesRequest,
5656
FetchProcessorTypesResponse,
5757
GetProcessorRequest,
58+
GetProcessorTypeRequest,
5859
GetProcessorVersionRequest,
5960
HumanReviewStatus,
6061
ListProcessorsRequest,
@@ -116,6 +117,7 @@
116117
"FetchProcessorTypesRequest",
117118
"FetchProcessorTypesResponse",
118119
"GetProcessorRequest",
120+
"GetProcessorTypeRequest",
119121
"GetProcessorVersionRequest",
120122
"HumanReviewStatus",
121123
"ListProcessorsRequest",

google/cloud/documentai_v1/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
FetchProcessorTypesRequest,
5454
FetchProcessorTypesResponse,
5555
GetProcessorRequest,
56+
GetProcessorTypeRequest,
5657
GetProcessorVersionRequest,
5758
HumanReviewStatus,
5859
ListProcessorsRequest,
@@ -112,6 +113,7 @@
112113
"GcsDocuments",
113114
"GcsPrefix",
114115
"GetProcessorRequest",
116+
"GetProcessorTypeRequest",
115117
"GetProcessorVersionRequest",
116118
"HumanReviewStatus",
117119
"ListProcessorTypesRequest",

google/cloud/documentai_v1/gapic_metadata.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@
5555
"get_processor"
5656
]
5757
},
58+
"GetProcessorType": {
59+
"methods": [
60+
"get_processor_type"
61+
]
62+
},
5863
"GetProcessorVersion": {
5964
"methods": [
6065
"get_processor_version"
@@ -145,6 +150,11 @@
145150
"get_processor"
146151
]
147152
},
153+
"GetProcessorType": {
154+
"methods": [
155+
"get_processor_type"
156+
]
157+
},
148158
"GetProcessorVersion": {
149159
"methods": [
150160
"get_processor_version"

google/cloud/documentai_v1/services/document_processor_service/async_client.py

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
except AttributeError: # pragma: NO COVER
4343
OptionalRetry = Union[retries.Retry, object] # type: ignore
4444

45+
from google.api import launch_stage_pb2 # type: ignore
4546
from google.api_core import operation # type: ignore
4647
from google.api_core import operation_async # type: ignore
4748
from google.cloud.location import locations_pb2 # type: ignore
@@ -746,6 +747,111 @@ async def sample_list_processor_types():
746747
# Done; return the response.
747748
return response
748749

750+
async def get_processor_type(
751+
self,
752+
request: Optional[
753+
Union[document_processor_service.GetProcessorTypeRequest, dict]
754+
] = None,
755+
*,
756+
name: Optional[str] = None,
757+
retry: OptionalRetry = gapic_v1.method.DEFAULT,
758+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
759+
metadata: Sequence[Tuple[str, str]] = (),
760+
) -> processor_type.ProcessorType:
761+
r"""Gets a processor type detail.
762+
763+
.. code-block:: python
764+
765+
# This snippet has been automatically generated and should be regarded as a
766+
# code template only.
767+
# It will require modifications to work:
768+
# - It may require correct/in-range values for request initialization.
769+
# - It may require specifying regional endpoints when creating the service
770+
# client as shown in:
771+
# https://googleapis.dev/python/google-api-core/latest/client_options.html
772+
from google.cloud import documentai_v1
773+
774+
async def sample_get_processor_type():
775+
# Create a client
776+
client = documentai_v1.DocumentProcessorServiceAsyncClient()
777+
778+
# Initialize request argument(s)
779+
request = documentai_v1.GetProcessorTypeRequest(
780+
name="name_value",
781+
)
782+
783+
# Make the request
784+
response = await client.get_processor_type(request=request)
785+
786+
# Handle the response
787+
print(response)
788+
789+
Args:
790+
request (Optional[Union[google.cloud.documentai_v1.types.GetProcessorTypeRequest, dict]]):
791+
The request object. Request message for get processor.
792+
name (:class:`str`):
793+
Required. The processor type resource
794+
name.
795+
796+
This corresponds to the ``name`` field
797+
on the ``request`` instance; if ``request`` is provided, this
798+
should not be set.
799+
retry (google.api_core.retry.Retry): Designation of what errors, if any,
800+
should be retried.
801+
timeout (float): The timeout for this request.
802+
metadata (Sequence[Tuple[str, str]]): Strings which should be
803+
sent along with the request as metadata.
804+
805+
Returns:
806+
google.cloud.documentai_v1.types.ProcessorType:
807+
A processor type is responsible for
808+
performing a certain document
809+
understanding task on a certain type of
810+
document.
811+
812+
"""
813+
# Create or coerce a protobuf request object.
814+
# Quick check: If we got a request object, we should *not* have
815+
# gotten any keyword arguments that map to the request.
816+
has_flattened_params = any([name])
817+
if request is not None and has_flattened_params:
818+
raise ValueError(
819+
"If the `request` argument is set, then none of "
820+
"the individual field arguments should be set."
821+
)
822+
823+
request = document_processor_service.GetProcessorTypeRequest(request)
824+
825+
# If we have keyword arguments corresponding to fields on the
826+
# request, apply these.
827+
if name is not None:
828+
request.name = name
829+
830+
# Wrap the RPC method; this adds retry and timeout information,
831+
# and friendly error handling.
832+
rpc = gapic_v1.method_async.wrap_method(
833+
self._client._transport.get_processor_type,
834+
default_timeout=None,
835+
client_info=DEFAULT_CLIENT_INFO,
836+
)
837+
838+
# Certain fields should be provided within the metadata header;
839+
# add these here.
840+
metadata = tuple(metadata) + (
841+
gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
842+
)
843+
844+
# Send the request.
845+
response = await rpc(
846+
request,
847+
retry=retry,
848+
timeout=timeout,
849+
metadata=metadata,
850+
)
851+
852+
# Done; return the response.
853+
return response
854+
749855
async def list_processors(
750856
self,
751857
request: Optional[

google/cloud/documentai_v1/services/document_processor_service/client.py

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
except AttributeError: # pragma: NO COVER
4747
OptionalRetry = Union[retries.Retry, object] # type: ignore
4848

49+
from google.api import launch_stage_pb2 # type: ignore
4950
from google.api_core import operation # type: ignore
5051
from google.api_core import operation_async # type: ignore
5152
from google.cloud.location import locations_pb2 # type: ignore
@@ -1000,6 +1001,111 @@ def sample_list_processor_types():
10001001
# Done; return the response.
10011002
return response
10021003

1004+
def get_processor_type(
1005+
self,
1006+
request: Optional[
1007+
Union[document_processor_service.GetProcessorTypeRequest, dict]
1008+
] = None,
1009+
*,
1010+
name: Optional[str] = None,
1011+
retry: OptionalRetry = gapic_v1.method.DEFAULT,
1012+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1013+
metadata: Sequence[Tuple[str, str]] = (),
1014+
) -> processor_type.ProcessorType:
1015+
r"""Gets a processor type detail.
1016+
1017+
.. code-block:: python
1018+
1019+
# This snippet has been automatically generated and should be regarded as a
1020+
# code template only.
1021+
# It will require modifications to work:
1022+
# - It may require correct/in-range values for request initialization.
1023+
# - It may require specifying regional endpoints when creating the service
1024+
# client as shown in:
1025+
# https://googleapis.dev/python/google-api-core/latest/client_options.html
1026+
from google.cloud import documentai_v1
1027+
1028+
def sample_get_processor_type():
1029+
# Create a client
1030+
client = documentai_v1.DocumentProcessorServiceClient()
1031+
1032+
# Initialize request argument(s)
1033+
request = documentai_v1.GetProcessorTypeRequest(
1034+
name="name_value",
1035+
)
1036+
1037+
# Make the request
1038+
response = client.get_processor_type(request=request)
1039+
1040+
# Handle the response
1041+
print(response)
1042+
1043+
Args:
1044+
request (Union[google.cloud.documentai_v1.types.GetProcessorTypeRequest, dict]):
1045+
The request object. Request message for get processor.
1046+
name (str):
1047+
Required. The processor type resource
1048+
name.
1049+
1050+
This corresponds to the ``name`` field
1051+
on the ``request`` instance; if ``request`` is provided, this
1052+
should not be set.
1053+
retry (google.api_core.retry.Retry): Designation of what errors, if any,
1054+
should be retried.
1055+
timeout (float): The timeout for this request.
1056+
metadata (Sequence[Tuple[str, str]]): Strings which should be
1057+
sent along with the request as metadata.
1058+
1059+
Returns:
1060+
google.cloud.documentai_v1.types.ProcessorType:
1061+
A processor type is responsible for
1062+
performing a certain document
1063+
understanding task on a certain type of
1064+
document.
1065+
1066+
"""
1067+
# Create or coerce a protobuf request object.
1068+
# Quick check: If we got a request object, we should *not* have
1069+
# gotten any keyword arguments that map to the request.
1070+
has_flattened_params = any([name])
1071+
if request is not None and has_flattened_params:
1072+
raise ValueError(
1073+
"If the `request` argument is set, then none of "
1074+
"the individual field arguments should be set."
1075+
)
1076+
1077+
# Minor optimization to avoid making a copy if the user passes
1078+
# in a document_processor_service.GetProcessorTypeRequest.
1079+
# There's no risk of modifying the input as we've already verified
1080+
# there are no flattened fields.
1081+
if not isinstance(request, document_processor_service.GetProcessorTypeRequest):
1082+
request = document_processor_service.GetProcessorTypeRequest(request)
1083+
# If we have keyword arguments corresponding to fields on the
1084+
# request, apply these.
1085+
if name is not None:
1086+
request.name = name
1087+
1088+
# Wrap the RPC method; this adds retry and timeout information,
1089+
# and friendly error handling.
1090+
rpc = self._transport._wrapped_methods[self._transport.get_processor_type]
1091+
1092+
# Certain fields should be provided within the metadata header;
1093+
# add these here.
1094+
metadata = tuple(metadata) + (
1095+
gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
1096+
)
1097+
1098+
# Send the request.
1099+
response = rpc(
1100+
request,
1101+
retry=retry,
1102+
timeout=timeout,
1103+
metadata=metadata,
1104+
)
1105+
1106+
# Done; return the response.
1107+
return response
1108+
10031109
def list_processors(
10041110
self,
10051111
request: Optional[

google/cloud/documentai_v1/services/document_processor_service/transports/base.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
from google.cloud.documentai_v1.types import document_processor_service
3131
from google.cloud.documentai_v1.types import processor
3232
from google.cloud.documentai_v1.types import processor as gcd_processor
33+
from google.cloud.documentai_v1.types import processor_type
3334

3435
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
3536
gapic_version=package_version.__version__
@@ -166,6 +167,11 @@ def _prep_wrapped_messages(self, client_info):
166167
default_timeout=None,
167168
client_info=client_info,
168169
),
170+
self.get_processor_type: gapic_v1.method.wrap_method(
171+
self.get_processor_type,
172+
default_timeout=None,
173+
client_info=client_info,
174+
),
169175
self.list_processors: gapic_v1.method.wrap_method(
170176
self.list_processors,
171177
default_timeout=None,
@@ -302,6 +308,15 @@ def list_processor_types(
302308
]:
303309
raise NotImplementedError()
304310

311+
@property
312+
def get_processor_type(
313+
self,
314+
) -> Callable[
315+
[document_processor_service.GetProcessorTypeRequest],
316+
Union[processor_type.ProcessorType, Awaitable[processor_type.ProcessorType]],
317+
]:
318+
raise NotImplementedError()
319+
305320
@property
306321
def list_processors(
307322
self,

google/cloud/documentai_v1/services/document_processor_service/transports/grpc.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from google.cloud.documentai_v1.types import document_processor_service
2828
from google.cloud.documentai_v1.types import processor
2929
from google.cloud.documentai_v1.types import processor as gcd_processor
30+
from google.cloud.documentai_v1.types import processor_type
3031

3132
from .base import DEFAULT_CLIENT_INFO, DocumentProcessorServiceTransport
3233

@@ -368,6 +369,35 @@ def list_processor_types(
368369
)
369370
return self._stubs["list_processor_types"]
370371

372+
@property
373+
def get_processor_type(
374+
self,
375+
) -> Callable[
376+
[document_processor_service.GetProcessorTypeRequest],
377+
processor_type.ProcessorType,
378+
]:
379+
r"""Return a callable for the get processor type method over gRPC.
380+
381+
Gets a processor type detail.
382+
383+
Returns:
384+
Callable[[~.GetProcessorTypeRequest],
385+
~.ProcessorType]:
386+
A function that, when called, will call the underlying RPC
387+
on the server.
388+
"""
389+
# Generate a "stub function" on-the-fly which will actually make
390+
# the request.
391+
# gRPC handles serialization and deserialization, so we just need
392+
# to pass in the functions for each.
393+
if "get_processor_type" not in self._stubs:
394+
self._stubs["get_processor_type"] = self.grpc_channel.unary_unary(
395+
"/google.cloud.documentai.v1.DocumentProcessorService/GetProcessorType",
396+
request_serializer=document_processor_service.GetProcessorTypeRequest.serialize,
397+
response_deserializer=processor_type.ProcessorType.deserialize,
398+
)
399+
return self._stubs["get_processor_type"]
400+
371401
@property
372402
def list_processors(
373403
self,

0 commit comments

Comments
 (0)