diff --git a/.github/.OwlBot.lock.yaml b/.github/.OwlBot.lock.yaml index eecb84c2..44c78f7c 100644 --- a/.github/.OwlBot.lock.yaml +++ b/.github/.OwlBot.lock.yaml @@ -1,3 +1,16 @@ +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. docker: image: gcr.io/cloud-devrel-public-resources/owlbot-python:latest - digest: sha256:ae600f36b6bc972b368367b6f83a1d91ec2c82a4a116b383d67d547c56fe6de3 + digest: sha256:4e1991042fe54b991db9ca17c8fb386e61b22fe4d1472a568bf0fcac85dcf5d3 diff --git a/.github/sync-repo-settings.yaml b/.github/sync-repo-settings.yaml index 3e98ae70..37438d33 100644 --- a/.github/sync-repo-settings.yaml +++ b/.github/sync-repo-settings.yaml @@ -10,6 +10,5 @@ branchProtectionRules: - 'Kokoro' - 'cla/google' - 'Samples - Lint' - - 'Samples - Python 3.6' - 'Samples - Python 3.7' - 'Samples - Python 3.8' diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml new file mode 100644 index 00000000..b46d7305 --- /dev/null +++ b/.github/workflows/docs.yml @@ -0,0 +1,38 @@ +on: + pull_request: + branches: + - main +name: docs +jobs: + docs: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Setup Python + uses: actions/setup-python@v3 + with: + python-version: "3.10" + - name: Install nox + run: | + python -m pip install --upgrade setuptools pip wheel + python -m pip install nox + - name: Run docs + run: | + nox -s docs + docfx: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Setup Python + uses: actions/setup-python@v3 + with: + python-version: "3.10" + - name: Install nox + run: | + python -m pip install --upgrade setuptools pip wheel + python -m pip install nox + - name: Run docfx + run: | + nox -s docfx diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 00000000..f512a496 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,25 @@ +on: + pull_request: + branches: + - main +name: lint +jobs: + lint: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Setup Python + uses: actions/setup-python@v3 + with: + python-version: "3.10" + - name: Install nox + run: | + python -m pip install --upgrade setuptools pip wheel + python -m pip install nox + - name: Run lint + run: | + nox -s lint + - name: Run lint_setup_py + run: | + nox -s lint_setup_py diff --git a/.github/workflows/unittest.yml b/.github/workflows/unittest.yml new file mode 100644 index 00000000..e5be6edb --- /dev/null +++ b/.github/workflows/unittest.yml @@ -0,0 +1,57 @@ +on: + pull_request: + branches: + - main +name: unittest +jobs: + unit: + runs-on: ubuntu-latest + strategy: + matrix: + python: ['3.6', '3.7', '3.8', '3.9', '3.10'] + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Setup Python + uses: actions/setup-python@v3 + with: + python-version: ${{ matrix.python }} + - name: Install nox + run: | + python -m pip install --upgrade setuptools pip wheel + python -m pip install nox + - name: Run unit tests + env: + COVERAGE_FILE: .coverage-${{ matrix.python }} + run: | + nox -s unit-${{ matrix.python }} + - name: Upload coverage results + uses: actions/upload-artifact@v3 + with: + name: coverage-artifacts + path: .coverage-${{ matrix.python }} + + cover: + runs-on: ubuntu-latest + needs: + - unit + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Setup Python + uses: actions/setup-python@v3 + with: + python-version: "3.10" + - name: Install coverage + run: | + python -m pip install --upgrade setuptools pip wheel + python -m pip install coverage + - name: Download coverage results + uses: actions/download-artifact@v3 + with: + name: coverage-artifacts + path: .coverage-results/ + - name: Report coverage results + run: | + coverage combine .coverage-results/.coverage* + coverage report --show-missing --fail-under=100 diff --git a/CHANGELOG.md b/CHANGELOG.md index 12d4a184..e44b5a67 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,23 @@ # Changelog +## [1.3.0](https://github.com/googleapis/python-documentai/compare/v1.2.1...v1.3.0) (2022-03-05) + + +### Features + +* add `symbols` field, and auto-format comments ([#277](https://github.com/googleapis/python-documentai/issues/277)) ([ca016dd](https://github.com/googleapis/python-documentai/commit/ca016dd0cfaa5df0e4ced218423245a5ba2eb669)) +* add api key support ([#267](https://github.com/googleapis/python-documentai/issues/267)) ([061eb45](https://github.com/googleapis/python-documentai/commit/061eb454d3fafa405f90d6b73240b4c130db845f)) +* add question_id field in ReviewDocumentOperationMetadata ([#269](https://github.com/googleapis/python-documentai/issues/269)) ([1c61b73](https://github.com/googleapis/python-documentai/commit/1c61b737ce02185bad04c7bd58c12e6772b8569f)) +* add question_id field in ReviewDocumentOperationMetadata ([#273](https://github.com/googleapis/python-documentai/issues/273)) ([530f2ba](https://github.com/googleapis/python-documentai/commit/530f2ba88cc5abc8f888722246a3610adca001a9)) + + +### Bug Fixes + +* **deps:** require google-api-core>=1.31.5, >=2.3.2 ([#285](https://github.com/googleapis/python-documentai/issues/285)) ([573deee](https://github.com/googleapis/python-documentai/commit/573deee85e91a7e0a02c411703467e89be36c734)) +* **deps:** require proto-plus>=1.15.0 ([573deee](https://github.com/googleapis/python-documentai/commit/573deee85e91a7e0a02c411703467e89be36c734)) +* remove libcst from setup_requires ([#276](https://github.com/googleapis/python-documentai/issues/276)) ([56c96e4](https://github.com/googleapis/python-documentai/commit/56c96e4cd3427321dac0e8c979aa4e34eefa0b12)) +* resolve DuplicateCredentialArgs error when using credentials_file ([530f2ba](https://github.com/googleapis/python-documentai/commit/530f2ba88cc5abc8f888722246a3610adca001a9)) + ### [1.2.1](https://github.com/googleapis/python-documentai/compare/v1.2.0...v1.2.1) (2022-01-17) diff --git a/documentai-v1-py.tar.gz b/documentai-v1-py.tar.gz deleted file mode 100644 index e69de29b..00000000 diff --git a/google/cloud/documentai/__init__.py b/google/cloud/documentai/__init__.py index c550d366..0687f19b 100644 --- a/google/cloud/documentai/__init__.py +++ b/google/cloud/documentai/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/documentai_v1/__init__.py b/google/cloud/documentai_v1/__init__.py index 5b1d91b3..2b683bd7 100644 --- a/google/cloud/documentai_v1/__init__.py +++ b/google/cloud/documentai_v1/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/documentai_v1/services/__init__.py b/google/cloud/documentai_v1/services/__init__.py index 4de65971..e8e1c384 100644 --- a/google/cloud/documentai_v1/services/__init__.py +++ b/google/cloud/documentai_v1/services/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/documentai_v1/services/document_processor_service/__init__.py b/google/cloud/documentai_v1/services/document_processor_service/__init__.py index 900ba543..d454baaa 100644 --- a/google/cloud/documentai_v1/services/document_processor_service/__init__.py +++ b/google/cloud/documentai_v1/services/document_processor_service/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/documentai_v1/services/document_processor_service/async_client.py b/google/cloud/documentai_v1/services/document_processor_service/async_client.py index 953934d2..d1bf70a6 100644 --- a/google/cloud/documentai_v1/services/document_processor_service/async_client.py +++ b/google/cloud/documentai_v1/services/document_processor_service/async_client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,7 +16,7 @@ from collections import OrderedDict import functools import re -from typing import Dict, Sequence, Tuple, Type, Union +from typing import Dict, Optional, Sequence, Tuple, Type, Union import pkg_resources from google.api_core.client_options import ClientOptions @@ -125,6 +125,42 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): from_service_account_json = from_service_account_file + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + return DocumentProcessorServiceClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore + @property def transport(self) -> DocumentProcessorServiceTransport: """Returns the transport used by the client instance. @@ -197,6 +233,29 @@ async def process_document( ) -> document_processor_service.ProcessResponse: r"""Processes a single document. + .. code-block:: python + + from google.cloud import documentai_v1 + + def sample_process_document(): + # Create a client + client = documentai_v1.DocumentProcessorServiceClient() + + # Initialize request argument(s) + inline_document = documentai_v1.Document() + inline_document.uri = "uri_value" + + request = documentai_v1.ProcessRequest( + inline_document=inline_document, + name="name_value", + ) + + # Make the request + response = client.process_document(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.documentai_v1.types.ProcessRequest, dict]): The request object. Request message for the process @@ -221,7 +280,7 @@ async def process_document( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: @@ -279,6 +338,30 @@ async def batch_process_documents( r"""LRO endpoint to batch process many documents. The output is written to Cloud Storage as JSON in the [Document] format. + + .. code-block:: python + + from google.cloud import documentai_v1 + + def sample_batch_process_documents(): + # Create a client + client = documentai_v1.DocumentProcessorServiceClient() + + # Initialize request argument(s) + request = documentai_v1.BatchProcessRequest( + name="name_value", + ) + + # Make the request + operation = client.batch_process_documents(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.documentai_v1.types.BatchProcessRequest, dict]): The request object. Request message for batch process @@ -306,7 +389,7 @@ async def batch_process_documents( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: @@ -372,6 +455,34 @@ async def review_document( r"""Send a document for Human Review. The input document should be processed by the specified processor. + + .. code-block:: python + + from google.cloud import documentai_v1 + + def sample_review_document(): + # Create a client + client = documentai_v1.DocumentProcessorServiceClient() + + # Initialize request argument(s) + inline_document = documentai_v1.Document() + inline_document.uri = "uri_value" + + request = documentai_v1.ReviewDocumentRequest( + inline_document=inline_document, + human_review_config="human_review_config_value", + ) + + # Make the request + operation = client.review_document(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.documentai_v1.types.ReviewDocumentRequest, dict]): The request object. Request message for review document @@ -400,7 +511,7 @@ async def review_document( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([human_review_config]) if request is not None and has_flattened_params: diff --git a/google/cloud/documentai_v1/services/document_processor_service/client.py b/google/cloud/documentai_v1/services/document_processor_service/client.py index b5d44355..ed696473 100644 --- a/google/cloud/documentai_v1/services/document_processor_service/client.py +++ b/google/cloud/documentai_v1/services/document_processor_service/client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -259,6 +259,73 @@ def parse_common_location_path(path: str) -> Dict[str, str]: m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)$", path) return m.groupdict() if m else {} + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[client_options_lib.ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + if client_options is None: + client_options = client_options_lib.ClientOptions() + use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") + if use_client_cert not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" + ) + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + + # Figure out the client cert source to use. + client_cert_source = None + if use_client_cert == "true": + if client_options.client_cert_source: + client_cert_source = client_options.client_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + + # Figure out which api endpoint to use. + if client_options.api_endpoint is not None: + api_endpoint = client_options.api_endpoint + elif use_mtls_endpoint == "always" or ( + use_mtls_endpoint == "auto" and client_cert_source + ): + api_endpoint = cls.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = cls.DEFAULT_ENDPOINT + + return api_endpoint, client_cert_source + def __init__( self, *, @@ -309,57 +376,22 @@ def __init__( if client_options is None: client_options = client_options_lib.ClientOptions() - # Create SSL credentials for mutual TLS if needed. - if os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") not in ( - "true", - "false", - ): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" - ) - use_client_cert = ( - os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") == "true" + api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( + client_options ) - client_cert_source_func = None - is_mtls = False - if use_client_cert: - if client_options.client_cert_source: - is_mtls = True - client_cert_source_func = client_options.client_cert_source - else: - is_mtls = mtls.has_default_client_cert_source() - if is_mtls: - client_cert_source_func = mtls.default_client_cert_source() - else: - client_cert_source_func = None - - # Figure out which api endpoint to use. - if client_options.api_endpoint is not None: - api_endpoint = client_options.api_endpoint - else: - use_mtls_env = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") - if use_mtls_env == "never": - api_endpoint = self.DEFAULT_ENDPOINT - elif use_mtls_env == "always": - api_endpoint = self.DEFAULT_MTLS_ENDPOINT - elif use_mtls_env == "auto": - if is_mtls: - api_endpoint = self.DEFAULT_MTLS_ENDPOINT - else: - api_endpoint = self.DEFAULT_ENDPOINT - else: - raise MutualTLSChannelError( - "Unsupported GOOGLE_API_USE_MTLS_ENDPOINT value. Accepted " - "values: never, auto, always" - ) + api_key_value = getattr(client_options, "api_key", None) + if api_key_value and credentials: + raise ValueError( + "client_options.api_key and credentials are mutually exclusive" + ) # Save or instantiate the transport. # Ordinarily, we provide the transport, but allowing a custom transport # instance provides an extensibility point for unusual situations. if isinstance(transport, DocumentProcessorServiceTransport): # transport is a DocumentProcessorServiceTransport instance. - if credentials or client_options.credentials_file: + if credentials or client_options.credentials_file or api_key_value: raise ValueError( "When providing a transport instance, " "provide its credentials directly." @@ -371,6 +403,15 @@ def __init__( ) self._transport = transport else: + import google.auth._default # type: ignore + + if api_key_value and hasattr( + google.auth._default, "get_api_key_credentials" + ): + credentials = google.auth._default.get_api_key_credentials( + api_key_value + ) + Transport = type(self).get_transport_class(transport) self._transport = Transport( credentials=credentials, @@ -394,6 +435,29 @@ def process_document( ) -> document_processor_service.ProcessResponse: r"""Processes a single document. + .. code-block:: python + + from google.cloud import documentai_v1 + + def sample_process_document(): + # Create a client + client = documentai_v1.DocumentProcessorServiceClient() + + # Initialize request argument(s) + inline_document = documentai_v1.Document() + inline_document.uri = "uri_value" + + request = documentai_v1.ProcessRequest( + inline_document=inline_document, + name="name_value", + ) + + # Make the request + response = client.process_document(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.documentai_v1.types.ProcessRequest, dict]): The request object. Request message for the process @@ -418,7 +482,7 @@ def process_document( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: @@ -466,6 +530,30 @@ def batch_process_documents( r"""LRO endpoint to batch process many documents. The output is written to Cloud Storage as JSON in the [Document] format. + + .. code-block:: python + + from google.cloud import documentai_v1 + + def sample_batch_process_documents(): + # Create a client + client = documentai_v1.DocumentProcessorServiceClient() + + # Initialize request argument(s) + request = documentai_v1.BatchProcessRequest( + name="name_value", + ) + + # Make the request + operation = client.batch_process_documents(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.documentai_v1.types.BatchProcessRequest, dict]): The request object. Request message for batch process @@ -493,7 +581,7 @@ def batch_process_documents( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: @@ -549,6 +637,34 @@ def review_document( r"""Send a document for Human Review. The input document should be processed by the specified processor. + + .. code-block:: python + + from google.cloud import documentai_v1 + + def sample_review_document(): + # Create a client + client = documentai_v1.DocumentProcessorServiceClient() + + # Initialize request argument(s) + inline_document = documentai_v1.Document() + inline_document.uri = "uri_value" + + request = documentai_v1.ReviewDocumentRequest( + inline_document=inline_document, + human_review_config="human_review_config_value", + ) + + # Make the request + operation = client.review_document(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.documentai_v1.types.ReviewDocumentRequest, dict]): The request object. Request message for review document @@ -577,7 +693,7 @@ def review_document( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([human_review_config]) if request is not None and has_flattened_params: diff --git a/google/cloud/documentai_v1/services/document_processor_service/transports/__init__.py b/google/cloud/documentai_v1/services/document_processor_service/transports/__init__.py index b9f737af..edfa7d68 100644 --- a/google/cloud/documentai_v1/services/document_processor_service/transports/__init__.py +++ b/google/cloud/documentai_v1/services/document_processor_service/transports/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/documentai_v1/services/document_processor_service/transports/base.py b/google/cloud/documentai_v1/services/document_processor_service/transports/base.py index 2442802b..e6f5168c 100644 --- a/google/cloud/documentai_v1/services/document_processor_service/transports/base.py +++ b/google/cloud/documentai_v1/services/document_processor_service/transports/base.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/documentai_v1/services/document_processor_service/transports/grpc.py b/google/cloud/documentai_v1/services/document_processor_service/transports/grpc.py index 58e02f35..2ab86d83 100644 --- a/google/cloud/documentai_v1/services/document_processor_service/transports/grpc.py +++ b/google/cloud/documentai_v1/services/document_processor_service/transports/grpc.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -165,8 +165,11 @@ def __init__( if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, @@ -239,7 +242,7 @@ def operations_client(self) -> operations_v1.OperationsClient: This property caches on the instance; repeated calls return the same client. """ - # Sanity check: Only create a new client if we do not already have one. + # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsClient(self.grpc_channel) diff --git a/google/cloud/documentai_v1/services/document_processor_service/transports/grpc_asyncio.py b/google/cloud/documentai_v1/services/document_processor_service/transports/grpc_asyncio.py index 0578ce72..759c82fd 100644 --- a/google/cloud/documentai_v1/services/document_processor_service/transports/grpc_asyncio.py +++ b/google/cloud/documentai_v1/services/document_processor_service/transports/grpc_asyncio.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -210,8 +210,11 @@ def __init__( if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, @@ -241,7 +244,7 @@ def operations_client(self) -> operations_v1.OperationsAsyncClient: This property caches on the instance; repeated calls return the same client. """ - # Sanity check: Only create a new client if we do not already have one. + # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsAsyncClient( self.grpc_channel diff --git a/google/cloud/documentai_v1/types/__init__.py b/google/cloud/documentai_v1/types/__init__.py index 677a7bcb..079dd069 100644 --- a/google/cloud/documentai_v1/types/__init__.py +++ b/google/cloud/documentai_v1/types/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/documentai_v1/types/document.py b/google/cloud/documentai_v1/types/document.py index ef8a59ac..904f46e2 100644 --- a/google/cloud/documentai_v1/types/document.py +++ b/google/cloud/documentai_v1/types/document.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -63,8 +63,7 @@ class Document(proto.Message): mime_type (str): An IANA published MIME type (also referred to as media type). For more information, see - https://www.iana.org/assignments/media- - types/media-types.xhtml. + https://www.iana.org/assignments/media-types/media-types.xhtml. text (str): Optional. UTF-8 encoded text in reading order from the document. @@ -225,6 +224,9 @@ class Page(proto.Message): form_fields (Sequence[google.cloud.documentai_v1.types.Document.Page.FormField]): A list of visually detected form fields on the page. + symbols (Sequence[google.cloud.documentai_v1.types.Document.Page.Symbol]): + A list of visually detected symbols on the + page. provenance (google.cloud.documentai_v1.types.Document.Provenance): The history of this page. """ @@ -455,6 +457,26 @@ class Type(proto.Enum): proto.MESSAGE, number=4, message="Document.Provenance", ) + class Symbol(proto.Message): + r"""A detected symbol. + + Attributes: + layout (google.cloud.documentai_v1.types.Document.Page.Layout): + [Layout][google.cloud.documentai.v1.Document.Page.Layout] + for + [Symbol][google.cloud.documentai.v1.Document.Page.Symbol]. + detected_languages (Sequence[google.cloud.documentai_v1.types.Document.Page.DetectedLanguage]): + A list of detected languages together with + confidence. + """ + + layout = proto.Field( + proto.MESSAGE, number=1, message="Document.Page.Layout", + ) + detected_languages = proto.RepeatedField( + proto.MESSAGE, number=2, message="Document.Page.DetectedLanguage", + ) + class VisualElement(proto.Message): r"""Detected non-text visual elements e.g. checkbox, signature etc. on the page. @@ -603,7 +625,7 @@ class DetectedLanguage(proto.Message): language_code (str): The BCP-47 language code, such as "en-US" or "sr-Latn". For more information, see - http://www.unicode.org/reports/tr35/#Unicode_locale_identifier. + https://www.unicode.org/reports/tr35/#Unicode_locale_identifier. confidence (float): Confidence of detected language. Range [0, 1]. """ @@ -644,13 +666,17 @@ class DetectedLanguage(proto.Message): form_fields = proto.RepeatedField( proto.MESSAGE, number=11, message="Document.Page.FormField", ) + symbols = proto.RepeatedField( + proto.MESSAGE, number=12, message="Document.Page.Symbol", + ) provenance = proto.Field( proto.MESSAGE, number=16, message="Document.Provenance", ) class Entity(proto.Message): - r"""A phrase in the text that is a known entity type, such as a - person, an organization, or location. + r"""An entity that could be a phrase in the text or a property + that belongs to the document. It is a known entity type, such as + a person, an organization, or location. Attributes: text_anchor (google.cloud.documentai_v1.types.Document.TextAnchor): @@ -661,7 +687,8 @@ class Entity(proto.Message): Entity type from a schema e.g. ``Address``. mention_text (str): Optional. Text value in the document e.g. - ``1600 Amphitheatre Pkwy``. + ``1600 Amphitheatre Pkwy``. If the entity is not present in + the document, this field will be empty. mention_id (str): Optional. Deprecated. Use ``id`` field instead. confidence (float): @@ -730,10 +757,14 @@ class NormalizedValue(proto.Message): This field is a member of `oneof`_ ``structured_value``. text (str): - Required. Normalized entity value stored as a string. This - field is populated for supported document type (e.g. - Invoice). For some entity types, one of respective - 'structured_value' fields may also be populated. + Optional. An optional field to store a normalized string. + For some entity types, one of respective + ``structured_value`` fields may also be populated. Also not + all the types of ``structured_value`` will be normalized. + For example, some processors may not generate float or int + normalized text by default. + + Below are sample formats mapped to structured values. - Money/Currency type (``money_value``) is in the ISO 4217 text format. @@ -819,7 +850,8 @@ class TextAnchor(proto.Message): [Document.text][google.cloud.documentai.v1.Document.text]. content (str): Contains the content of the text span so that users do not - have to look it up in the text_segments. + have to look it up in the text_segments. It is always + populated for formFields. """ class TextSegment(proto.Message): @@ -943,18 +975,18 @@ class OperationType(proto.Enum): EVAL_SKIPPED = 6 class Parent(proto.Message): - r"""Structure for referencing parent provenances. When an - element replaces one of more other elements parent references - identify the elements that are replaced. + r"""The parent element the current element is based on. Used for + referencing/aligning, removal and replacement operations. Attributes: revision (int): - The index of the [Document.revisions] identifying the parent - revision. + The index of the index into current revision's parent_ids + list. index (int): - The index of the parent revisions - corresponding collection of items (eg. list of - entities, properties within entities, etc.) + The index of the parent item in the + corresponding item list (eg. list of entities, + properties within entities, etc.) in the parent + revision. id (int): The id of the parent provenance. """ diff --git a/google/cloud/documentai_v1/types/document_io.py b/google/cloud/documentai_v1/types/document_io.py index 06b3d1cc..2f5d326b 100644 --- a/google/cloud/documentai_v1/types/document_io.py +++ b/google/cloud/documentai_v1/types/document_io.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/documentai_v1/types/document_processor_service.py b/google/cloud/documentai_v1/types/document_processor_service.py index d94bee45..c7a71cd9 100644 --- a/google/cloud/documentai_v1/types/document_processor_service.py +++ b/google/cloud/documentai_v1/types/document_processor_service.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -274,11 +274,14 @@ class ReviewDocumentOperationMetadata(proto.Message): common_metadata (google.cloud.documentai_v1.types.CommonOperationMetadata): The basic metadata of the long running operation. + question_id (str): + The question ID. """ common_metadata = proto.Field( proto.MESSAGE, number=5, message=operation_metadata.CommonOperationMetadata, ) + question_id = proto.Field(proto.STRING, number=6,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/documentai_v1/types/geometry.py b/google/cloud/documentai_v1/types/geometry.py index 50d01649..d6b41600 100644 --- a/google/cloud/documentai_v1/types/geometry.py +++ b/google/cloud/documentai_v1/types/geometry.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/documentai_v1/types/operation_metadata.py b/google/cloud/documentai_v1/types/operation_metadata.py index 9b8429fe..32db9d66 100644 --- a/google/cloud/documentai_v1/types/operation_metadata.py +++ b/google/cloud/documentai_v1/types/operation_metadata.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/documentai_v1beta2/__init__.py b/google/cloud/documentai_v1beta2/__init__.py index f5a4882b..f73206c8 100644 --- a/google/cloud/documentai_v1beta2/__init__.py +++ b/google/cloud/documentai_v1beta2/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/documentai_v1beta2/services/__init__.py b/google/cloud/documentai_v1beta2/services/__init__.py index 4de65971..e8e1c384 100644 --- a/google/cloud/documentai_v1beta2/services/__init__.py +++ b/google/cloud/documentai_v1beta2/services/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/documentai_v1beta2/services/document_understanding_service/__init__.py b/google/cloud/documentai_v1beta2/services/document_understanding_service/__init__.py index f8f821ee..17f69842 100644 --- a/google/cloud/documentai_v1beta2/services/document_understanding_service/__init__.py +++ b/google/cloud/documentai_v1beta2/services/document_understanding_service/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/documentai_v1beta2/services/document_understanding_service/async_client.py b/google/cloud/documentai_v1beta2/services/document_understanding_service/async_client.py index c41655ee..0f83bafa 100644 --- a/google/cloud/documentai_v1beta2/services/document_understanding_service/async_client.py +++ b/google/cloud/documentai_v1beta2/services/document_understanding_service/async_client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,7 +16,7 @@ from collections import OrderedDict import functools import re -from typing import Dict, Sequence, Tuple, Type, Union +from typing import Dict, Optional, Sequence, Tuple, Type, Union import pkg_resources from google.api_core.client_options import ClientOptions @@ -116,6 +116,42 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): from_service_account_json = from_service_account_file + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + return DocumentUnderstandingServiceClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore + @property def transport(self) -> DocumentUnderstandingServiceTransport: """Returns the transport used by the client instance. @@ -191,6 +227,34 @@ async def batch_process_documents( r"""LRO endpoint to batch process many documents. The output is written to Cloud Storage as JSON in the [Document] format. + + .. code-block:: python + + from google.cloud import documentai_v1beta2 + + def sample_batch_process_documents(): + # Create a client + client = documentai_v1beta2.DocumentUnderstandingServiceClient() + + # Initialize request argument(s) + requests = documentai_v1beta2.ProcessDocumentRequest() + requests.input_config.gcs_source.uri = "uri_value" + requests.input_config.mime_type = "mime_type_value" + + request = documentai_v1beta2.BatchProcessDocumentsRequest( + requests=requests, + ) + + # Make the request + operation = client.batch_process_documents(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.documentai_v1beta2.types.BatchProcessDocumentsRequest, dict]): The request object. Request to batch process documents @@ -218,7 +282,7 @@ async def batch_process_documents( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([requests]) if request is not None and has_flattened_params: @@ -282,6 +346,29 @@ async def process_document( ) -> document.Document: r"""Processes a single document. + .. code-block:: python + + from google.cloud import documentai_v1beta2 + + def sample_process_document(): + # Create a client + client = documentai_v1beta2.DocumentUnderstandingServiceClient() + + # Initialize request argument(s) + input_config = documentai_v1beta2.InputConfig() + input_config.gcs_source.uri = "uri_value" + input_config.mime_type = "mime_type_value" + + request = documentai_v1beta2.ProcessDocumentRequest( + input_config=input_config, + ) + + # Make the request + response = client.process_document(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.documentai_v1beta2.types.ProcessDocumentRequest, dict]): The request object. Request to process one document. diff --git a/google/cloud/documentai_v1beta2/services/document_understanding_service/client.py b/google/cloud/documentai_v1beta2/services/document_understanding_service/client.py index 1d7bec4a..ba817046 100644 --- a/google/cloud/documentai_v1beta2/services/document_understanding_service/client.py +++ b/google/cloud/documentai_v1beta2/services/document_understanding_service/client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -230,6 +230,73 @@ def parse_common_location_path(path: str) -> Dict[str, str]: m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)$", path) return m.groupdict() if m else {} + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[client_options_lib.ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + if client_options is None: + client_options = client_options_lib.ClientOptions() + use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") + if use_client_cert not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" + ) + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + + # Figure out the client cert source to use. + client_cert_source = None + if use_client_cert == "true": + if client_options.client_cert_source: + client_cert_source = client_options.client_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + + # Figure out which api endpoint to use. + if client_options.api_endpoint is not None: + api_endpoint = client_options.api_endpoint + elif use_mtls_endpoint == "always" or ( + use_mtls_endpoint == "auto" and client_cert_source + ): + api_endpoint = cls.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = cls.DEFAULT_ENDPOINT + + return api_endpoint, client_cert_source + def __init__( self, *, @@ -280,57 +347,22 @@ def __init__( if client_options is None: client_options = client_options_lib.ClientOptions() - # Create SSL credentials for mutual TLS if needed. - if os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") not in ( - "true", - "false", - ): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" - ) - use_client_cert = ( - os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") == "true" + api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( + client_options ) - client_cert_source_func = None - is_mtls = False - if use_client_cert: - if client_options.client_cert_source: - is_mtls = True - client_cert_source_func = client_options.client_cert_source - else: - is_mtls = mtls.has_default_client_cert_source() - if is_mtls: - client_cert_source_func = mtls.default_client_cert_source() - else: - client_cert_source_func = None - - # Figure out which api endpoint to use. - if client_options.api_endpoint is not None: - api_endpoint = client_options.api_endpoint - else: - use_mtls_env = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") - if use_mtls_env == "never": - api_endpoint = self.DEFAULT_ENDPOINT - elif use_mtls_env == "always": - api_endpoint = self.DEFAULT_MTLS_ENDPOINT - elif use_mtls_env == "auto": - if is_mtls: - api_endpoint = self.DEFAULT_MTLS_ENDPOINT - else: - api_endpoint = self.DEFAULT_ENDPOINT - else: - raise MutualTLSChannelError( - "Unsupported GOOGLE_API_USE_MTLS_ENDPOINT value. Accepted " - "values: never, auto, always" - ) + api_key_value = getattr(client_options, "api_key", None) + if api_key_value and credentials: + raise ValueError( + "client_options.api_key and credentials are mutually exclusive" + ) # Save or instantiate the transport. # Ordinarily, we provide the transport, but allowing a custom transport # instance provides an extensibility point for unusual situations. if isinstance(transport, DocumentUnderstandingServiceTransport): # transport is a DocumentUnderstandingServiceTransport instance. - if credentials or client_options.credentials_file: + if credentials or client_options.credentials_file or api_key_value: raise ValueError( "When providing a transport instance, " "provide its credentials directly." @@ -342,6 +374,15 @@ def __init__( ) self._transport = transport else: + import google.auth._default # type: ignore + + if api_key_value and hasattr( + google.auth._default, "get_api_key_credentials" + ): + credentials = google.auth._default.get_api_key_credentials( + api_key_value + ) + Transport = type(self).get_transport_class(transport) self._transport = Transport( credentials=credentials, @@ -368,6 +409,34 @@ def batch_process_documents( r"""LRO endpoint to batch process many documents. The output is written to Cloud Storage as JSON in the [Document] format. + + .. code-block:: python + + from google.cloud import documentai_v1beta2 + + def sample_batch_process_documents(): + # Create a client + client = documentai_v1beta2.DocumentUnderstandingServiceClient() + + # Initialize request argument(s) + requests = documentai_v1beta2.ProcessDocumentRequest() + requests.input_config.gcs_source.uri = "uri_value" + requests.input_config.mime_type = "mime_type_value" + + request = documentai_v1beta2.BatchProcessDocumentsRequest( + requests=requests, + ) + + # Make the request + operation = client.batch_process_documents(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.documentai_v1beta2.types.BatchProcessDocumentsRequest, dict]): The request object. Request to batch process documents @@ -395,7 +464,7 @@ def batch_process_documents( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([requests]) if request is not None and has_flattened_params: @@ -449,6 +518,29 @@ def process_document( ) -> document.Document: r"""Processes a single document. + .. code-block:: python + + from google.cloud import documentai_v1beta2 + + def sample_process_document(): + # Create a client + client = documentai_v1beta2.DocumentUnderstandingServiceClient() + + # Initialize request argument(s) + input_config = documentai_v1beta2.InputConfig() + input_config.gcs_source.uri = "uri_value" + input_config.mime_type = "mime_type_value" + + request = documentai_v1beta2.ProcessDocumentRequest( + input_config=input_config, + ) + + # Make the request + response = client.process_document(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.documentai_v1beta2.types.ProcessDocumentRequest, dict]): The request object. Request to process one document. diff --git a/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/__init__.py b/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/__init__.py index 0961801d..c4d38059 100644 --- a/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/__init__.py +++ b/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/base.py b/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/base.py index 2907c6c7..d231500e 100644 --- a/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/base.py +++ b/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/base.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/grpc.py b/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/grpc.py index c08a8db1..d58f124c 100644 --- a/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/grpc.py +++ b/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/grpc.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -164,8 +164,11 @@ def __init__( if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, @@ -238,7 +241,7 @@ def operations_client(self) -> operations_v1.OperationsClient: This property caches on the instance; repeated calls return the same client. """ - # Sanity check: Only create a new client if we do not already have one. + # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsClient(self.grpc_channel) diff --git a/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/grpc_asyncio.py b/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/grpc_asyncio.py index 238594d1..82d18beb 100644 --- a/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/grpc_asyncio.py +++ b/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/grpc_asyncio.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -211,8 +211,11 @@ def __init__( if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, @@ -242,7 +245,7 @@ def operations_client(self) -> operations_v1.OperationsAsyncClient: This property caches on the instance; repeated calls return the same client. """ - # Sanity check: Only create a new client if we do not already have one. + # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsAsyncClient( self.grpc_channel diff --git a/google/cloud/documentai_v1beta2/types/__init__.py b/google/cloud/documentai_v1beta2/types/__init__.py index be41d52a..31c275ea 100644 --- a/google/cloud/documentai_v1beta2/types/__init__.py +++ b/google/cloud/documentai_v1beta2/types/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/documentai_v1beta2/types/document.py b/google/cloud/documentai_v1beta2/types/document.py index b58ec2b9..02394cb5 100644 --- a/google/cloud/documentai_v1beta2/types/document.py +++ b/google/cloud/documentai_v1beta2/types/document.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -58,8 +58,7 @@ class Document(proto.Message): mime_type (str): An IANA published MIME type (also referred to as media type). For more information, see - https://www.iana.org/assignments/media- - types/media-types.xhtml. + https://www.iana.org/assignments/media-types/media-types.xhtml. text (str): UTF-8 encoded text in reading order from the document. diff --git a/google/cloud/documentai_v1beta2/types/document_understanding.py b/google/cloud/documentai_v1beta2/types/document_understanding.py index d1393675..d0df2906 100644 --- a/google/cloud/documentai_v1beta2/types/document_understanding.py +++ b/google/cloud/documentai_v1beta2/types/document_understanding.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/documentai_v1beta2/types/geometry.py b/google/cloud/documentai_v1beta2/types/geometry.py index 2c695733..cb593df2 100644 --- a/google/cloud/documentai_v1beta2/types/geometry.py +++ b/google/cloud/documentai_v1beta2/types/geometry.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/documentai_v1beta3/__init__.py b/google/cloud/documentai_v1beta3/__init__.py index 9fcd12ae..06ce2fce 100644 --- a/google/cloud/documentai_v1beta3/__init__.py +++ b/google/cloud/documentai_v1beta3/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/documentai_v1beta3/services/__init__.py b/google/cloud/documentai_v1beta3/services/__init__.py index 4de65971..e8e1c384 100644 --- a/google/cloud/documentai_v1beta3/services/__init__.py +++ b/google/cloud/documentai_v1beta3/services/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/documentai_v1beta3/services/document_processor_service/__init__.py b/google/cloud/documentai_v1beta3/services/document_processor_service/__init__.py index 900ba543..d454baaa 100644 --- a/google/cloud/documentai_v1beta3/services/document_processor_service/__init__.py +++ b/google/cloud/documentai_v1beta3/services/document_processor_service/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/documentai_v1beta3/services/document_processor_service/async_client.py b/google/cloud/documentai_v1beta3/services/document_processor_service/async_client.py index 534699e1..64f6f451 100644 --- a/google/cloud/documentai_v1beta3/services/document_processor_service/async_client.py +++ b/google/cloud/documentai_v1beta3/services/document_processor_service/async_client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,7 +16,7 @@ from collections import OrderedDict import functools import re -from typing import Dict, Sequence, Tuple, Type, Union +from typing import Dict, Optional, Sequence, Tuple, Type, Union import pkg_resources from google.api_core.client_options import ClientOptions @@ -137,6 +137,42 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): from_service_account_json = from_service_account_file + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + return DocumentProcessorServiceClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore + @property def transport(self) -> DocumentProcessorServiceTransport: """Returns the transport used by the client instance. @@ -209,6 +245,29 @@ async def process_document( ) -> document_processor_service.ProcessResponse: r"""Processes a single document. + .. code-block:: python + + from google.cloud import documentai_v1beta3 + + def sample_process_document(): + # Create a client + client = documentai_v1beta3.DocumentProcessorServiceClient() + + # Initialize request argument(s) + inline_document = documentai_v1beta3.Document() + inline_document.uri = "uri_value" + + request = documentai_v1beta3.ProcessRequest( + inline_document=inline_document, + name="name_value", + ) + + # Make the request + response = client.process_document(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.documentai_v1beta3.types.ProcessRequest, dict]): The request object. Request message for the process @@ -233,7 +292,7 @@ async def process_document( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: @@ -291,6 +350,30 @@ async def batch_process_documents( r"""LRO endpoint to batch process many documents. The output is written to Cloud Storage as JSON in the [Document] format. + + .. code-block:: python + + from google.cloud import documentai_v1beta3 + + def sample_batch_process_documents(): + # Create a client + client = documentai_v1beta3.DocumentProcessorServiceClient() + + # Initialize request argument(s) + request = documentai_v1beta3.BatchProcessRequest( + name="name_value", + ) + + # Make the request + operation = client.batch_process_documents(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.documentai_v1beta3.types.BatchProcessRequest, dict]): The request object. Request message for batch process @@ -318,7 +401,7 @@ async def batch_process_documents( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: @@ -385,6 +468,25 @@ async def fetch_processor_types( ) -> document_processor_service.FetchProcessorTypesResponse: r"""Fetches processor types. + .. code-block:: python + + from google.cloud import documentai_v1beta3 + + def sample_fetch_processor_types(): + # Create a client + client = documentai_v1beta3.DocumentProcessorServiceClient() + + # Initialize request argument(s) + request = documentai_v1beta3.FetchProcessorTypesRequest( + parent="parent_value", + ) + + # Make the request + response = client.fetch_processor_types(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.documentai_v1beta3.types.FetchProcessorTypesRequest, dict]): The request object. Request message for fetch processor @@ -410,7 +512,7 @@ async def fetch_processor_types( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([parent]) if request is not None and has_flattened_params: @@ -457,6 +559,26 @@ async def list_processors( ) -> pagers.ListProcessorsAsyncPager: r"""Lists all processors which belong to this project. + .. code-block:: python + + from google.cloud import documentai_v1beta3 + + def sample_list_processors(): + # Create a client + client = documentai_v1beta3.DocumentProcessorServiceClient() + + # Initialize request argument(s) + request = documentai_v1beta3.ListProcessorsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_processors(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: request (Union[google.cloud.documentai_v1beta3.types.ListProcessorsRequest, dict]): The request object. Request message for list all @@ -485,7 +607,7 @@ async def list_processors( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([parent]) if request is not None and has_flattened_params: @@ -541,6 +663,26 @@ async def create_processor( user chose. The processor will be at "ENABLED" state by default after its creation. + + .. code-block:: python + + from google.cloud import documentai_v1beta3 + + def sample_create_processor(): + # Create a client + client = documentai_v1beta3.DocumentProcessorServiceClient() + + # Initialize request argument(s) + request = documentai_v1beta3.CreateProcessorRequest( + parent="parent_value", + ) + + # Make the request + response = client.create_processor(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.documentai_v1beta3.types.CreateProcessorRequest, dict]): The request object. Request message for create a @@ -579,7 +721,7 @@ async def create_processor( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([parent, processor]) if request is not None and has_flattened_params: @@ -630,6 +772,30 @@ async def delete_processor( artifacts if it was enabled and then deletes all artifacts associated with this processor. + + .. code-block:: python + + from google.cloud import documentai_v1beta3 + + def sample_delete_processor(): + # Create a client + client = documentai_v1beta3.DocumentProcessorServiceClient() + + # Initialize request argument(s) + request = documentai_v1beta3.DeleteProcessorRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_processor(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.documentai_v1beta3.types.DeleteProcessorRequest, dict]): The request object. Request message for the delete @@ -667,7 +833,7 @@ async def delete_processor( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: @@ -721,6 +887,29 @@ async def enable_processor( ) -> operation_async.AsyncOperation: r"""Enables a processor + .. code-block:: python + + from google.cloud import documentai_v1beta3 + + def sample_enable_processor(): + # Create a client + client = documentai_v1beta3.DocumentProcessorServiceClient() + + # Initialize request argument(s) + request = documentai_v1beta3.EnableProcessorRequest( + name="name_value", + ) + + # Make the request + operation = client.enable_processor(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.documentai_v1beta3.types.EnableProcessorRequest, dict]): The request object. Request message for the enable @@ -781,6 +970,29 @@ async def disable_processor( ) -> operation_async.AsyncOperation: r"""Disables a processor + .. code-block:: python + + from google.cloud import documentai_v1beta3 + + def sample_disable_processor(): + # Create a client + client = documentai_v1beta3.DocumentProcessorServiceClient() + + # Initialize request argument(s) + request = documentai_v1beta3.DisableProcessorRequest( + name="name_value", + ) + + # Make the request + operation = client.disable_processor(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.documentai_v1beta3.types.DisableProcessorRequest, dict]): The request object. Request message for the disable @@ -843,6 +1055,34 @@ async def review_document( r"""Send a document for Human Review. The input document should be processed by the specified processor. + + .. code-block:: python + + from google.cloud import documentai_v1beta3 + + def sample_review_document(): + # Create a client + client = documentai_v1beta3.DocumentProcessorServiceClient() + + # Initialize request argument(s) + inline_document = documentai_v1beta3.Document() + inline_document.uri = "uri_value" + + request = documentai_v1beta3.ReviewDocumentRequest( + inline_document=inline_document, + human_review_config="human_review_config_value", + ) + + # Make the request + operation = client.review_document(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.documentai_v1beta3.types.ReviewDocumentRequest, dict]): The request object. Request message for review document @@ -871,7 +1111,7 @@ async def review_document( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([human_review_config]) if request is not None and has_flattened_params: diff --git a/google/cloud/documentai_v1beta3/services/document_processor_service/client.py b/google/cloud/documentai_v1beta3/services/document_processor_service/client.py index ca22871e..00c31dd5 100644 --- a/google/cloud/documentai_v1beta3/services/document_processor_service/client.py +++ b/google/cloud/documentai_v1beta3/services/document_processor_service/client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -281,6 +281,73 @@ def parse_common_location_path(path: str) -> Dict[str, str]: m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)$", path) return m.groupdict() if m else {} + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[client_options_lib.ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + if client_options is None: + client_options = client_options_lib.ClientOptions() + use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") + if use_client_cert not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" + ) + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + + # Figure out the client cert source to use. + client_cert_source = None + if use_client_cert == "true": + if client_options.client_cert_source: + client_cert_source = client_options.client_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + + # Figure out which api endpoint to use. + if client_options.api_endpoint is not None: + api_endpoint = client_options.api_endpoint + elif use_mtls_endpoint == "always" or ( + use_mtls_endpoint == "auto" and client_cert_source + ): + api_endpoint = cls.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = cls.DEFAULT_ENDPOINT + + return api_endpoint, client_cert_source + def __init__( self, *, @@ -331,57 +398,22 @@ def __init__( if client_options is None: client_options = client_options_lib.ClientOptions() - # Create SSL credentials for mutual TLS if needed. - if os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") not in ( - "true", - "false", - ): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" - ) - use_client_cert = ( - os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") == "true" + api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( + client_options ) - client_cert_source_func = None - is_mtls = False - if use_client_cert: - if client_options.client_cert_source: - is_mtls = True - client_cert_source_func = client_options.client_cert_source - else: - is_mtls = mtls.has_default_client_cert_source() - if is_mtls: - client_cert_source_func = mtls.default_client_cert_source() - else: - client_cert_source_func = None - - # Figure out which api endpoint to use. - if client_options.api_endpoint is not None: - api_endpoint = client_options.api_endpoint - else: - use_mtls_env = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") - if use_mtls_env == "never": - api_endpoint = self.DEFAULT_ENDPOINT - elif use_mtls_env == "always": - api_endpoint = self.DEFAULT_MTLS_ENDPOINT - elif use_mtls_env == "auto": - if is_mtls: - api_endpoint = self.DEFAULT_MTLS_ENDPOINT - else: - api_endpoint = self.DEFAULT_ENDPOINT - else: - raise MutualTLSChannelError( - "Unsupported GOOGLE_API_USE_MTLS_ENDPOINT value. Accepted " - "values: never, auto, always" - ) + api_key_value = getattr(client_options, "api_key", None) + if api_key_value and credentials: + raise ValueError( + "client_options.api_key and credentials are mutually exclusive" + ) # Save or instantiate the transport. # Ordinarily, we provide the transport, but allowing a custom transport # instance provides an extensibility point for unusual situations. if isinstance(transport, DocumentProcessorServiceTransport): # transport is a DocumentProcessorServiceTransport instance. - if credentials or client_options.credentials_file: + if credentials or client_options.credentials_file or api_key_value: raise ValueError( "When providing a transport instance, " "provide its credentials directly." @@ -393,6 +425,15 @@ def __init__( ) self._transport = transport else: + import google.auth._default # type: ignore + + if api_key_value and hasattr( + google.auth._default, "get_api_key_credentials" + ): + credentials = google.auth._default.get_api_key_credentials( + api_key_value + ) + Transport = type(self).get_transport_class(transport) self._transport = Transport( credentials=credentials, @@ -416,6 +457,29 @@ def process_document( ) -> document_processor_service.ProcessResponse: r"""Processes a single document. + .. code-block:: python + + from google.cloud import documentai_v1beta3 + + def sample_process_document(): + # Create a client + client = documentai_v1beta3.DocumentProcessorServiceClient() + + # Initialize request argument(s) + inline_document = documentai_v1beta3.Document() + inline_document.uri = "uri_value" + + request = documentai_v1beta3.ProcessRequest( + inline_document=inline_document, + name="name_value", + ) + + # Make the request + response = client.process_document(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.documentai_v1beta3.types.ProcessRequest, dict]): The request object. Request message for the process @@ -440,7 +504,7 @@ def process_document( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: @@ -488,6 +552,30 @@ def batch_process_documents( r"""LRO endpoint to batch process many documents. The output is written to Cloud Storage as JSON in the [Document] format. + + .. code-block:: python + + from google.cloud import documentai_v1beta3 + + def sample_batch_process_documents(): + # Create a client + client = documentai_v1beta3.DocumentProcessorServiceClient() + + # Initialize request argument(s) + request = documentai_v1beta3.BatchProcessRequest( + name="name_value", + ) + + # Make the request + operation = client.batch_process_documents(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.documentai_v1beta3.types.BatchProcessRequest, dict]): The request object. Request message for batch process @@ -515,7 +603,7 @@ def batch_process_documents( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: @@ -572,6 +660,25 @@ def fetch_processor_types( ) -> document_processor_service.FetchProcessorTypesResponse: r"""Fetches processor types. + .. code-block:: python + + from google.cloud import documentai_v1beta3 + + def sample_fetch_processor_types(): + # Create a client + client = documentai_v1beta3.DocumentProcessorServiceClient() + + # Initialize request argument(s) + request = documentai_v1beta3.FetchProcessorTypesRequest( + parent="parent_value", + ) + + # Make the request + response = client.fetch_processor_types(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.documentai_v1beta3.types.FetchProcessorTypesRequest, dict]): The request object. Request message for fetch processor @@ -597,7 +704,7 @@ def fetch_processor_types( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([parent]) if request is not None and has_flattened_params: @@ -646,6 +753,26 @@ def list_processors( ) -> pagers.ListProcessorsPager: r"""Lists all processors which belong to this project. + .. code-block:: python + + from google.cloud import documentai_v1beta3 + + def sample_list_processors(): + # Create a client + client = documentai_v1beta3.DocumentProcessorServiceClient() + + # Initialize request argument(s) + request = documentai_v1beta3.ListProcessorsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_processors(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: request (Union[google.cloud.documentai_v1beta3.types.ListProcessorsRequest, dict]): The request object. Request message for list all @@ -674,7 +801,7 @@ def list_processors( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([parent]) if request is not None and has_flattened_params: @@ -730,6 +857,26 @@ def create_processor( user chose. The processor will be at "ENABLED" state by default after its creation. + + .. code-block:: python + + from google.cloud import documentai_v1beta3 + + def sample_create_processor(): + # Create a client + client = documentai_v1beta3.DocumentProcessorServiceClient() + + # Initialize request argument(s) + request = documentai_v1beta3.CreateProcessorRequest( + parent="parent_value", + ) + + # Make the request + response = client.create_processor(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.documentai_v1beta3.types.CreateProcessorRequest, dict]): The request object. Request message for create a @@ -768,7 +915,7 @@ def create_processor( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([parent, processor]) if request is not None and has_flattened_params: @@ -819,6 +966,30 @@ def delete_processor( artifacts if it was enabled and then deletes all artifacts associated with this processor. + + .. code-block:: python + + from google.cloud import documentai_v1beta3 + + def sample_delete_processor(): + # Create a client + client = documentai_v1beta3.DocumentProcessorServiceClient() + + # Initialize request argument(s) + request = documentai_v1beta3.DeleteProcessorRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_processor(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.documentai_v1beta3.types.DeleteProcessorRequest, dict]): The request object. Request message for the delete @@ -856,7 +1027,7 @@ def delete_processor( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: @@ -910,6 +1081,29 @@ def enable_processor( ) -> operation.Operation: r"""Enables a processor + .. code-block:: python + + from google.cloud import documentai_v1beta3 + + def sample_enable_processor(): + # Create a client + client = documentai_v1beta3.DocumentProcessorServiceClient() + + # Initialize request argument(s) + request = documentai_v1beta3.EnableProcessorRequest( + name="name_value", + ) + + # Make the request + operation = client.enable_processor(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.documentai_v1beta3.types.EnableProcessorRequest, dict]): The request object. Request message for the enable @@ -971,6 +1165,29 @@ def disable_processor( ) -> operation.Operation: r"""Disables a processor + .. code-block:: python + + from google.cloud import documentai_v1beta3 + + def sample_disable_processor(): + # Create a client + client = documentai_v1beta3.DocumentProcessorServiceClient() + + # Initialize request argument(s) + request = documentai_v1beta3.DisableProcessorRequest( + name="name_value", + ) + + # Make the request + operation = client.disable_processor(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.documentai_v1beta3.types.DisableProcessorRequest, dict]): The request object. Request message for the disable @@ -1034,6 +1251,34 @@ def review_document( r"""Send a document for Human Review. The input document should be processed by the specified processor. + + .. code-block:: python + + from google.cloud import documentai_v1beta3 + + def sample_review_document(): + # Create a client + client = documentai_v1beta3.DocumentProcessorServiceClient() + + # Initialize request argument(s) + inline_document = documentai_v1beta3.Document() + inline_document.uri = "uri_value" + + request = documentai_v1beta3.ReviewDocumentRequest( + inline_document=inline_document, + human_review_config="human_review_config_value", + ) + + # Make the request + operation = client.review_document(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.documentai_v1beta3.types.ReviewDocumentRequest, dict]): The request object. Request message for review document @@ -1062,7 +1307,7 @@ def review_document( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([human_review_config]) if request is not None and has_flattened_params: diff --git a/google/cloud/documentai_v1beta3/services/document_processor_service/pagers.py b/google/cloud/documentai_v1beta3/services/document_processor_service/pagers.py index 668b3801..6f1a2e48 100644 --- a/google/cloud/documentai_v1beta3/services/document_processor_service/pagers.py +++ b/google/cloud/documentai_v1beta3/services/document_processor_service/pagers.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/documentai_v1beta3/services/document_processor_service/transports/__init__.py b/google/cloud/documentai_v1beta3/services/document_processor_service/transports/__init__.py index b9f737af..edfa7d68 100644 --- a/google/cloud/documentai_v1beta3/services/document_processor_service/transports/__init__.py +++ b/google/cloud/documentai_v1beta3/services/document_processor_service/transports/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/documentai_v1beta3/services/document_processor_service/transports/base.py b/google/cloud/documentai_v1beta3/services/document_processor_service/transports/base.py index 775dce99..5053fe61 100644 --- a/google/cloud/documentai_v1beta3/services/document_processor_service/transports/base.py +++ b/google/cloud/documentai_v1beta3/services/document_processor_service/transports/base.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/documentai_v1beta3/services/document_processor_service/transports/grpc.py b/google/cloud/documentai_v1beta3/services/document_processor_service/transports/grpc.py index ec345fc9..a4ae4d3f 100644 --- a/google/cloud/documentai_v1beta3/services/document_processor_service/transports/grpc.py +++ b/google/cloud/documentai_v1beta3/services/document_processor_service/transports/grpc.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -166,8 +166,11 @@ def __init__( if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, @@ -240,7 +243,7 @@ def operations_client(self) -> operations_v1.OperationsClient: This property caches on the instance; repeated calls return the same client. """ - # Sanity check: Only create a new client if we do not already have one. + # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsClient(self.grpc_channel) diff --git a/google/cloud/documentai_v1beta3/services/document_processor_service/transports/grpc_asyncio.py b/google/cloud/documentai_v1beta3/services/document_processor_service/transports/grpc_asyncio.py index b5e9f687..0dc5696e 100644 --- a/google/cloud/documentai_v1beta3/services/document_processor_service/transports/grpc_asyncio.py +++ b/google/cloud/documentai_v1beta3/services/document_processor_service/transports/grpc_asyncio.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -211,8 +211,11 @@ def __init__( if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, @@ -242,7 +245,7 @@ def operations_client(self) -> operations_v1.OperationsAsyncClient: This property caches on the instance; repeated calls return the same client. """ - # Sanity check: Only create a new client if we do not already have one. + # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsAsyncClient( self.grpc_channel diff --git a/google/cloud/documentai_v1beta3/types/__init__.py b/google/cloud/documentai_v1beta3/types/__init__.py index 60aab2df..522631ea 100644 --- a/google/cloud/documentai_v1beta3/types/__init__.py +++ b/google/cloud/documentai_v1beta3/types/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/documentai_v1beta3/types/document.py b/google/cloud/documentai_v1beta3/types/document.py index 1f02f195..27d7d341 100644 --- a/google/cloud/documentai_v1beta3/types/document.py +++ b/google/cloud/documentai_v1beta3/types/document.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -63,13 +63,12 @@ class Document(proto.Message): mime_type (str): An IANA published MIME type (also referred to as media type). For more information, see - https://www.iana.org/assignments/media- - types/media-types.xhtml. + https://www.iana.org/assignments/media-types/media-types.xhtml. text (str): Optional. UTF-8 encoded text in reading order from the document. text_styles (Sequence[google.cloud.documentai_v1beta3.types.Document.Style]): - Styles for the + Placeholder. Styles for the [Document.text][google.cloud.documentai.v1beta3.Document.text]. pages (Sequence[google.cloud.documentai_v1beta3.types.Document.Page]): Visual page layout for the @@ -80,13 +79,13 @@ class Document(proto.Message): For document shards, entities in this list may cross shard boundaries. entity_relations (Sequence[google.cloud.documentai_v1beta3.types.Document.EntityRelation]): - Relationship among + Placeholder. Relationship among [Document.entities][google.cloud.documentai.v1beta3.Document.entities]. text_changes (Sequence[google.cloud.documentai_v1beta3.types.Document.TextChange]): - A list of text corrections made to [Document.text]. This is - usually used for annotating corrections to OCR mistakes. - Text changes for a given revision may not overlap with each - other. + Placeholder. A list of text corrections made to + [Document.text]. This is usually used for annotating + corrections to OCR mistakes. Text changes for a given + revision may not overlap with each other. shard_info (google.cloud.documentai_v1beta3.types.Document.ShardInfo): Information about the sharding if this document is sharded part of a larger document. @@ -96,7 +95,8 @@ class Document(proto.Message): Any error that occurred while processing this document. revisions (Sequence[google.cloud.documentai_v1beta3.types.Document.Revision]): - Revision history of this document. + Placeholder. Revision history of this + document. """ class ShardInfo(proto.Message): @@ -225,6 +225,9 @@ class Page(proto.Message): form_fields (Sequence[google.cloud.documentai_v1beta3.types.Document.Page.FormField]): A list of visually detected form fields on the page. + symbols (Sequence[google.cloud.documentai_v1beta3.types.Document.Page.Symbol]): + A list of visually detected symbols on the + page. provenance (google.cloud.documentai_v1beta3.types.Document.Provenance): The history of this page. """ @@ -458,6 +461,26 @@ class Type(proto.Enum): proto.MESSAGE, number=4, message="Document.Provenance", ) + class Symbol(proto.Message): + r"""A detected symbol. + + Attributes: + layout (google.cloud.documentai_v1beta3.types.Document.Page.Layout): + [Layout][google.cloud.documentai.v1beta3.Document.Page.Layout] + for + [Symbol][google.cloud.documentai.v1beta3.Document.Page.Symbol]. + detected_languages (Sequence[google.cloud.documentai_v1beta3.types.Document.Page.DetectedLanguage]): + A list of detected languages together with + confidence. + """ + + layout = proto.Field( + proto.MESSAGE, number=1, message="Document.Page.Layout", + ) + detected_languages = proto.RepeatedField( + proto.MESSAGE, number=2, message="Document.Page.DetectedLanguage", + ) + class VisualElement(proto.Message): r"""Detected non-text visual elements e.g. checkbox, signature etc. on the page. @@ -607,7 +630,7 @@ class DetectedLanguage(proto.Message): language_code (str): The BCP-47 language code, such as "en-US" or "sr-Latn". For more information, see - http://www.unicode.org/reports/tr35/#Unicode_locale_identifier. + https://www.unicode.org/reports/tr35/#Unicode_locale_identifier. confidence (float): Confidence of detected language. Range [0, 1]. """ @@ -648,13 +671,17 @@ class DetectedLanguage(proto.Message): form_fields = proto.RepeatedField( proto.MESSAGE, number=11, message="Document.Page.FormField", ) + symbols = proto.RepeatedField( + proto.MESSAGE, number=12, message="Document.Page.Symbol", + ) provenance = proto.Field( proto.MESSAGE, number=16, message="Document.Provenance", ) class Entity(proto.Message): - r"""A phrase in the text that is a known entity type, such as a - person, an organization, or location. + r"""An entity that could be a phrase in the text or a property + that belongs to the document. It is a known entity type, such as + a person, an organization, or location. Attributes: text_anchor (google.cloud.documentai_v1beta3.types.Document.TextAnchor): @@ -665,7 +692,8 @@ class Entity(proto.Message): Entity type from a schema e.g. ``Address``. mention_text (str): Optional. Text value in the document e.g. - ``1600 Amphitheatre Pkwy``. + ``1600 Amphitheatre Pkwy``. If the entity is not present in + the document, this field will be empty. mention_id (str): Optional. Deprecated. Use ``id`` field instead. confidence (float): @@ -734,10 +762,14 @@ class NormalizedValue(proto.Message): This field is a member of `oneof`_ ``structured_value``. text (str): - Required. Normalized entity value stored as a string. This - field is populated for supported document type (e.g. - Invoice). For some entity types, one of respective - 'structured_value' fields may also be populated. + Optional. An optional field to store a normalized string. + For some entity types, one of respective + ``structured_value`` fields may also be populated. Also not + all the types of ``structured_value`` will be normalized. + For example, some processors may not generate float or int + normalized text by default. + + Below are sample formats mapped to structured values. - Money/Currency type (``money_value``) is in the ISO 4217 text format. @@ -823,7 +855,8 @@ class TextAnchor(proto.Message): [Document.text][google.cloud.documentai.v1beta3.Document.text]. content (str): Contains the content of the text span so that users do not - have to look it up in the text_segments. + have to look it up in the text_segments. It is always + populated for formFields. """ class TextSegment(proto.Message): @@ -947,18 +980,18 @@ class OperationType(proto.Enum): EVAL_SKIPPED = 6 class Parent(proto.Message): - r"""Structure for referencing parent provenances. When an - element replaces one of more other elements parent references - identify the elements that are replaced. + r"""The parent element the current element is based on. Used for + referencing/aligning, removal and replacement operations. Attributes: revision (int): - The index of the [Document.revisions] identifying the parent - revision. + The index of the index into current revision's parent_ids + list. index (int): - The index of the parent revisions - corresponding collection of items (eg. list of - entities, properties within entities, etc.) + The index of the parent item in the + corresponding item list (eg. list of entities, + properties within entities, etc.) in the parent + revision. id (int): The id of the parent provenance. """ diff --git a/google/cloud/documentai_v1beta3/types/document_io.py b/google/cloud/documentai_v1beta3/types/document_io.py index 2a9d84e7..3bc1ec68 100644 --- a/google/cloud/documentai_v1beta3/types/document_io.py +++ b/google/cloud/documentai_v1beta3/types/document_io.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/documentai_v1beta3/types/document_processor_service.py b/google/cloud/documentai_v1beta3/types/document_processor_service.py index a7980cbe..668e718f 100644 --- a/google/cloud/documentai_v1beta3/types/document_processor_service.py +++ b/google/cloud/documentai_v1beta3/types/document_processor_service.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -543,6 +543,8 @@ class ReviewDocumentOperationMetadata(proto.Message): common_metadata (google.cloud.documentai_v1beta3.types.CommonOperationMetadata): The basic metadata of the long running operation. + question_id (str): + The question ID. """ class State(proto.Enum): @@ -561,6 +563,7 @@ class State(proto.Enum): common_metadata = proto.Field( proto.MESSAGE, number=5, message=operation_metadata.CommonOperationMetadata, ) + question_id = proto.Field(proto.STRING, number=6,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/documentai_v1beta3/types/geometry.py b/google/cloud/documentai_v1beta3/types/geometry.py index b00e3b1c..e1a103b5 100644 --- a/google/cloud/documentai_v1beta3/types/geometry.py +++ b/google/cloud/documentai_v1beta3/types/geometry.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/documentai_v1beta3/types/operation_metadata.py b/google/cloud/documentai_v1beta3/types/operation_metadata.py index 05c1e07e..a4e57051 100644 --- a/google/cloud/documentai_v1beta3/types/operation_metadata.py +++ b/google/cloud/documentai_v1beta3/types/operation_metadata.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/documentai_v1beta3/types/processor.py b/google/cloud/documentai_v1beta3/types/processor.py index 0c613e7d..dc0dc83b 100644 --- a/google/cloud/documentai_v1beta3/types/processor.py +++ b/google/cloud/documentai_v1beta3/types/processor.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -48,8 +48,7 @@ class Processor(proto.Message): kms_key_name (str): The KMS key used for encryption/decryption in CMEK scenarios. See - https://cloud.google.com/security-key- - management. + https://cloud.google.com/security-key-management. """ class State(proto.Enum): diff --git a/google/cloud/documentai_v1beta3/types/processor_type.py b/google/cloud/documentai_v1beta3/types/processor_type.py index 9f0ec773..5161782c 100644 --- a/google/cloud/documentai_v1beta3/types/processor_type.py +++ b/google/cloud/documentai_v1beta3/types/processor_type.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/samples/generated_samples/documentai_generated_documentai_v1_document_processor_service_batch_process_documents_async.py b/samples/generated_samples/documentai_v1_generated_document_processor_service_batch_process_documents_async.py similarity index 75% rename from samples/generated_samples/documentai_generated_documentai_v1_document_processor_service_batch_process_documents_async.py rename to samples/generated_samples/documentai_v1_generated_document_processor_service_batch_process_documents_async.py index 1bd888b5..2713e2db 100644 --- a/samples/generated_samples/documentai_generated_documentai_v1_document_processor_service_batch_process_documents_async.py +++ b/samples/generated_samples/documentai_v1_generated_document_processor_service_batch_process_documents_async.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -23,24 +23,17 @@ # python3 -m pip install google-cloud-documentai -# [START documentai_generated_documentai_v1_DocumentProcessorService_BatchProcessDocuments_async] +# [START documentai_v1_generated_DocumentProcessorService_BatchProcessDocuments_async] from google.cloud import documentai_v1 async def sample_batch_process_documents(): - """Snippet for batch_process_documents""" - # Create a client client = documentai_v1.DocumentProcessorServiceAsyncClient() # Initialize request argument(s) - project = "my-project-id" - location = "us-central1" - processor = "processor_value" - name = f"projects/{project}/locations/{location}/processors/{processor}" - request = documentai_v1.BatchProcessRequest( - name=name, + name="name_value", ) # Make the request @@ -49,6 +42,8 @@ async def sample_batch_process_documents(): print("Waiting for operation to complete...") response = await operation.result() + + # Handle the response print(response) -# [END documentai_generated_documentai_v1_DocumentProcessorService_BatchProcessDocuments_async] +# [END documentai_v1_generated_DocumentProcessorService_BatchProcessDocuments_async] diff --git a/samples/generated_samples/documentai_generated_documentai_v1_document_processor_service_batch_process_documents_sync.py b/samples/generated_samples/documentai_v1_generated_document_processor_service_batch_process_documents_sync.py similarity index 75% rename from samples/generated_samples/documentai_generated_documentai_v1_document_processor_service_batch_process_documents_sync.py rename to samples/generated_samples/documentai_v1_generated_document_processor_service_batch_process_documents_sync.py index ae827a1c..cc7d39b6 100644 --- a/samples/generated_samples/documentai_generated_documentai_v1_document_processor_service_batch_process_documents_sync.py +++ b/samples/generated_samples/documentai_v1_generated_document_processor_service_batch_process_documents_sync.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -23,24 +23,17 @@ # python3 -m pip install google-cloud-documentai -# [START documentai_generated_documentai_v1_DocumentProcessorService_BatchProcessDocuments_sync] +# [START documentai_v1_generated_DocumentProcessorService_BatchProcessDocuments_sync] from google.cloud import documentai_v1 def sample_batch_process_documents(): - """Snippet for batch_process_documents""" - # Create a client client = documentai_v1.DocumentProcessorServiceClient() # Initialize request argument(s) - project = "my-project-id" - location = "us-central1" - processor = "processor_value" - name = f"projects/{project}/locations/{location}/processors/{processor}" - request = documentai_v1.BatchProcessRequest( - name=name, + name="name_value", ) # Make the request @@ -49,6 +42,8 @@ def sample_batch_process_documents(): print("Waiting for operation to complete...") response = operation.result() + + # Handle the response print(response) -# [END documentai_generated_documentai_v1_DocumentProcessorService_BatchProcessDocuments_sync] +# [END documentai_v1_generated_DocumentProcessorService_BatchProcessDocuments_sync] diff --git a/samples/generated_samples/documentai_generated_documentai_v1_document_processor_service_process_document_async.py b/samples/generated_samples/documentai_v1_generated_document_processor_service_process_document_async.py similarity index 75% rename from samples/generated_samples/documentai_generated_documentai_v1_document_processor_service_process_document_async.py rename to samples/generated_samples/documentai_v1_generated_document_processor_service_process_document_async.py index b09a7917..e9f2b9e3 100644 --- a/samples/generated_samples/documentai_generated_documentai_v1_document_processor_service_process_document_async.py +++ b/samples/generated_samples/documentai_v1_generated_document_processor_service_process_document_async.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -23,13 +23,11 @@ # python3 -m pip install google-cloud-documentai -# [START documentai_generated_documentai_v1_DocumentProcessorService_ProcessDocument_async] +# [START documentai_v1_generated_DocumentProcessorService_ProcessDocument_async] from google.cloud import documentai_v1 async def sample_process_document(): - """Snippet for process_document""" - # Create a client client = documentai_v1.DocumentProcessorServiceAsyncClient() @@ -37,20 +35,15 @@ async def sample_process_document(): inline_document = documentai_v1.Document() inline_document.uri = "uri_value" - project = "my-project-id" - location = "us-central1" - processor = "processor_value" - name = f"projects/{project}/locations/{location}/processors/{processor}" - request = documentai_v1.ProcessRequest( inline_document=inline_document, - name=name, + name="name_value", ) # Make the request response = await client.process_document(request=request) - # Handle response + # Handle the response print(response) -# [END documentai_generated_documentai_v1_DocumentProcessorService_ProcessDocument_async] +# [END documentai_v1_generated_DocumentProcessorService_ProcessDocument_async] diff --git a/samples/generated_samples/documentai_generated_documentai_v1_document_processor_service_process_document_sync.py b/samples/generated_samples/documentai_v1_generated_document_processor_service_process_document_sync.py similarity index 75% rename from samples/generated_samples/documentai_generated_documentai_v1_document_processor_service_process_document_sync.py rename to samples/generated_samples/documentai_v1_generated_document_processor_service_process_document_sync.py index f7c58628..ad67e5ad 100644 --- a/samples/generated_samples/documentai_generated_documentai_v1_document_processor_service_process_document_sync.py +++ b/samples/generated_samples/documentai_v1_generated_document_processor_service_process_document_sync.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -23,13 +23,11 @@ # python3 -m pip install google-cloud-documentai -# [START documentai_generated_documentai_v1_DocumentProcessorService_ProcessDocument_sync] +# [START documentai_v1_generated_DocumentProcessorService_ProcessDocument_sync] from google.cloud import documentai_v1 def sample_process_document(): - """Snippet for process_document""" - # Create a client client = documentai_v1.DocumentProcessorServiceClient() @@ -37,20 +35,15 @@ def sample_process_document(): inline_document = documentai_v1.Document() inline_document.uri = "uri_value" - project = "my-project-id" - location = "us-central1" - processor = "processor_value" - name = f"projects/{project}/locations/{location}/processors/{processor}" - request = documentai_v1.ProcessRequest( inline_document=inline_document, - name=name, + name="name_value", ) # Make the request response = client.process_document(request=request) - # Handle response + # Handle the response print(response) -# [END documentai_generated_documentai_v1_DocumentProcessorService_ProcessDocument_sync] +# [END documentai_v1_generated_DocumentProcessorService_ProcessDocument_sync] diff --git a/samples/generated_samples/documentai_generated_documentai_v1_document_processor_service_review_document_async.py b/samples/generated_samples/documentai_v1_generated_document_processor_service_review_document_async.py similarity index 74% rename from samples/generated_samples/documentai_generated_documentai_v1_document_processor_service_review_document_async.py rename to samples/generated_samples/documentai_v1_generated_document_processor_service_review_document_async.py index afd5c6dc..692d1797 100644 --- a/samples/generated_samples/documentai_generated_documentai_v1_document_processor_service_review_document_async.py +++ b/samples/generated_samples/documentai_v1_generated_document_processor_service_review_document_async.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -23,13 +23,11 @@ # python3 -m pip install google-cloud-documentai -# [START documentai_generated_documentai_v1_DocumentProcessorService_ReviewDocument_async] +# [START documentai_v1_generated_DocumentProcessorService_ReviewDocument_async] from google.cloud import documentai_v1 async def sample_review_document(): - """Snippet for review_document""" - # Create a client client = documentai_v1.DocumentProcessorServiceAsyncClient() @@ -37,14 +35,9 @@ async def sample_review_document(): inline_document = documentai_v1.Document() inline_document.uri = "uri_value" - project = "my-project-id" - location = "us-central1" - processor = "processor_value" - human_review_config = f"projects/{project}/locations/{location}/processors/{processor}/humanReviewConfig" - request = documentai_v1.ReviewDocumentRequest( inline_document=inline_document, - human_review_config=human_review_config, + human_review_config="human_review_config_value", ) # Make the request @@ -53,6 +46,8 @@ async def sample_review_document(): print("Waiting for operation to complete...") response = await operation.result() + + # Handle the response print(response) -# [END documentai_generated_documentai_v1_DocumentProcessorService_ReviewDocument_async] +# [END documentai_v1_generated_DocumentProcessorService_ReviewDocument_async] diff --git a/samples/generated_samples/documentai_generated_documentai_v1_document_processor_service_review_document_sync.py b/samples/generated_samples/documentai_v1_generated_document_processor_service_review_document_sync.py similarity index 74% rename from samples/generated_samples/documentai_generated_documentai_v1_document_processor_service_review_document_sync.py rename to samples/generated_samples/documentai_v1_generated_document_processor_service_review_document_sync.py index ce4d7b25..07e8a94e 100644 --- a/samples/generated_samples/documentai_generated_documentai_v1_document_processor_service_review_document_sync.py +++ b/samples/generated_samples/documentai_v1_generated_document_processor_service_review_document_sync.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -23,13 +23,11 @@ # python3 -m pip install google-cloud-documentai -# [START documentai_generated_documentai_v1_DocumentProcessorService_ReviewDocument_sync] +# [START documentai_v1_generated_DocumentProcessorService_ReviewDocument_sync] from google.cloud import documentai_v1 def sample_review_document(): - """Snippet for review_document""" - # Create a client client = documentai_v1.DocumentProcessorServiceClient() @@ -37,14 +35,9 @@ def sample_review_document(): inline_document = documentai_v1.Document() inline_document.uri = "uri_value" - project = "my-project-id" - location = "us-central1" - processor = "processor_value" - human_review_config = f"projects/{project}/locations/{location}/processors/{processor}/humanReviewConfig" - request = documentai_v1.ReviewDocumentRequest( inline_document=inline_document, - human_review_config=human_review_config, + human_review_config="human_review_config_value", ) # Make the request @@ -53,6 +46,8 @@ def sample_review_document(): print("Waiting for operation to complete...") response = operation.result() + + # Handle the response print(response) -# [END documentai_generated_documentai_v1_DocumentProcessorService_ReviewDocument_sync] +# [END documentai_v1_generated_DocumentProcessorService_ReviewDocument_sync] diff --git a/samples/generated_samples/documentai_v1beta2_generated_document_understanding_service_batch_process_documents_async.py b/samples/generated_samples/documentai_v1beta2_generated_document_understanding_service_batch_process_documents_async.py new file mode 100644 index 00000000..89eef1f3 --- /dev/null +++ b/samples/generated_samples/documentai_v1beta2_generated_document_understanding_service_batch_process_documents_async.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BatchProcessDocuments +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-documentai + + +# [START documentai_v1beta2_generated_DocumentUnderstandingService_BatchProcessDocuments_async] +from google.cloud import documentai_v1beta2 + + +async def sample_batch_process_documents(): + # Create a client + client = documentai_v1beta2.DocumentUnderstandingServiceAsyncClient() + + # Initialize request argument(s) + requests = documentai_v1beta2.ProcessDocumentRequest() + requests.input_config.gcs_source.uri = "uri_value" + requests.input_config.mime_type = "mime_type_value" + + request = documentai_v1beta2.BatchProcessDocumentsRequest( + requests=requests, + ) + + # Make the request + operation = client.batch_process_documents(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END documentai_v1beta2_generated_DocumentUnderstandingService_BatchProcessDocuments_async] diff --git a/samples/generated_samples/documentai_v1beta2_generated_document_understanding_service_batch_process_documents_sync.py b/samples/generated_samples/documentai_v1beta2_generated_document_understanding_service_batch_process_documents_sync.py new file mode 100644 index 00000000..62656b1a --- /dev/null +++ b/samples/generated_samples/documentai_v1beta2_generated_document_understanding_service_batch_process_documents_sync.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BatchProcessDocuments +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-documentai + + +# [START documentai_v1beta2_generated_DocumentUnderstandingService_BatchProcessDocuments_sync] +from google.cloud import documentai_v1beta2 + + +def sample_batch_process_documents(): + # Create a client + client = documentai_v1beta2.DocumentUnderstandingServiceClient() + + # Initialize request argument(s) + requests = documentai_v1beta2.ProcessDocumentRequest() + requests.input_config.gcs_source.uri = "uri_value" + requests.input_config.mime_type = "mime_type_value" + + request = documentai_v1beta2.BatchProcessDocumentsRequest( + requests=requests, + ) + + # Make the request + operation = client.batch_process_documents(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END documentai_v1beta2_generated_DocumentUnderstandingService_BatchProcessDocuments_sync] diff --git a/samples/generated_samples/documentai_v1beta2_generated_document_understanding_service_process_document_async.py b/samples/generated_samples/documentai_v1beta2_generated_document_understanding_service_process_document_async.py new file mode 100644 index 00000000..38d6eda7 --- /dev/null +++ b/samples/generated_samples/documentai_v1beta2_generated_document_understanding_service_process_document_async.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ProcessDocument +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-documentai + + +# [START documentai_v1beta2_generated_DocumentUnderstandingService_ProcessDocument_async] +from google.cloud import documentai_v1beta2 + + +async def sample_process_document(): + # Create a client + client = documentai_v1beta2.DocumentUnderstandingServiceAsyncClient() + + # Initialize request argument(s) + input_config = documentai_v1beta2.InputConfig() + input_config.gcs_source.uri = "uri_value" + input_config.mime_type = "mime_type_value" + + request = documentai_v1beta2.ProcessDocumentRequest( + input_config=input_config, + ) + + # Make the request + response = await client.process_document(request=request) + + # Handle the response + print(response) + +# [END documentai_v1beta2_generated_DocumentUnderstandingService_ProcessDocument_async] diff --git a/samples/generated_samples/documentai_v1beta2_generated_document_understanding_service_process_document_sync.py b/samples/generated_samples/documentai_v1beta2_generated_document_understanding_service_process_document_sync.py new file mode 100644 index 00000000..5a35ccc7 --- /dev/null +++ b/samples/generated_samples/documentai_v1beta2_generated_document_understanding_service_process_document_sync.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ProcessDocument +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-documentai + + +# [START documentai_v1beta2_generated_DocumentUnderstandingService_ProcessDocument_sync] +from google.cloud import documentai_v1beta2 + + +def sample_process_document(): + # Create a client + client = documentai_v1beta2.DocumentUnderstandingServiceClient() + + # Initialize request argument(s) + input_config = documentai_v1beta2.InputConfig() + input_config.gcs_source.uri = "uri_value" + input_config.mime_type = "mime_type_value" + + request = documentai_v1beta2.ProcessDocumentRequest( + input_config=input_config, + ) + + # Make the request + response = client.process_document(request=request) + + # Handle the response + print(response) + +# [END documentai_v1beta2_generated_DocumentUnderstandingService_ProcessDocument_sync] diff --git a/samples/generated_samples/documentai_generated_documentai_v1beta3_document_processor_service_batch_process_documents_async.py b/samples/generated_samples/documentai_v1beta3_generated_document_processor_service_batch_process_documents_async.py similarity index 74% rename from samples/generated_samples/documentai_generated_documentai_v1beta3_document_processor_service_batch_process_documents_async.py rename to samples/generated_samples/documentai_v1beta3_generated_document_processor_service_batch_process_documents_async.py index 63b5ff54..3e9cb614 100644 --- a/samples/generated_samples/documentai_generated_documentai_v1beta3_document_processor_service_batch_process_documents_async.py +++ b/samples/generated_samples/documentai_v1beta3_generated_document_processor_service_batch_process_documents_async.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -23,24 +23,17 @@ # python3 -m pip install google-cloud-documentai -# [START documentai_generated_documentai_v1beta3_DocumentProcessorService_BatchProcessDocuments_async] +# [START documentai_v1beta3_generated_DocumentProcessorService_BatchProcessDocuments_async] from google.cloud import documentai_v1beta3 async def sample_batch_process_documents(): - """Snippet for batch_process_documents""" - # Create a client client = documentai_v1beta3.DocumentProcessorServiceAsyncClient() # Initialize request argument(s) - project = "my-project-id" - location = "us-central1" - processor = "processor_value" - name = f"projects/{project}/locations/{location}/processors/{processor}" - request = documentai_v1beta3.BatchProcessRequest( - name=name, + name="name_value", ) # Make the request @@ -49,6 +42,8 @@ async def sample_batch_process_documents(): print("Waiting for operation to complete...") response = await operation.result() + + # Handle the response print(response) -# [END documentai_generated_documentai_v1beta3_DocumentProcessorService_BatchProcessDocuments_async] +# [END documentai_v1beta3_generated_DocumentProcessorService_BatchProcessDocuments_async] diff --git a/samples/generated_samples/documentai_generated_documentai_v1beta3_document_processor_service_batch_process_documents_sync.py b/samples/generated_samples/documentai_v1beta3_generated_document_processor_service_batch_process_documents_sync.py similarity index 74% rename from samples/generated_samples/documentai_generated_documentai_v1beta3_document_processor_service_batch_process_documents_sync.py rename to samples/generated_samples/documentai_v1beta3_generated_document_processor_service_batch_process_documents_sync.py index 0e541965..3c10c873 100644 --- a/samples/generated_samples/documentai_generated_documentai_v1beta3_document_processor_service_batch_process_documents_sync.py +++ b/samples/generated_samples/documentai_v1beta3_generated_document_processor_service_batch_process_documents_sync.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -23,24 +23,17 @@ # python3 -m pip install google-cloud-documentai -# [START documentai_generated_documentai_v1beta3_DocumentProcessorService_BatchProcessDocuments_sync] +# [START documentai_v1beta3_generated_DocumentProcessorService_BatchProcessDocuments_sync] from google.cloud import documentai_v1beta3 def sample_batch_process_documents(): - """Snippet for batch_process_documents""" - # Create a client client = documentai_v1beta3.DocumentProcessorServiceClient() # Initialize request argument(s) - project = "my-project-id" - location = "us-central1" - processor = "processor_value" - name = f"projects/{project}/locations/{location}/processors/{processor}" - request = documentai_v1beta3.BatchProcessRequest( - name=name, + name="name_value", ) # Make the request @@ -49,6 +42,8 @@ def sample_batch_process_documents(): print("Waiting for operation to complete...") response = operation.result() + + # Handle the response print(response) -# [END documentai_generated_documentai_v1beta3_DocumentProcessorService_BatchProcessDocuments_sync] +# [END documentai_v1beta3_generated_DocumentProcessorService_BatchProcessDocuments_sync] diff --git a/samples/generated_samples/documentai_generated_documentai_v1beta3_document_processor_service_create_processor_async.py b/samples/generated_samples/documentai_v1beta3_generated_document_processor_service_create_processor_async.py similarity index 73% rename from samples/generated_samples/documentai_generated_documentai_v1beta3_document_processor_service_create_processor_async.py rename to samples/generated_samples/documentai_v1beta3_generated_document_processor_service_create_processor_async.py index 05ed108f..39b22910 100644 --- a/samples/generated_samples/documentai_generated_documentai_v1beta3_document_processor_service_create_processor_async.py +++ b/samples/generated_samples/documentai_v1beta3_generated_document_processor_service_create_processor_async.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -23,30 +23,23 @@ # python3 -m pip install google-cloud-documentai -# [START documentai_generated_documentai_v1beta3_DocumentProcessorService_CreateProcessor_async] +# [START documentai_v1beta3_generated_DocumentProcessorService_CreateProcessor_async] from google.cloud import documentai_v1beta3 async def sample_create_processor(): - """Snippet for create_processor""" - # Create a client client = documentai_v1beta3.DocumentProcessorServiceAsyncClient() # Initialize request argument(s) - project = "my-project-id" - location = "us-central1" - processor = "processor_value" - parent = f"projects/{project}/locations/{location}/processors/{processor}" - request = documentai_v1beta3.CreateProcessorRequest( - parent=parent, + parent="parent_value", ) # Make the request response = await client.create_processor(request=request) - # Handle response + # Handle the response print(response) -# [END documentai_generated_documentai_v1beta3_DocumentProcessorService_CreateProcessor_async] +# [END documentai_v1beta3_generated_DocumentProcessorService_CreateProcessor_async] diff --git a/samples/generated_samples/documentai_generated_documentai_v1beta3_document_processor_service_create_processor_sync.py b/samples/generated_samples/documentai_v1beta3_generated_document_processor_service_create_processor_sync.py similarity index 72% rename from samples/generated_samples/documentai_generated_documentai_v1beta3_document_processor_service_create_processor_sync.py rename to samples/generated_samples/documentai_v1beta3_generated_document_processor_service_create_processor_sync.py index edef2692..4633b035 100644 --- a/samples/generated_samples/documentai_generated_documentai_v1beta3_document_processor_service_create_processor_sync.py +++ b/samples/generated_samples/documentai_v1beta3_generated_document_processor_service_create_processor_sync.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -23,30 +23,23 @@ # python3 -m pip install google-cloud-documentai -# [START documentai_generated_documentai_v1beta3_DocumentProcessorService_CreateProcessor_sync] +# [START documentai_v1beta3_generated_DocumentProcessorService_CreateProcessor_sync] from google.cloud import documentai_v1beta3 def sample_create_processor(): - """Snippet for create_processor""" - # Create a client client = documentai_v1beta3.DocumentProcessorServiceClient() # Initialize request argument(s) - project = "my-project-id" - location = "us-central1" - processor = "processor_value" - parent = f"projects/{project}/locations/{location}/processors/{processor}" - request = documentai_v1beta3.CreateProcessorRequest( - parent=parent, + parent="parent_value", ) # Make the request response = client.create_processor(request=request) - # Handle response + # Handle the response print(response) -# [END documentai_generated_documentai_v1beta3_DocumentProcessorService_CreateProcessor_sync] +# [END documentai_v1beta3_generated_DocumentProcessorService_CreateProcessor_sync] diff --git a/samples/generated_samples/documentai_generated_documentai_v1beta3_document_processor_service_delete_processor_async.py b/samples/generated_samples/documentai_v1beta3_generated_document_processor_service_delete_processor_async.py similarity index 75% rename from samples/generated_samples/documentai_generated_documentai_v1beta3_document_processor_service_delete_processor_async.py rename to samples/generated_samples/documentai_v1beta3_generated_document_processor_service_delete_processor_async.py index 10ac66e8..2c52d833 100644 --- a/samples/generated_samples/documentai_generated_documentai_v1beta3_document_processor_service_delete_processor_async.py +++ b/samples/generated_samples/documentai_v1beta3_generated_document_processor_service_delete_processor_async.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -23,24 +23,17 @@ # python3 -m pip install google-cloud-documentai -# [START documentai_generated_documentai_v1beta3_DocumentProcessorService_DeleteProcessor_async] +# [START documentai_v1beta3_generated_DocumentProcessorService_DeleteProcessor_async] from google.cloud import documentai_v1beta3 async def sample_delete_processor(): - """Snippet for delete_processor""" - # Create a client client = documentai_v1beta3.DocumentProcessorServiceAsyncClient() # Initialize request argument(s) - project = "my-project-id" - location = "us-central1" - processor = "processor_value" - name = f"projects/{project}/locations/{location}/processors/{processor}" - request = documentai_v1beta3.DeleteProcessorRequest( - name=name, + name="name_value", ) # Make the request @@ -49,6 +42,8 @@ async def sample_delete_processor(): print("Waiting for operation to complete...") response = await operation.result() + + # Handle the response print(response) -# [END documentai_generated_documentai_v1beta3_DocumentProcessorService_DeleteProcessor_async] +# [END documentai_v1beta3_generated_DocumentProcessorService_DeleteProcessor_async] diff --git a/samples/generated_samples/documentai_generated_documentai_v1beta3_document_processor_service_delete_processor_sync.py b/samples/generated_samples/documentai_v1beta3_generated_document_processor_service_delete_processor_sync.py similarity index 75% rename from samples/generated_samples/documentai_generated_documentai_v1beta3_document_processor_service_delete_processor_sync.py rename to samples/generated_samples/documentai_v1beta3_generated_document_processor_service_delete_processor_sync.py index fbb5dd84..72720ff0 100644 --- a/samples/generated_samples/documentai_generated_documentai_v1beta3_document_processor_service_delete_processor_sync.py +++ b/samples/generated_samples/documentai_v1beta3_generated_document_processor_service_delete_processor_sync.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -23,24 +23,17 @@ # python3 -m pip install google-cloud-documentai -# [START documentai_generated_documentai_v1beta3_DocumentProcessorService_DeleteProcessor_sync] +# [START documentai_v1beta3_generated_DocumentProcessorService_DeleteProcessor_sync] from google.cloud import documentai_v1beta3 def sample_delete_processor(): - """Snippet for delete_processor""" - # Create a client client = documentai_v1beta3.DocumentProcessorServiceClient() # Initialize request argument(s) - project = "my-project-id" - location = "us-central1" - processor = "processor_value" - name = f"projects/{project}/locations/{location}/processors/{processor}" - request = documentai_v1beta3.DeleteProcessorRequest( - name=name, + name="name_value", ) # Make the request @@ -49,6 +42,8 @@ def sample_delete_processor(): print("Waiting for operation to complete...") response = operation.result() + + # Handle the response print(response) -# [END documentai_generated_documentai_v1beta3_DocumentProcessorService_DeleteProcessor_sync] +# [END documentai_v1beta3_generated_DocumentProcessorService_DeleteProcessor_sync] diff --git a/samples/generated_samples/documentai_generated_documentai_v1beta3_document_processor_service_disable_processor_async.py b/samples/generated_samples/documentai_v1beta3_generated_document_processor_service_disable_processor_async.py similarity index 75% rename from samples/generated_samples/documentai_generated_documentai_v1beta3_document_processor_service_disable_processor_async.py rename to samples/generated_samples/documentai_v1beta3_generated_document_processor_service_disable_processor_async.py index 32907a2a..736a9e11 100644 --- a/samples/generated_samples/documentai_generated_documentai_v1beta3_document_processor_service_disable_processor_async.py +++ b/samples/generated_samples/documentai_v1beta3_generated_document_processor_service_disable_processor_async.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -23,24 +23,17 @@ # python3 -m pip install google-cloud-documentai -# [START documentai_generated_documentai_v1beta3_DocumentProcessorService_DisableProcessor_async] +# [START documentai_v1beta3_generated_DocumentProcessorService_DisableProcessor_async] from google.cloud import documentai_v1beta3 async def sample_disable_processor(): - """Snippet for disable_processor""" - # Create a client client = documentai_v1beta3.DocumentProcessorServiceAsyncClient() # Initialize request argument(s) - project = "my-project-id" - location = "us-central1" - processor = "processor_value" - name = f"projects/{project}/locations/{location}/processors/{processor}" - request = documentai_v1beta3.DisableProcessorRequest( - name=name, + name="name_value", ) # Make the request @@ -49,6 +42,8 @@ async def sample_disable_processor(): print("Waiting for operation to complete...") response = await operation.result() + + # Handle the response print(response) -# [END documentai_generated_documentai_v1beta3_DocumentProcessorService_DisableProcessor_async] +# [END documentai_v1beta3_generated_DocumentProcessorService_DisableProcessor_async] diff --git a/samples/generated_samples/documentai_generated_documentai_v1beta3_document_processor_service_disable_processor_sync.py b/samples/generated_samples/documentai_v1beta3_generated_document_processor_service_disable_processor_sync.py similarity index 75% rename from samples/generated_samples/documentai_generated_documentai_v1beta3_document_processor_service_disable_processor_sync.py rename to samples/generated_samples/documentai_v1beta3_generated_document_processor_service_disable_processor_sync.py index f4fa53e5..5870e5b4 100644 --- a/samples/generated_samples/documentai_generated_documentai_v1beta3_document_processor_service_disable_processor_sync.py +++ b/samples/generated_samples/documentai_v1beta3_generated_document_processor_service_disable_processor_sync.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -23,24 +23,17 @@ # python3 -m pip install google-cloud-documentai -# [START documentai_generated_documentai_v1beta3_DocumentProcessorService_DisableProcessor_sync] +# [START documentai_v1beta3_generated_DocumentProcessorService_DisableProcessor_sync] from google.cloud import documentai_v1beta3 def sample_disable_processor(): - """Snippet for disable_processor""" - # Create a client client = documentai_v1beta3.DocumentProcessorServiceClient() # Initialize request argument(s) - project = "my-project-id" - location = "us-central1" - processor = "processor_value" - name = f"projects/{project}/locations/{location}/processors/{processor}" - request = documentai_v1beta3.DisableProcessorRequest( - name=name, + name="name_value", ) # Make the request @@ -49,6 +42,8 @@ def sample_disable_processor(): print("Waiting for operation to complete...") response = operation.result() + + # Handle the response print(response) -# [END documentai_generated_documentai_v1beta3_DocumentProcessorService_DisableProcessor_sync] +# [END documentai_v1beta3_generated_DocumentProcessorService_DisableProcessor_sync] diff --git a/samples/generated_samples/documentai_generated_documentai_v1beta3_document_processor_service_enable_processor_async.py b/samples/generated_samples/documentai_v1beta3_generated_document_processor_service_enable_processor_async.py similarity index 75% rename from samples/generated_samples/documentai_generated_documentai_v1beta3_document_processor_service_enable_processor_async.py rename to samples/generated_samples/documentai_v1beta3_generated_document_processor_service_enable_processor_async.py index 515fa7bd..6f45b3dc 100644 --- a/samples/generated_samples/documentai_generated_documentai_v1beta3_document_processor_service_enable_processor_async.py +++ b/samples/generated_samples/documentai_v1beta3_generated_document_processor_service_enable_processor_async.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -23,24 +23,17 @@ # python3 -m pip install google-cloud-documentai -# [START documentai_generated_documentai_v1beta3_DocumentProcessorService_EnableProcessor_async] +# [START documentai_v1beta3_generated_DocumentProcessorService_EnableProcessor_async] from google.cloud import documentai_v1beta3 async def sample_enable_processor(): - """Snippet for enable_processor""" - # Create a client client = documentai_v1beta3.DocumentProcessorServiceAsyncClient() # Initialize request argument(s) - project = "my-project-id" - location = "us-central1" - processor = "processor_value" - name = f"projects/{project}/locations/{location}/processors/{processor}" - request = documentai_v1beta3.EnableProcessorRequest( - name=name, + name="name_value", ) # Make the request @@ -49,6 +42,8 @@ async def sample_enable_processor(): print("Waiting for operation to complete...") response = await operation.result() + + # Handle the response print(response) -# [END documentai_generated_documentai_v1beta3_DocumentProcessorService_EnableProcessor_async] +# [END documentai_v1beta3_generated_DocumentProcessorService_EnableProcessor_async] diff --git a/samples/generated_samples/documentai_generated_documentai_v1beta3_document_processor_service_enable_processor_sync.py b/samples/generated_samples/documentai_v1beta3_generated_document_processor_service_enable_processor_sync.py similarity index 75% rename from samples/generated_samples/documentai_generated_documentai_v1beta3_document_processor_service_enable_processor_sync.py rename to samples/generated_samples/documentai_v1beta3_generated_document_processor_service_enable_processor_sync.py index 17cc9f76..3577eb37 100644 --- a/samples/generated_samples/documentai_generated_documentai_v1beta3_document_processor_service_enable_processor_sync.py +++ b/samples/generated_samples/documentai_v1beta3_generated_document_processor_service_enable_processor_sync.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -23,24 +23,17 @@ # python3 -m pip install google-cloud-documentai -# [START documentai_generated_documentai_v1beta3_DocumentProcessorService_EnableProcessor_sync] +# [START documentai_v1beta3_generated_DocumentProcessorService_EnableProcessor_sync] from google.cloud import documentai_v1beta3 def sample_enable_processor(): - """Snippet for enable_processor""" - # Create a client client = documentai_v1beta3.DocumentProcessorServiceClient() # Initialize request argument(s) - project = "my-project-id" - location = "us-central1" - processor = "processor_value" - name = f"projects/{project}/locations/{location}/processors/{processor}" - request = documentai_v1beta3.EnableProcessorRequest( - name=name, + name="name_value", ) # Make the request @@ -49,6 +42,8 @@ def sample_enable_processor(): print("Waiting for operation to complete...") response = operation.result() + + # Handle the response print(response) -# [END documentai_generated_documentai_v1beta3_DocumentProcessorService_EnableProcessor_sync] +# [END documentai_v1beta3_generated_DocumentProcessorService_EnableProcessor_sync] diff --git a/samples/generated_samples/documentai_generated_documentai_v1beta3_document_processor_service_fetch_processor_types_async.py b/samples/generated_samples/documentai_v1beta3_generated_document_processor_service_fetch_processor_types_async.py similarity index 72% rename from samples/generated_samples/documentai_generated_documentai_v1beta3_document_processor_service_fetch_processor_types_async.py rename to samples/generated_samples/documentai_v1beta3_generated_document_processor_service_fetch_processor_types_async.py index ba9971de..51d1b171 100644 --- a/samples/generated_samples/documentai_generated_documentai_v1beta3_document_processor_service_fetch_processor_types_async.py +++ b/samples/generated_samples/documentai_v1beta3_generated_document_processor_service_fetch_processor_types_async.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -23,30 +23,23 @@ # python3 -m pip install google-cloud-documentai -# [START documentai_generated_documentai_v1beta3_DocumentProcessorService_FetchProcessorTypes_async] +# [START documentai_v1beta3_generated_DocumentProcessorService_FetchProcessorTypes_async] from google.cloud import documentai_v1beta3 async def sample_fetch_processor_types(): - """Snippet for fetch_processor_types""" - # Create a client client = documentai_v1beta3.DocumentProcessorServiceAsyncClient() # Initialize request argument(s) - project = "my-project-id" - location = "us-central1" - processor_type = "processor_type_value" - parent = f"projects/{project}/locations/{location}/processorTypes/{processor_type}" - request = documentai_v1beta3.FetchProcessorTypesRequest( - parent=parent, + parent="parent_value", ) # Make the request response = await client.fetch_processor_types(request=request) - # Handle response + # Handle the response print(response) -# [END documentai_generated_documentai_v1beta3_DocumentProcessorService_FetchProcessorTypes_async] +# [END documentai_v1beta3_generated_DocumentProcessorService_FetchProcessorTypes_async] diff --git a/samples/generated_samples/documentai_generated_documentai_v1beta3_document_processor_service_fetch_processor_types_sync.py b/samples/generated_samples/documentai_v1beta3_generated_document_processor_service_fetch_processor_types_sync.py similarity index 71% rename from samples/generated_samples/documentai_generated_documentai_v1beta3_document_processor_service_fetch_processor_types_sync.py rename to samples/generated_samples/documentai_v1beta3_generated_document_processor_service_fetch_processor_types_sync.py index 5d2cde3f..5d62280a 100644 --- a/samples/generated_samples/documentai_generated_documentai_v1beta3_document_processor_service_fetch_processor_types_sync.py +++ b/samples/generated_samples/documentai_v1beta3_generated_document_processor_service_fetch_processor_types_sync.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -23,30 +23,23 @@ # python3 -m pip install google-cloud-documentai -# [START documentai_generated_documentai_v1beta3_DocumentProcessorService_FetchProcessorTypes_sync] +# [START documentai_v1beta3_generated_DocumentProcessorService_FetchProcessorTypes_sync] from google.cloud import documentai_v1beta3 def sample_fetch_processor_types(): - """Snippet for fetch_processor_types""" - # Create a client client = documentai_v1beta3.DocumentProcessorServiceClient() # Initialize request argument(s) - project = "my-project-id" - location = "us-central1" - processor_type = "processor_type_value" - parent = f"projects/{project}/locations/{location}/processorTypes/{processor_type}" - request = documentai_v1beta3.FetchProcessorTypesRequest( - parent=parent, + parent="parent_value", ) # Make the request response = client.fetch_processor_types(request=request) - # Handle response + # Handle the response print(response) -# [END documentai_generated_documentai_v1beta3_DocumentProcessorService_FetchProcessorTypes_sync] +# [END documentai_v1beta3_generated_DocumentProcessorService_FetchProcessorTypes_sync] diff --git a/samples/generated_samples/documentai_generated_documentai_v1beta3_document_processor_service_list_processors_async.py b/samples/generated_samples/documentai_v1beta3_generated_document_processor_service_list_processors_async.py similarity index 74% rename from samples/generated_samples/documentai_generated_documentai_v1beta3_document_processor_service_list_processors_async.py rename to samples/generated_samples/documentai_v1beta3_generated_document_processor_service_list_processors_async.py index 2cf1a9e1..000b3b9e 100644 --- a/samples/generated_samples/documentai_generated_documentai_v1beta3_document_processor_service_list_processors_async.py +++ b/samples/generated_samples/documentai_v1beta3_generated_document_processor_service_list_processors_async.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -23,29 +23,24 @@ # python3 -m pip install google-cloud-documentai -# [START documentai_generated_documentai_v1beta3_DocumentProcessorService_ListProcessors_async] +# [START documentai_v1beta3_generated_DocumentProcessorService_ListProcessors_async] from google.cloud import documentai_v1beta3 async def sample_list_processors(): - """Snippet for list_processors""" - # Create a client client = documentai_v1beta3.DocumentProcessorServiceAsyncClient() # Initialize request argument(s) - project = "my-project-id" - location = "us-central1" - processor = "processor_value" - parent = f"projects/{project}/locations/{location}/processors/{processor}" - request = documentai_v1beta3.ListProcessorsRequest( - parent=parent, + parent="parent_value", ) # Make the request page_result = client.list_processors(request=request) + + # Handle the response async for response in page_result: print(response) -# [END documentai_generated_documentai_v1beta3_DocumentProcessorService_ListProcessors_async] +# [END documentai_v1beta3_generated_DocumentProcessorService_ListProcessors_async] diff --git a/samples/generated_samples/documentai_generated_documentai_v1beta3_document_processor_service_list_processors_sync.py b/samples/generated_samples/documentai_v1beta3_generated_document_processor_service_list_processors_sync.py similarity index 74% rename from samples/generated_samples/documentai_generated_documentai_v1beta3_document_processor_service_list_processors_sync.py rename to samples/generated_samples/documentai_v1beta3_generated_document_processor_service_list_processors_sync.py index 6d84b5e5..e334dd35 100644 --- a/samples/generated_samples/documentai_generated_documentai_v1beta3_document_processor_service_list_processors_sync.py +++ b/samples/generated_samples/documentai_v1beta3_generated_document_processor_service_list_processors_sync.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -23,29 +23,24 @@ # python3 -m pip install google-cloud-documentai -# [START documentai_generated_documentai_v1beta3_DocumentProcessorService_ListProcessors_sync] +# [START documentai_v1beta3_generated_DocumentProcessorService_ListProcessors_sync] from google.cloud import documentai_v1beta3 def sample_list_processors(): - """Snippet for list_processors""" - # Create a client client = documentai_v1beta3.DocumentProcessorServiceClient() # Initialize request argument(s) - project = "my-project-id" - location = "us-central1" - processor = "processor_value" - parent = f"projects/{project}/locations/{location}/processors/{processor}" - request = documentai_v1beta3.ListProcessorsRequest( - parent=parent, + parent="parent_value", ) # Make the request page_result = client.list_processors(request=request) + + # Handle the response for response in page_result: print(response) -# [END documentai_generated_documentai_v1beta3_DocumentProcessorService_ListProcessors_sync] +# [END documentai_v1beta3_generated_DocumentProcessorService_ListProcessors_sync] diff --git a/samples/generated_samples/documentai_generated_documentai_v1beta3_document_processor_service_process_document_async.py b/samples/generated_samples/documentai_v1beta3_generated_document_processor_service_process_document_async.py similarity index 75% rename from samples/generated_samples/documentai_generated_documentai_v1beta3_document_processor_service_process_document_async.py rename to samples/generated_samples/documentai_v1beta3_generated_document_processor_service_process_document_async.py index 46c9c117..9b3c664a 100644 --- a/samples/generated_samples/documentai_generated_documentai_v1beta3_document_processor_service_process_document_async.py +++ b/samples/generated_samples/documentai_v1beta3_generated_document_processor_service_process_document_async.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -23,13 +23,11 @@ # python3 -m pip install google-cloud-documentai -# [START documentai_generated_documentai_v1beta3_DocumentProcessorService_ProcessDocument_async] +# [START documentai_v1beta3_generated_DocumentProcessorService_ProcessDocument_async] from google.cloud import documentai_v1beta3 async def sample_process_document(): - """Snippet for process_document""" - # Create a client client = documentai_v1beta3.DocumentProcessorServiceAsyncClient() @@ -37,20 +35,15 @@ async def sample_process_document(): inline_document = documentai_v1beta3.Document() inline_document.uri = "uri_value" - project = "my-project-id" - location = "us-central1" - processor = "processor_value" - name = f"projects/{project}/locations/{location}/processors/{processor}" - request = documentai_v1beta3.ProcessRequest( inline_document=inline_document, - name=name, + name="name_value", ) # Make the request response = await client.process_document(request=request) - # Handle response + # Handle the response print(response) -# [END documentai_generated_documentai_v1beta3_DocumentProcessorService_ProcessDocument_async] +# [END documentai_v1beta3_generated_DocumentProcessorService_ProcessDocument_async] diff --git a/samples/generated_samples/documentai_generated_documentai_v1beta3_document_processor_service_process_document_sync.py b/samples/generated_samples/documentai_v1beta3_generated_document_processor_service_process_document_sync.py similarity index 74% rename from samples/generated_samples/documentai_generated_documentai_v1beta3_document_processor_service_process_document_sync.py rename to samples/generated_samples/documentai_v1beta3_generated_document_processor_service_process_document_sync.py index 259d85c9..e5088abf 100644 --- a/samples/generated_samples/documentai_generated_documentai_v1beta3_document_processor_service_process_document_sync.py +++ b/samples/generated_samples/documentai_v1beta3_generated_document_processor_service_process_document_sync.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -23,13 +23,11 @@ # python3 -m pip install google-cloud-documentai -# [START documentai_generated_documentai_v1beta3_DocumentProcessorService_ProcessDocument_sync] +# [START documentai_v1beta3_generated_DocumentProcessorService_ProcessDocument_sync] from google.cloud import documentai_v1beta3 def sample_process_document(): - """Snippet for process_document""" - # Create a client client = documentai_v1beta3.DocumentProcessorServiceClient() @@ -37,20 +35,15 @@ def sample_process_document(): inline_document = documentai_v1beta3.Document() inline_document.uri = "uri_value" - project = "my-project-id" - location = "us-central1" - processor = "processor_value" - name = f"projects/{project}/locations/{location}/processors/{processor}" - request = documentai_v1beta3.ProcessRequest( inline_document=inline_document, - name=name, + name="name_value", ) # Make the request response = client.process_document(request=request) - # Handle response + # Handle the response print(response) -# [END documentai_generated_documentai_v1beta3_DocumentProcessorService_ProcessDocument_sync] +# [END documentai_v1beta3_generated_DocumentProcessorService_ProcessDocument_sync] diff --git a/samples/generated_samples/documentai_generated_documentai_v1beta3_document_processor_service_review_document_async.py b/samples/generated_samples/documentai_v1beta3_generated_document_processor_service_review_document_async.py similarity index 74% rename from samples/generated_samples/documentai_generated_documentai_v1beta3_document_processor_service_review_document_async.py rename to samples/generated_samples/documentai_v1beta3_generated_document_processor_service_review_document_async.py index c40c5d9c..8fd5481c 100644 --- a/samples/generated_samples/documentai_generated_documentai_v1beta3_document_processor_service_review_document_async.py +++ b/samples/generated_samples/documentai_v1beta3_generated_document_processor_service_review_document_async.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -23,13 +23,11 @@ # python3 -m pip install google-cloud-documentai -# [START documentai_generated_documentai_v1beta3_DocumentProcessorService_ReviewDocument_async] +# [START documentai_v1beta3_generated_DocumentProcessorService_ReviewDocument_async] from google.cloud import documentai_v1beta3 async def sample_review_document(): - """Snippet for review_document""" - # Create a client client = documentai_v1beta3.DocumentProcessorServiceAsyncClient() @@ -37,14 +35,9 @@ async def sample_review_document(): inline_document = documentai_v1beta3.Document() inline_document.uri = "uri_value" - project = "my-project-id" - location = "us-central1" - processor = "processor_value" - human_review_config = f"projects/{project}/locations/{location}/processors/{processor}/humanReviewConfig" - request = documentai_v1beta3.ReviewDocumentRequest( inline_document=inline_document, - human_review_config=human_review_config, + human_review_config="human_review_config_value", ) # Make the request @@ -53,6 +46,8 @@ async def sample_review_document(): print("Waiting for operation to complete...") response = await operation.result() + + # Handle the response print(response) -# [END documentai_generated_documentai_v1beta3_DocumentProcessorService_ReviewDocument_async] +# [END documentai_v1beta3_generated_DocumentProcessorService_ReviewDocument_async] diff --git a/samples/generated_samples/documentai_generated_documentai_v1beta3_document_processor_service_review_document_sync.py b/samples/generated_samples/documentai_v1beta3_generated_document_processor_service_review_document_sync.py similarity index 74% rename from samples/generated_samples/documentai_generated_documentai_v1beta3_document_processor_service_review_document_sync.py rename to samples/generated_samples/documentai_v1beta3_generated_document_processor_service_review_document_sync.py index 30d55799..f3a9eb55 100644 --- a/samples/generated_samples/documentai_generated_documentai_v1beta3_document_processor_service_review_document_sync.py +++ b/samples/generated_samples/documentai_v1beta3_generated_document_processor_service_review_document_sync.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -23,13 +23,11 @@ # python3 -m pip install google-cloud-documentai -# [START documentai_generated_documentai_v1beta3_DocumentProcessorService_ReviewDocument_sync] +# [START documentai_v1beta3_generated_DocumentProcessorService_ReviewDocument_sync] from google.cloud import documentai_v1beta3 def sample_review_document(): - """Snippet for review_document""" - # Create a client client = documentai_v1beta3.DocumentProcessorServiceClient() @@ -37,14 +35,9 @@ def sample_review_document(): inline_document = documentai_v1beta3.Document() inline_document.uri = "uri_value" - project = "my-project-id" - location = "us-central1" - processor = "processor_value" - human_review_config = f"projects/{project}/locations/{location}/processors/{processor}/humanReviewConfig" - request = documentai_v1beta3.ReviewDocumentRequest( inline_document=inline_document, - human_review_config=human_review_config, + human_review_config="human_review_config_value", ) # Make the request @@ -53,6 +46,8 @@ def sample_review_document(): print("Waiting for operation to complete...") response = operation.result() + + # Handle the response print(response) -# [END documentai_generated_documentai_v1beta3_DocumentProcessorService_ReviewDocument_sync] +# [END documentai_v1beta3_generated_DocumentProcessorService_ReviewDocument_sync] diff --git a/samples/generated_samples/snippet_metadata_documentai_v1.json b/samples/generated_samples/snippet_metadata_documentai_v1.json new file mode 100644 index 00000000..e32e56f8 --- /dev/null +++ b/samples/generated_samples/snippet_metadata_documentai_v1.json @@ -0,0 +1,271 @@ +{ + "snippets": [ + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "DocumentProcessorService" + }, + "shortName": "BatchProcessDocuments" + } + }, + "file": "documentai_v1_generated_document_processor_service_batch_process_documents_async.py", + "regionTag": "documentai_v1_generated_DocumentProcessorService_BatchProcessDocuments_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "DocumentProcessorService" + }, + "shortName": "BatchProcessDocuments" + } + }, + "file": "documentai_v1_generated_document_processor_service_batch_process_documents_sync.py", + "regionTag": "documentai_v1_generated_DocumentProcessorService_BatchProcessDocuments_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "DocumentProcessorService" + }, + "shortName": "ProcessDocument" + } + }, + "file": "documentai_v1_generated_document_processor_service_process_document_async.py", + "regionTag": "documentai_v1_generated_DocumentProcessorService_ProcessDocument_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 42, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 43, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "DocumentProcessorService" + }, + "shortName": "ProcessDocument" + } + }, + "file": "documentai_v1_generated_document_processor_service_process_document_sync.py", + "regionTag": "documentai_v1_generated_DocumentProcessorService_ProcessDocument_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 42, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 43, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "DocumentProcessorService" + }, + "shortName": "ReviewDocument" + } + }, + "file": "documentai_v1_generated_document_processor_service_review_document_async.py", + "regionTag": "documentai_v1_generated_DocumentProcessorService_ReviewDocument_async", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 42, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 49, + "start": 43, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 50, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "DocumentProcessorService" + }, + "shortName": "ReviewDocument" + } + }, + "file": "documentai_v1_generated_document_processor_service_review_document_sync.py", + "regionTag": "documentai_v1_generated_DocumentProcessorService_ReviewDocument_sync", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 42, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 49, + "start": 43, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 50, + "type": "RESPONSE_HANDLING" + } + ] + } + ] +} diff --git a/samples/generated_samples/snippet_metadata_documentai_v1beta2.json b/samples/generated_samples/snippet_metadata_documentai_v1beta2.json new file mode 100644 index 00000000..1d18b708 --- /dev/null +++ b/samples/generated_samples/snippet_metadata_documentai_v1beta2.json @@ -0,0 +1,182 @@ +{ + "snippets": [ + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "DocumentUnderstandingService" + }, + "shortName": "BatchProcessDocuments" + } + }, + "file": "documentai_v1beta2_generated_document_understanding_service_batch_process_documents_async.py", + "regionTag": "documentai_v1beta2_generated_DocumentUnderstandingService_BatchProcessDocuments_async", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 42, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 49, + "start": 43, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 50, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "DocumentUnderstandingService" + }, + "shortName": "BatchProcessDocuments" + } + }, + "file": "documentai_v1beta2_generated_document_understanding_service_batch_process_documents_sync.py", + "regionTag": "documentai_v1beta2_generated_DocumentUnderstandingService_BatchProcessDocuments_sync", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 42, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 49, + "start": 43, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 50, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "DocumentUnderstandingService" + }, + "shortName": "ProcessDocument" + } + }, + "file": "documentai_v1beta2_generated_document_understanding_service_process_document_async.py", + "regionTag": "documentai_v1beta2_generated_DocumentUnderstandingService_ProcessDocument_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 42, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 43, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "DocumentUnderstandingService" + }, + "shortName": "ProcessDocument" + } + }, + "file": "documentai_v1beta2_generated_document_understanding_service_process_document_sync.py", + "regionTag": "documentai_v1beta2_generated_DocumentUnderstandingService_ProcessDocument_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 42, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 43, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ] + } + ] +} diff --git a/samples/generated_samples/snippet_metadata_documentai_v1beta3.json b/samples/generated_samples/snippet_metadata_documentai_v1beta3.json new file mode 100644 index 00000000..53d92b3d --- /dev/null +++ b/samples/generated_samples/snippet_metadata_documentai_v1beta3.json @@ -0,0 +1,805 @@ +{ + "snippets": [ + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "DocumentProcessorService" + }, + "shortName": "BatchProcessDocuments" + } + }, + "file": "documentai_v1beta3_generated_document_processor_service_batch_process_documents_async.py", + "regionTag": "documentai_v1beta3_generated_DocumentProcessorService_BatchProcessDocuments_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "DocumentProcessorService" + }, + "shortName": "BatchProcessDocuments" + } + }, + "file": "documentai_v1beta3_generated_document_processor_service_batch_process_documents_sync.py", + "regionTag": "documentai_v1beta3_generated_DocumentProcessorService_BatchProcessDocuments_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "DocumentProcessorService" + }, + "shortName": "CreateProcessor" + } + }, + "file": "documentai_v1beta3_generated_document_processor_service_create_processor_async.py", + "regionTag": "documentai_v1beta3_generated_DocumentProcessorService_CreateProcessor_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "DocumentProcessorService" + }, + "shortName": "CreateProcessor" + } + }, + "file": "documentai_v1beta3_generated_document_processor_service_create_processor_sync.py", + "regionTag": "documentai_v1beta3_generated_DocumentProcessorService_CreateProcessor_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "DocumentProcessorService" + }, + "shortName": "DeleteProcessor" + } + }, + "file": "documentai_v1beta3_generated_document_processor_service_delete_processor_async.py", + "regionTag": "documentai_v1beta3_generated_DocumentProcessorService_DeleteProcessor_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "DocumentProcessorService" + }, + "shortName": "DeleteProcessor" + } + }, + "file": "documentai_v1beta3_generated_document_processor_service_delete_processor_sync.py", + "regionTag": "documentai_v1beta3_generated_DocumentProcessorService_DeleteProcessor_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "DocumentProcessorService" + }, + "shortName": "DisableProcessor" + } + }, + "file": "documentai_v1beta3_generated_document_processor_service_disable_processor_async.py", + "regionTag": "documentai_v1beta3_generated_DocumentProcessorService_DisableProcessor_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "DocumentProcessorService" + }, + "shortName": "DisableProcessor" + } + }, + "file": "documentai_v1beta3_generated_document_processor_service_disable_processor_sync.py", + "regionTag": "documentai_v1beta3_generated_DocumentProcessorService_DisableProcessor_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "DocumentProcessorService" + }, + "shortName": "EnableProcessor" + } + }, + "file": "documentai_v1beta3_generated_document_processor_service_enable_processor_async.py", + "regionTag": "documentai_v1beta3_generated_DocumentProcessorService_EnableProcessor_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "DocumentProcessorService" + }, + "shortName": "EnableProcessor" + } + }, + "file": "documentai_v1beta3_generated_document_processor_service_enable_processor_sync.py", + "regionTag": "documentai_v1beta3_generated_DocumentProcessorService_EnableProcessor_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "DocumentProcessorService" + }, + "shortName": "FetchProcessorTypes" + } + }, + "file": "documentai_v1beta3_generated_document_processor_service_fetch_processor_types_async.py", + "regionTag": "documentai_v1beta3_generated_DocumentProcessorService_FetchProcessorTypes_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "DocumentProcessorService" + }, + "shortName": "FetchProcessorTypes" + } + }, + "file": "documentai_v1beta3_generated_document_processor_service_fetch_processor_types_sync.py", + "regionTag": "documentai_v1beta3_generated_DocumentProcessorService_FetchProcessorTypes_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "DocumentProcessorService" + }, + "shortName": "ListProcessors" + } + }, + "file": "documentai_v1beta3_generated_document_processor_service_list_processors_async.py", + "regionTag": "documentai_v1beta3_generated_DocumentProcessorService_ListProcessors_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "DocumentProcessorService" + }, + "shortName": "ListProcessors" + } + }, + "file": "documentai_v1beta3_generated_document_processor_service_list_processors_sync.py", + "regionTag": "documentai_v1beta3_generated_DocumentProcessorService_ListProcessors_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "DocumentProcessorService" + }, + "shortName": "ProcessDocument" + } + }, + "file": "documentai_v1beta3_generated_document_processor_service_process_document_async.py", + "regionTag": "documentai_v1beta3_generated_DocumentProcessorService_ProcessDocument_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 42, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 43, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "DocumentProcessorService" + }, + "shortName": "ProcessDocument" + } + }, + "file": "documentai_v1beta3_generated_document_processor_service_process_document_sync.py", + "regionTag": "documentai_v1beta3_generated_DocumentProcessorService_ProcessDocument_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 42, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 43, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "DocumentProcessorService" + }, + "shortName": "ReviewDocument" + } + }, + "file": "documentai_v1beta3_generated_document_processor_service_review_document_async.py", + "regionTag": "documentai_v1beta3_generated_DocumentProcessorService_ReviewDocument_async", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 42, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 49, + "start": 43, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 50, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "DocumentProcessorService" + }, + "shortName": "ReviewDocument" + } + }, + "file": "documentai_v1beta3_generated_document_processor_service_review_document_sync.py", + "regionTag": "documentai_v1beta3_generated_DocumentProcessorService_ReviewDocument_sync", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 42, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 49, + "start": 43, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 50, + "type": "RESPONSE_HANDLING" + } + ] + } + ] +} diff --git a/samples/snippets/noxfile.py b/samples/snippets/noxfile.py index 3bbef5d5..85f5836d 100644 --- a/samples/snippets/noxfile.py +++ b/samples/snippets/noxfile.py @@ -187,42 +187,53 @@ def _session_tests( ) -> None: # check for presence of tests test_list = glob.glob("*_test.py") + glob.glob("test_*.py") + test_list.extend(glob.glob("tests")) + if len(test_list) == 0: print("No tests found, skipping directory.") - else: - if TEST_CONFIG["pip_version_override"]: - pip_version = TEST_CONFIG["pip_version_override"] - session.install(f"pip=={pip_version}") - """Runs py.test for a particular project.""" - if os.path.exists("requirements.txt"): - if os.path.exists("constraints.txt"): - session.install("-r", "requirements.txt", "-c", "constraints.txt") - else: - session.install("-r", "requirements.txt") - - if os.path.exists("requirements-test.txt"): - if os.path.exists("constraints-test.txt"): - session.install( - "-r", "requirements-test.txt", "-c", "constraints-test.txt" - ) - else: - session.install("-r", "requirements-test.txt") - - if INSTALL_LIBRARY_FROM_SOURCE: - session.install("-e", _get_repo_root()) - - if post_install: - post_install(session) - - session.run( - "pytest", - *(PYTEST_COMMON_ARGS + session.posargs), - # Pytest will return 5 when no tests are collected. This can happen - # on travis where slow and flaky tests are excluded. - # See http://doc.pytest.org/en/latest/_modules/_pytest/main.html - success_codes=[0, 5], - env=get_pytest_env_vars(), - ) + return + + if TEST_CONFIG["pip_version_override"]: + pip_version = TEST_CONFIG["pip_version_override"] + session.install(f"pip=={pip_version}") + """Runs py.test for a particular project.""" + concurrent_args = [] + if os.path.exists("requirements.txt"): + if os.path.exists("constraints.txt"): + session.install("-r", "requirements.txt", "-c", "constraints.txt") + else: + session.install("-r", "requirements.txt") + with open("requirements.txt") as rfile: + packages = rfile.read() + + if os.path.exists("requirements-test.txt"): + if os.path.exists("constraints-test.txt"): + session.install("-r", "requirements-test.txt", "-c", "constraints-test.txt") + else: + session.install("-r", "requirements-test.txt") + with open("requirements-test.txt") as rtfile: + packages += rtfile.read() + + if INSTALL_LIBRARY_FROM_SOURCE: + session.install("-e", _get_repo_root()) + + if post_install: + post_install(session) + + if "pytest-parallel" in packages: + concurrent_args.extend(["--workers", "auto", "--tests-per-worker", "auto"]) + elif "pytest-xdist" in packages: + concurrent_args.extend(["-n", "auto"]) + + session.run( + "pytest", + *(PYTEST_COMMON_ARGS + session.posargs + concurrent_args), + # Pytest will return 5 when no tests are collected. This can happen + # on travis where slow and flaky tests are excluded. + # See http://doc.pytest.org/en/latest/_modules/_pytest/main.html + success_codes=[0, 5], + env=get_pytest_env_vars(), + ) @nox.session(python=ALL_VERSIONS) diff --git a/samples/snippets/process_document_splitter_sample_test.py b/samples/snippets/process_document_splitter_sample_test.py index 81f32905..df0baf26 100644 --- a/samples/snippets/process_document_splitter_sample_test.py +++ b/samples/snippets/process_document_splitter_sample_test.py @@ -33,6 +33,9 @@ def test_process_documents(capsys): ) out, _ = capsys.readouterr() + # Remove newlines and quotes from output for easier comparison + out = out.replace(' "" ', " ").replace("\n", "") + expected_strings = [ "Found 8 subdocuments", "confident that pages 1 to 2 are a subdocument", diff --git a/samples/snippets/requirements-test.txt b/samples/snippets/requirements-test.txt index 92709451..c2845bff 100644 --- a/samples/snippets/requirements-test.txt +++ b/samples/snippets/requirements-test.txt @@ -1 +1 @@ -pytest==6.2.5 +pytest==7.0.1 diff --git a/samples/snippets/requirements.txt b/samples/snippets/requirements.txt index 16658b4a..22c75a38 100644 --- a/samples/snippets/requirements.txt +++ b/samples/snippets/requirements.txt @@ -1,2 +1,2 @@ -google-cloud-documentai==1.2.0 -google-cloud-storage==2.0.0 +google-cloud-documentai==1.2.1 +google-cloud-storage==2.1.0 diff --git a/scripts/fixup_documentai_v1_keywords.py b/scripts/fixup_documentai_v1_keywords.py index e296b746..fbe6d384 100644 --- a/scripts/fixup_documentai_v1_keywords.py +++ b/scripts/fixup_documentai_v1_keywords.py @@ -1,6 +1,6 @@ #! /usr/bin/env python3 # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/scripts/fixup_documentai_v1beta2_keywords.py b/scripts/fixup_documentai_v1beta2_keywords.py index edc0fbd2..bb31619b 100644 --- a/scripts/fixup_documentai_v1beta2_keywords.py +++ b/scripts/fixup_documentai_v1beta2_keywords.py @@ -1,6 +1,6 @@ #! /usr/bin/env python3 # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/scripts/fixup_documentai_v1beta3_keywords.py b/scripts/fixup_documentai_v1beta3_keywords.py index 74059427..c2b7e32e 100644 --- a/scripts/fixup_documentai_v1beta3_keywords.py +++ b/scripts/fixup_documentai_v1beta3_keywords.py @@ -1,6 +1,6 @@ #! /usr/bin/env python3 # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/setup.py b/setup.py index 10a9359d..3b6b4202 100644 --- a/setup.py +++ b/setup.py @@ -19,7 +19,7 @@ import os import setuptools # type: ignore -version = "1.2.1" +version = "1.3.0" package_root = os.path.abspath(os.path.dirname(__file__)) @@ -48,11 +48,10 @@ # NOTE: Maintainers, please do not require google-api-core>=2.x.x # Until this issue is closed # https://github.com/googleapis/google-cloud-python/issues/10566 - "google-api-core[grpc] >= 1.28.0, <3.0.0dev", - "proto-plus >= 1.10.0", + "google-api-core[grpc] >= 1.31.5, <3.0.0dev,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.0", + "proto-plus >= 1.15.0", ), python_requires=">=3.6", - setup_requires=["libcst >= 0.2.5"], classifiers=[ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", diff --git a/testing/constraints-3.6.txt b/testing/constraints-3.6.txt index da8c5737..b666ca6c 100644 --- a/testing/constraints-3.6.txt +++ b/testing/constraints-3.6.txt @@ -5,5 +5,5 @@ # # e.g., if setup.py has "foo >= 1.14.0, < 2.0.0dev", # Then this file should have foo==1.14.0 -google-api-core==1.28.0 -proto-plus==1.10.0 +google-api-core==1.31.5 +proto-plus==1.15.0 diff --git a/tests/__init__.py b/tests/__init__.py index 4de65971..e8e1c384 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tests/unit/__init__.py b/tests/unit/__init__.py index 4de65971..e8e1c384 100644 --- a/tests/unit/__init__.py +++ b/tests/unit/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tests/unit/gapic/__init__.py b/tests/unit/gapic/__init__.py index 4de65971..e8e1c384 100644 --- a/tests/unit/gapic/__init__.py +++ b/tests/unit/gapic/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tests/unit/gapic/documentai_v1/__init__.py b/tests/unit/gapic/documentai_v1/__init__.py index 4de65971..e8e1c384 100644 --- a/tests/unit/gapic/documentai_v1/__init__.py +++ b/tests/unit/gapic/documentai_v1/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tests/unit/gapic/documentai_v1/test_document_processor_service.py b/tests/unit/gapic/documentai_v1/test_document_processor_service.py index a4e384ed..f2674284 100644 --- a/tests/unit/gapic/documentai_v1/test_document_processor_service.py +++ b/tests/unit/gapic/documentai_v1/test_document_processor_service.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -29,6 +29,7 @@ from google.api_core import gapic_v1 from google.api_core import grpc_helpers from google.api_core import grpc_helpers_async +from google.api_core import operation from google.api_core import operation_async # type: ignore from google.api_core import operations_v1 from google.api_core import path_template @@ -436,6 +437,90 @@ def test_document_processor_service_client_mtls_env_auto( ) +@pytest.mark.parametrize( + "client_class", + [DocumentProcessorServiceClient, DocumentProcessorServiceAsyncClient], +) +@mock.patch.object( + DocumentProcessorServiceClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(DocumentProcessorServiceClient), +) +@mock.patch.object( + DocumentProcessorServiceAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(DocumentProcessorServiceAsyncClient), +) +def test_document_processor_service_client_get_mtls_endpoint_and_cert_source( + client_class, +): + mock_client_cert_source = mock.Mock() + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "true". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source == mock_client_cert_source + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "false". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + mock_client_cert_source = mock.Mock() + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "never". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "always". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert doesn't exist. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=False, + ): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert exists. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=True, + ): + with mock.patch( + "google.auth.transport.mtls.default_client_cert_source", + return_value=mock_client_cert_source, + ): + ( + api_endpoint, + cert_source, + ) = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source == mock_client_cert_source + + @pytest.mark.parametrize( "client_class,transport_class,transport_name", [ @@ -472,25 +557,28 @@ def test_document_processor_service_client_client_options_scopes( @pytest.mark.parametrize( - "client_class,transport_class,transport_name", + "client_class,transport_class,transport_name,grpc_helpers", [ ( DocumentProcessorServiceClient, transports.DocumentProcessorServiceGrpcTransport, "grpc", + grpc_helpers, ), ( DocumentProcessorServiceAsyncClient, transports.DocumentProcessorServiceGrpcAsyncIOTransport, "grpc_asyncio", + grpc_helpers_async, ), ], ) def test_document_processor_service_client_client_options_credentials_file( - client_class, transport_class, transport_name + client_class, transport_class, transport_name, grpc_helpers ): # Check the case credentials file is provided. options = client_options.ClientOptions(credentials_file="credentials.json") + with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None client = client_class(client_options=options, transport=transport_name) @@ -526,6 +614,72 @@ def test_document_processor_service_client_client_options_from_dict(): ) +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + ( + DocumentProcessorServiceClient, + transports.DocumentProcessorServiceGrpcTransport, + "grpc", + grpc_helpers, + ), + ( + DocumentProcessorServiceAsyncClient, + transports.DocumentProcessorServiceGrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_document_processor_service_client_create_channel_credentials_file( + client_class, transport_class, transport_name, grpc_helpers +): + # Check the case credentials file is provided. + options = client_options.ClientOptions(credentials_file="credentials.json") + + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file="credentials.json", + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # test that the credentials from file are saved and used as the credentials. + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel" + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + file_creds = ga_credentials.AnonymousCredentials() + load_creds.return_value = (file_creds, None) + adc.return_value = (creds, None) + client = client_class(client_options=options, transport=transport_name) + create_channel.assert_called_with( + "documentai.googleapis.com:443", + credentials=file_creds, + credentials_file=None, + quota_project_id=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, + default_host="documentai.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + @pytest.mark.parametrize( "request_type", [document_processor_service.ProcessRequest, dict,] ) @@ -1194,6 +1348,25 @@ def test_credentials_transport_error(): transport=transport, ) + # It is an error to provide an api_key and a transport instance. + transport = transports.DocumentProcessorServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = DocumentProcessorServiceClient( + client_options=options, transport=transport, + ) + + # It is an error to provide an api_key and a credential. + options = mock.Mock() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = DocumentProcessorServiceClient( + client_options=options, credentials=ga_credentials.AnonymousCredentials() + ) + # It is an error to provide scopes and a transport instance. transport = transports.DocumentProcessorServiceGrpcTransport( credentials=ga_credentials.AnonymousCredentials(), @@ -1820,3 +1993,39 @@ def test_client_ctx(): with client: pass close.assert_called() + + +@pytest.mark.parametrize( + "client_class,transport_class", + [ + ( + DocumentProcessorServiceClient, + transports.DocumentProcessorServiceGrpcTransport, + ), + ( + DocumentProcessorServiceAsyncClient, + transports.DocumentProcessorServiceGrpcAsyncIOTransport, + ), + ], +) +def test_api_key_credentials(client_class, transport_class): + with mock.patch.object( + google.auth._default, "get_api_key_credentials", create=True + ) as get_api_key_credentials: + mock_cred = mock.Mock() + get_api_key_credentials.return_value = mock_cred + options = client_options.ClientOptions() + options.api_key = "api_key" + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options) + patched.assert_called_once_with( + credentials=mock_cred, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) diff --git a/tests/unit/gapic/documentai_v1beta2/__init__.py b/tests/unit/gapic/documentai_v1beta2/__init__.py index 4de65971..e8e1c384 100644 --- a/tests/unit/gapic/documentai_v1beta2/__init__.py +++ b/tests/unit/gapic/documentai_v1beta2/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tests/unit/gapic/documentai_v1beta2/test_document_understanding_service.py b/tests/unit/gapic/documentai_v1beta2/test_document_understanding_service.py index 4d9c59ec..8f31ff05 100644 --- a/tests/unit/gapic/documentai_v1beta2/test_document_understanding_service.py +++ b/tests/unit/gapic/documentai_v1beta2/test_document_understanding_service.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -29,6 +29,7 @@ from google.api_core import gapic_v1 from google.api_core import grpc_helpers from google.api_core import grpc_helpers_async +from google.api_core import operation from google.api_core import operation_async # type: ignore from google.api_core import operations_v1 from google.api_core import path_template @@ -430,6 +431,90 @@ def test_document_understanding_service_client_mtls_env_auto( ) +@pytest.mark.parametrize( + "client_class", + [DocumentUnderstandingServiceClient, DocumentUnderstandingServiceAsyncClient], +) +@mock.patch.object( + DocumentUnderstandingServiceClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(DocumentUnderstandingServiceClient), +) +@mock.patch.object( + DocumentUnderstandingServiceAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(DocumentUnderstandingServiceAsyncClient), +) +def test_document_understanding_service_client_get_mtls_endpoint_and_cert_source( + client_class, +): + mock_client_cert_source = mock.Mock() + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "true". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source == mock_client_cert_source + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "false". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + mock_client_cert_source = mock.Mock() + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "never". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "always". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert doesn't exist. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=False, + ): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert exists. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=True, + ): + with mock.patch( + "google.auth.transport.mtls.default_client_cert_source", + return_value=mock_client_cert_source, + ): + ( + api_endpoint, + cert_source, + ) = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source == mock_client_cert_source + + @pytest.mark.parametrize( "client_class,transport_class,transport_name", [ @@ -466,25 +551,28 @@ def test_document_understanding_service_client_client_options_scopes( @pytest.mark.parametrize( - "client_class,transport_class,transport_name", + "client_class,transport_class,transport_name,grpc_helpers", [ ( DocumentUnderstandingServiceClient, transports.DocumentUnderstandingServiceGrpcTransport, "grpc", + grpc_helpers, ), ( DocumentUnderstandingServiceAsyncClient, transports.DocumentUnderstandingServiceGrpcAsyncIOTransport, "grpc_asyncio", + grpc_helpers_async, ), ], ) def test_document_understanding_service_client_client_options_credentials_file( - client_class, transport_class, transport_name + client_class, transport_class, transport_name, grpc_helpers ): # Check the case credentials file is provided. options = client_options.ClientOptions(credentials_file="credentials.json") + with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None client = client_class(client_options=options, transport=transport_name) @@ -520,6 +608,72 @@ def test_document_understanding_service_client_client_options_from_dict(): ) +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + ( + DocumentUnderstandingServiceClient, + transports.DocumentUnderstandingServiceGrpcTransport, + "grpc", + grpc_helpers, + ), + ( + DocumentUnderstandingServiceAsyncClient, + transports.DocumentUnderstandingServiceGrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_document_understanding_service_client_create_channel_credentials_file( + client_class, transport_class, transport_name, grpc_helpers +): + # Check the case credentials file is provided. + options = client_options.ClientOptions(credentials_file="credentials.json") + + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file="credentials.json", + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # test that the credentials from file are saved and used as the credentials. + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel" + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + file_creds = ga_credentials.AnonymousCredentials() + load_creds.return_value = (file_creds, None) + adc.return_value = (creds, None) + client = client_class(client_options=options, transport=transport_name) + create_channel.assert_called_with( + "documentai.googleapis.com:443", + credentials=file_creds, + credentials_file=None, + quota_project_id=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, + default_host="documentai.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + @pytest.mark.parametrize( "request_type", [document_understanding.BatchProcessDocumentsRequest, dict,] ) @@ -916,6 +1070,25 @@ def test_credentials_transport_error(): transport=transport, ) + # It is an error to provide an api_key and a transport instance. + transport = transports.DocumentUnderstandingServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = DocumentUnderstandingServiceClient( + client_options=options, transport=transport, + ) + + # It is an error to provide an api_key and a credential. + options = mock.Mock() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = DocumentUnderstandingServiceClient( + client_options=options, credentials=ga_credentials.AnonymousCredentials() + ) + # It is an error to provide scopes and a transport instance. transport = transports.DocumentUnderstandingServiceGrpcTransport( credentials=ga_credentials.AnonymousCredentials(), @@ -1498,3 +1671,39 @@ def test_client_ctx(): with client: pass close.assert_called() + + +@pytest.mark.parametrize( + "client_class,transport_class", + [ + ( + DocumentUnderstandingServiceClient, + transports.DocumentUnderstandingServiceGrpcTransport, + ), + ( + DocumentUnderstandingServiceAsyncClient, + transports.DocumentUnderstandingServiceGrpcAsyncIOTransport, + ), + ], +) +def test_api_key_credentials(client_class, transport_class): + with mock.patch.object( + google.auth._default, "get_api_key_credentials", create=True + ) as get_api_key_credentials: + mock_cred = mock.Mock() + get_api_key_credentials.return_value = mock_cred + options = client_options.ClientOptions() + options.api_key = "api_key" + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options) + patched.assert_called_once_with( + credentials=mock_cred, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) diff --git a/tests/unit/gapic/documentai_v1beta3/__init__.py b/tests/unit/gapic/documentai_v1beta3/__init__.py index 4de65971..e8e1c384 100644 --- a/tests/unit/gapic/documentai_v1beta3/__init__.py +++ b/tests/unit/gapic/documentai_v1beta3/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tests/unit/gapic/documentai_v1beta3/test_document_processor_service.py b/tests/unit/gapic/documentai_v1beta3/test_document_processor_service.py index 2bac0ae9..39bcd6a2 100644 --- a/tests/unit/gapic/documentai_v1beta3/test_document_processor_service.py +++ b/tests/unit/gapic/documentai_v1beta3/test_document_processor_service.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -29,6 +29,7 @@ from google.api_core import gapic_v1 from google.api_core import grpc_helpers from google.api_core import grpc_helpers_async +from google.api_core import operation from google.api_core import operation_async # type: ignore from google.api_core import operations_v1 from google.api_core import path_template @@ -442,6 +443,90 @@ def test_document_processor_service_client_mtls_env_auto( ) +@pytest.mark.parametrize( + "client_class", + [DocumentProcessorServiceClient, DocumentProcessorServiceAsyncClient], +) +@mock.patch.object( + DocumentProcessorServiceClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(DocumentProcessorServiceClient), +) +@mock.patch.object( + DocumentProcessorServiceAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(DocumentProcessorServiceAsyncClient), +) +def test_document_processor_service_client_get_mtls_endpoint_and_cert_source( + client_class, +): + mock_client_cert_source = mock.Mock() + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "true". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source == mock_client_cert_source + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "false". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + mock_client_cert_source = mock.Mock() + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "never". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "always". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert doesn't exist. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=False, + ): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert exists. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=True, + ): + with mock.patch( + "google.auth.transport.mtls.default_client_cert_source", + return_value=mock_client_cert_source, + ): + ( + api_endpoint, + cert_source, + ) = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source == mock_client_cert_source + + @pytest.mark.parametrize( "client_class,transport_class,transport_name", [ @@ -478,25 +563,28 @@ def test_document_processor_service_client_client_options_scopes( @pytest.mark.parametrize( - "client_class,transport_class,transport_name", + "client_class,transport_class,transport_name,grpc_helpers", [ ( DocumentProcessorServiceClient, transports.DocumentProcessorServiceGrpcTransport, "grpc", + grpc_helpers, ), ( DocumentProcessorServiceAsyncClient, transports.DocumentProcessorServiceGrpcAsyncIOTransport, "grpc_asyncio", + grpc_helpers_async, ), ], ) def test_document_processor_service_client_client_options_credentials_file( - client_class, transport_class, transport_name + client_class, transport_class, transport_name, grpc_helpers ): # Check the case credentials file is provided. options = client_options.ClientOptions(credentials_file="credentials.json") + with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None client = client_class(client_options=options, transport=transport_name) @@ -532,6 +620,72 @@ def test_document_processor_service_client_client_options_from_dict(): ) +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + ( + DocumentProcessorServiceClient, + transports.DocumentProcessorServiceGrpcTransport, + "grpc", + grpc_helpers, + ), + ( + DocumentProcessorServiceAsyncClient, + transports.DocumentProcessorServiceGrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_document_processor_service_client_create_channel_credentials_file( + client_class, transport_class, transport_name, grpc_helpers +): + # Check the case credentials file is provided. + options = client_options.ClientOptions(credentials_file="credentials.json") + + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file="credentials.json", + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # test that the credentials from file are saved and used as the credentials. + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel" + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + file_creds = ga_credentials.AnonymousCredentials() + load_creds.return_value = (file_creds, None) + adc.return_value = (creds, None) + client = client_class(client_options=options, transport=transport_name) + create_channel.assert_called_with( + "documentai.googleapis.com:443", + credentials=file_creds, + credentials_file=None, + quota_project_id=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, + default_host="documentai.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + @pytest.mark.parametrize( "request_type", [document_processor_service.ProcessRequest, dict,] ) @@ -2532,6 +2686,25 @@ def test_credentials_transport_error(): transport=transport, ) + # It is an error to provide an api_key and a transport instance. + transport = transports.DocumentProcessorServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = DocumentProcessorServiceClient( + client_options=options, transport=transport, + ) + + # It is an error to provide an api_key and a credential. + options = mock.Mock() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = DocumentProcessorServiceClient( + client_options=options, credentials=ga_credentials.AnonymousCredentials() + ) + # It is an error to provide scopes and a transport instance. transport = transports.DocumentProcessorServiceGrpcTransport( credentials=ga_credentials.AnonymousCredentials(), @@ -3190,3 +3363,39 @@ def test_client_ctx(): with client: pass close.assert_called() + + +@pytest.mark.parametrize( + "client_class,transport_class", + [ + ( + DocumentProcessorServiceClient, + transports.DocumentProcessorServiceGrpcTransport, + ), + ( + DocumentProcessorServiceAsyncClient, + transports.DocumentProcessorServiceGrpcAsyncIOTransport, + ), + ], +) +def test_api_key_credentials(client_class, transport_class): + with mock.patch.object( + google.auth._default, "get_api_key_credentials", create=True + ) as get_api_key_credentials: + mock_cred = mock.Mock() + get_api_key_credentials.return_value = mock_cred + options = client_options.ClientOptions() + options.api_key = "api_key" + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options) + patched.assert_called_once_with( + credentials=mock_cred, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + )