Skip to content
Permalink
Browse files
feat: add from_service_account_info factory and fix sphinx identifiers (
#80)

feat: add 'from_service_account_info' factory to clients
fix: fix sphinx identifiers
PiperOrigin-RevId: 350246057

Source-Author: Google APIs <noreply@google.com>
Source-Date: Tue Jan 5 16:44:11 2021 -0800
Source-Repo: googleapis/googleapis
Source-Sha: 520682435235d9c503983a360a2090025aa47cd1
Source-Link: googleapis/googleapis@5206824
  • Loading branch information
yoshi-automation committed Jan 6, 2021
1 parent 33dc258 commit d6f183a696b211c6d29bc28e9bbd0a8537f65577
@@ -15,4 +15,4 @@ exclude_lines =
# This is added at the module level as a safeguard for if someone
# generates the code and tries to run it without pip installing. This
# makes it virtually impossible to test properly.
except pkg_resources.DistributionNotFound
except pkg_resources.DistributionNotFound
@@ -0,0 +1,6 @@
DocumentUnderstandingService
----------------------------------------------

.. automodule:: google.cloud.documentai_v1beta2.services.document_understanding_service
:members:
:inherited-members:
@@ -1,6 +1,6 @@
Services for Google Cloud Documentai v1beta2 API
================================================
.. toctree::
:maxdepth: 2

.. automodule:: google.cloud.documentai_v1beta2.services.document_understanding_service
:members:
:inherited-members:
document_understanding_service
@@ -3,4 +3,5 @@ Types for Google Cloud Documentai v1beta2 API

.. automodule:: google.cloud.documentai_v1beta2.types
:members:
:undoc-members:
:show-inheritance:
@@ -0,0 +1,6 @@
DocumentProcessorService
------------------------------------------

.. automodule:: google.cloud.documentai_v1beta3.services.document_processor_service
:members:
:inherited-members:
@@ -1,6 +1,6 @@
Services for Google Cloud Documentai v1beta3 API
================================================
.. toctree::
:maxdepth: 2

.. automodule:: google.cloud.documentai_v1beta3.services.document_processor_service
:members:
:inherited-members:
document_processor_service
@@ -3,4 +3,5 @@ Types for Google Cloud Documentai v1beta3 API

.. automodule:: google.cloud.documentai_v1beta3.types
:members:
:undoc-members:
:show-inheritance:
@@ -85,6 +85,9 @@ class DocumentUnderstandingServiceAsyncClient:
DocumentUnderstandingServiceClient.parse_common_location_path
)

from_service_account_info = (
DocumentUnderstandingServiceClient.from_service_account_info
)
from_service_account_file = (
DocumentUnderstandingServiceClient.from_service_account_file
)
@@ -165,13 +168,14 @@ async def batch_process_documents(
written to Cloud Storage as JSON in the [Document] format.
Args:
request (:class:`~.document_understanding.BatchProcessDocumentsRequest`):
request (:class:`google.cloud.documentai_v1beta2.types.BatchProcessDocumentsRequest`):
The request object. Request to batch process documents
as an asynchronous operation. The output is written to
Cloud Storage as JSON in the [Document] format.
requests (:class:`Sequence[~.document_understanding.ProcessDocumentRequest]`):
requests (:class:`Sequence[google.cloud.documentai_v1beta2.types.ProcessDocumentRequest]`):
Required. Individual requests for
each document.
This corresponds to the ``requests`` field
on the ``request`` instance; if ``request`` is provided, this
should not be set.
@@ -183,14 +187,11 @@ async def batch_process_documents(
sent along with the request as metadata.
Returns:
~.operation_async.AsyncOperation:
google.api_core.operation_async.AsyncOperation:
An object representing a long-running operation.
The result type for the operation will be
:class:``~.document_understanding.BatchProcessDocumentsResponse``:
Response to an batch document processing request. This
is returned in the LRO Operation after the operation is
complete.
The result type for the operation will be :class:`google.cloud.documentai_v1beta2.types.BatchProcessDocumentsResponse` Response to an batch document processing request. This is returned in
the LRO Operation after the operation is complete.
"""
# Create or coerce a protobuf request object.
@@ -258,7 +259,7 @@ async def process_document(
r"""Processes a single document.
Args:
request (:class:`~.document_understanding.ProcessDocumentRequest`):
request (:class:`google.cloud.documentai_v1beta2.types.ProcessDocumentRequest`):
The request object. Request to process one document.
retry (google.api_core.retry.Retry): Designation of what errors, if any,
@@ -268,7 +269,7 @@ async def process_document(
sent along with the request as metadata.
Returns:
~.document.Document:
google.cloud.documentai_v1beta2.types.Document:
Document represents the canonical
document resource in Document
Understanding AI. It is an interchange
@@ -122,6 +122,22 @@ def _get_default_mtls_endpoint(api_endpoint):
DEFAULT_ENDPOINT
)

@classmethod
def from_service_account_info(cls, info: dict, *args, **kwargs):
"""Creates an instance of this client using the provided credentials info.
Args:
info (dict): The service account private key info.
args: Additional arguments to pass to the constructor.
kwargs: Additional arguments to pass to the constructor.
Returns:
DocumentUnderstandingServiceClient: The constructed client.
"""
credentials = service_account.Credentials.from_service_account_info(info)
kwargs["credentials"] = credentials
return cls(*args, **kwargs)

@classmethod
def from_service_account_file(cls, filename: str, *args, **kwargs):
"""Creates an instance of this client using the provided credentials
@@ -134,7 +150,7 @@ def from_service_account_file(cls, filename: str, *args, **kwargs):
kwargs: Additional arguments to pass to the constructor.
Returns:
{@api.name}: The constructed client.
DocumentUnderstandingServiceClient: The constructed client.
"""
credentials = service_account.Credentials.from_service_account_file(filename)
kwargs["credentials"] = credentials
@@ -226,10 +242,10 @@ def __init__(
credentials identify the application to the service; if none
are specified, the client will attempt to ascertain the
credentials from the environment.
transport (Union[str, ~.DocumentUnderstandingServiceTransport]): The
transport (Union[str, DocumentUnderstandingServiceTransport]): The
transport to use. If set to None, a transport is chosen
automatically.
client_options (client_options_lib.ClientOptions): Custom options for the
client_options (google.api_core.client_options.ClientOptions): Custom options for the
client. It won't take effect if a ``transport`` instance is provided.
(1) The ``api_endpoint`` property can be used to override the
default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT
@@ -340,13 +356,14 @@ def batch_process_documents(
written to Cloud Storage as JSON in the [Document] format.
Args:
request (:class:`~.document_understanding.BatchProcessDocumentsRequest`):
request (google.cloud.documentai_v1beta2.types.BatchProcessDocumentsRequest):
The request object. Request to batch process documents
as an asynchronous operation. The output is written to
Cloud Storage as JSON in the [Document] format.
requests (:class:`Sequence[~.document_understanding.ProcessDocumentRequest]`):
requests (Sequence[google.cloud.documentai_v1beta2.types.ProcessDocumentRequest]):
Required. Individual requests for
each document.
This corresponds to the ``requests`` field
on the ``request`` instance; if ``request`` is provided, this
should not be set.
@@ -358,14 +375,11 @@ def batch_process_documents(
sent along with the request as metadata.
Returns:
~.operation.Operation:
google.api_core.operation.Operation:
An object representing a long-running operation.
The result type for the operation will be
:class:``~.document_understanding.BatchProcessDocumentsResponse``:
Response to an batch document processing request. This
is returned in the LRO Operation after the operation is
complete.
The result type for the operation will be :class:`google.cloud.documentai_v1beta2.types.BatchProcessDocumentsResponse` Response to an batch document processing request. This is returned in
the LRO Operation after the operation is complete.
"""
# Create or coerce a protobuf request object.
@@ -426,7 +440,7 @@ def process_document(
r"""Processes a single document.
Args:
request (:class:`~.document_understanding.ProcessDocumentRequest`):
request (google.cloud.documentai_v1beta2.types.ProcessDocumentRequest):
The request object. Request to process one document.
retry (google.api_core.retry.Retry): Designation of what errors, if any,
@@ -436,7 +450,7 @@ def process_document(
sent along with the request as metadata.
Returns:
~.document.Document:
google.cloud.documentai_v1beta2.types.Document:
Document represents the canonical
document resource in Document
Understanding AI. It is an interchange

0 comments on commit d6f183a

Please sign in to comment.