Skip to main content

google_cloud_documentai_v1/
client.rs

1// Copyright 2025 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//
15// Code generated by sidekick. DO NOT EDIT.
16#![allow(rustdoc::redundant_explicit_links)]
17#![allow(rustdoc::broken_intra_doc_links)]
18
19/// Implements a client for the Cloud Document AI API.
20///
21/// # Example
22/// ```
23/// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
24/// # use google_cloud_documentai_v1::client::DocumentProcessorService;
25/// let client = DocumentProcessorService::builder().build().await?;
26/// // use `client` to make requests to the Cloud Document AI API.
27/// # Ok(()) }
28/// ```
29///
30/// # Service Description
31///
32/// Service to call Document AI to process documents according to the
33/// processor's definition. Processors are built using state-of-the-art Google
34/// AI such as natural language, computer vision, and translation to extract
35/// structured information from unstructured or semi-structured documents.
36///
37/// # Configuration
38///
39/// To configure `DocumentProcessorService` use the `with_*` methods in the type returned
40/// by [builder()][DocumentProcessorService::builder]. The default configuration should
41/// work for most applications. Common configuration changes include
42///
43/// * [with_endpoint()]: by default this client uses the global default endpoint
44///   (`https://documentai.googleapis.com`). Applications using regional
45///   endpoints or running in restricted networks (e.g. a network configured
46//    with [Private Google Access with VPC Service Controls]) may want to
47///   override this default.
48/// * [with_credentials()]: by default this client uses
49///   [Application Default Credentials]. Applications using custom
50///   authentication may need to override this default.
51///
52/// [with_endpoint()]: super::builder::document_processor_service::ClientBuilder::with_endpoint
53/// [with_credentials()]: super::builder::document_processor_service::ClientBuilder::credentials
54/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
55/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
56///
57/// # Pooling and Cloning
58///
59/// `DocumentProcessorService` holds a connection pool internally, it is advised to
60/// create one and the reuse it.  You do not need to wrap `DocumentProcessorService` in
61/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
62/// already uses an `Arc` internally.
63#[derive(Clone, Debug)]
64pub struct DocumentProcessorService {
65    inner: std::sync::Arc<dyn super::stub::dynamic::DocumentProcessorService>,
66}
67
68impl DocumentProcessorService {
69    /// Returns a builder for [DocumentProcessorService].
70    ///
71    /// ```
72    /// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
73    /// # use google_cloud_documentai_v1::client::DocumentProcessorService;
74    /// let client = DocumentProcessorService::builder().build().await?;
75    /// # Ok(()) }
76    /// ```
77    pub fn builder() -> super::builder::document_processor_service::ClientBuilder {
78        crate::new_client_builder(super::builder::document_processor_service::client::Factory)
79    }
80
81    /// Creates a new client from the provided stub.
82    ///
83    /// The most common case for calling this function is in tests mocking the
84    /// client's behavior.
85    pub fn from_stub<T>(stub: T) -> Self
86    where
87        T: super::stub::DocumentProcessorService + 'static,
88    {
89        Self {
90            inner: std::sync::Arc::new(stub),
91        }
92    }
93
94    pub(crate) async fn new(
95        config: gaxi::options::ClientConfig,
96    ) -> crate::ClientBuilderResult<Self> {
97        let inner = Self::build_inner(config).await?;
98        Ok(Self { inner })
99    }
100
101    async fn build_inner(
102        conf: gaxi::options::ClientConfig,
103    ) -> crate::ClientBuilderResult<
104        std::sync::Arc<dyn super::stub::dynamic::DocumentProcessorService>,
105    > {
106        if gaxi::options::tracing_enabled(&conf) {
107            return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
108        }
109        Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
110    }
111
112    async fn build_transport(
113        conf: gaxi::options::ClientConfig,
114    ) -> crate::ClientBuilderResult<impl super::stub::DocumentProcessorService> {
115        super::transport::DocumentProcessorService::new(conf).await
116    }
117
118    async fn build_with_tracing(
119        conf: gaxi::options::ClientConfig,
120    ) -> crate::ClientBuilderResult<impl super::stub::DocumentProcessorService> {
121        Self::build_transport(conf)
122            .await
123            .map(super::tracing::DocumentProcessorService::new)
124    }
125
126    /// Processes a single document.
127    pub fn process_document(&self) -> super::builder::document_processor_service::ProcessDocument {
128        super::builder::document_processor_service::ProcessDocument::new(self.inner.clone())
129    }
130
131    /// LRO endpoint to batch process many documents. The output is written
132    /// to Cloud Storage as JSON in the [Document] format.
133    ///
134    /// # Long running operations
135    ///
136    /// This method is used to start, and/or poll a [long-running Operation].
137    /// The [Working with long-running operations] chapter in the [user guide]
138    /// covers these operations in detail.
139    ///
140    /// [long-running operation]: https://google.aip.dev/151
141    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
142    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
143    pub fn batch_process_documents(
144        &self,
145    ) -> super::builder::document_processor_service::BatchProcessDocuments {
146        super::builder::document_processor_service::BatchProcessDocuments::new(self.inner.clone())
147    }
148
149    /// Fetches processor types. Note that we don't use
150    /// [ListProcessorTypes][google.cloud.documentai.v1.DocumentProcessorService.ListProcessorTypes]
151    /// here, because it isn't paginated.
152    ///
153    /// [google.cloud.documentai.v1.DocumentProcessorService.ListProcessorTypes]: crate::client::DocumentProcessorService::list_processor_types
154    pub fn fetch_processor_types(
155        &self,
156    ) -> super::builder::document_processor_service::FetchProcessorTypes {
157        super::builder::document_processor_service::FetchProcessorTypes::new(self.inner.clone())
158    }
159
160    /// Lists the processor types that exist.
161    pub fn list_processor_types(
162        &self,
163    ) -> super::builder::document_processor_service::ListProcessorTypes {
164        super::builder::document_processor_service::ListProcessorTypes::new(self.inner.clone())
165    }
166
167    /// Gets a processor type detail.
168    pub fn get_processor_type(
169        &self,
170    ) -> super::builder::document_processor_service::GetProcessorType {
171        super::builder::document_processor_service::GetProcessorType::new(self.inner.clone())
172    }
173
174    /// Lists all processors which belong to this project.
175    pub fn list_processors(&self) -> super::builder::document_processor_service::ListProcessors {
176        super::builder::document_processor_service::ListProcessors::new(self.inner.clone())
177    }
178
179    /// Gets a processor detail.
180    pub fn get_processor(&self) -> super::builder::document_processor_service::GetProcessor {
181        super::builder::document_processor_service::GetProcessor::new(self.inner.clone())
182    }
183
184    /// Trains a new processor version.
185    /// Operation metadata is returned as
186    /// [TrainProcessorVersionMetadata][google.cloud.documentai.v1.TrainProcessorVersionMetadata].
187    ///
188    /// [google.cloud.documentai.v1.TrainProcessorVersionMetadata]: crate::model::TrainProcessorVersionMetadata
189    ///
190    /// # Long running operations
191    ///
192    /// This method is used to start, and/or poll a [long-running Operation].
193    /// The [Working with long-running operations] chapter in the [user guide]
194    /// covers these operations in detail.
195    ///
196    /// [long-running operation]: https://google.aip.dev/151
197    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
198    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
199    pub fn train_processor_version(
200        &self,
201    ) -> super::builder::document_processor_service::TrainProcessorVersion {
202        super::builder::document_processor_service::TrainProcessorVersion::new(self.inner.clone())
203    }
204
205    /// Gets a processor version detail.
206    pub fn get_processor_version(
207        &self,
208    ) -> super::builder::document_processor_service::GetProcessorVersion {
209        super::builder::document_processor_service::GetProcessorVersion::new(self.inner.clone())
210    }
211
212    /// Lists all versions of a processor.
213    pub fn list_processor_versions(
214        &self,
215    ) -> super::builder::document_processor_service::ListProcessorVersions {
216        super::builder::document_processor_service::ListProcessorVersions::new(self.inner.clone())
217    }
218
219    /// Deletes the processor version, all artifacts under the processor version
220    /// will be deleted.
221    ///
222    /// # Long running operations
223    ///
224    /// This method is used to start, and/or poll a [long-running Operation].
225    /// The [Working with long-running operations] chapter in the [user guide]
226    /// covers these operations in detail.
227    ///
228    /// [long-running operation]: https://google.aip.dev/151
229    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
230    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
231    pub fn delete_processor_version(
232        &self,
233    ) -> super::builder::document_processor_service::DeleteProcessorVersion {
234        super::builder::document_processor_service::DeleteProcessorVersion::new(self.inner.clone())
235    }
236
237    /// Deploys the processor version.
238    ///
239    /// # Long running operations
240    ///
241    /// This method is used to start, and/or poll a [long-running Operation].
242    /// The [Working with long-running operations] chapter in the [user guide]
243    /// covers these operations in detail.
244    ///
245    /// [long-running operation]: https://google.aip.dev/151
246    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
247    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
248    pub fn deploy_processor_version(
249        &self,
250    ) -> super::builder::document_processor_service::DeployProcessorVersion {
251        super::builder::document_processor_service::DeployProcessorVersion::new(self.inner.clone())
252    }
253
254    /// Undeploys the processor version.
255    ///
256    /// # Long running operations
257    ///
258    /// This method is used to start, and/or poll a [long-running Operation].
259    /// The [Working with long-running operations] chapter in the [user guide]
260    /// covers these operations in detail.
261    ///
262    /// [long-running operation]: https://google.aip.dev/151
263    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
264    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
265    pub fn undeploy_processor_version(
266        &self,
267    ) -> super::builder::document_processor_service::UndeployProcessorVersion {
268        super::builder::document_processor_service::UndeployProcessorVersion::new(
269            self.inner.clone(),
270        )
271    }
272
273    /// Creates a processor from the
274    /// [ProcessorType][google.cloud.documentai.v1.ProcessorType] provided. The
275    /// processor will be at `ENABLED` state by default after its creation. Note
276    /// that this method requires the `documentai.processors.create` permission on
277    /// the project, which is highly privileged. A user or service account with
278    /// this permission can create new processors that can interact with any gcs
279    /// bucket in your project.
280    ///
281    /// [google.cloud.documentai.v1.ProcessorType]: crate::model::ProcessorType
282    pub fn create_processor(&self) -> super::builder::document_processor_service::CreateProcessor {
283        super::builder::document_processor_service::CreateProcessor::new(self.inner.clone())
284    }
285
286    /// Deletes the processor, unloads all deployed model artifacts if it was
287    /// enabled and then deletes all artifacts associated with this processor.
288    ///
289    /// # Long running operations
290    ///
291    /// This method is used to start, and/or poll a [long-running Operation].
292    /// The [Working with long-running operations] chapter in the [user guide]
293    /// covers these operations in detail.
294    ///
295    /// [long-running operation]: https://google.aip.dev/151
296    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
297    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
298    pub fn delete_processor(&self) -> super::builder::document_processor_service::DeleteProcessor {
299        super::builder::document_processor_service::DeleteProcessor::new(self.inner.clone())
300    }
301
302    /// Enables a processor
303    ///
304    /// # Long running operations
305    ///
306    /// This method is used to start, and/or poll a [long-running Operation].
307    /// The [Working with long-running operations] chapter in the [user guide]
308    /// covers these operations in detail.
309    ///
310    /// [long-running operation]: https://google.aip.dev/151
311    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
312    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
313    pub fn enable_processor(&self) -> super::builder::document_processor_service::EnableProcessor {
314        super::builder::document_processor_service::EnableProcessor::new(self.inner.clone())
315    }
316
317    /// Disables a processor
318    ///
319    /// # Long running operations
320    ///
321    /// This method is used to start, and/or poll a [long-running Operation].
322    /// The [Working with long-running operations] chapter in the [user guide]
323    /// covers these operations in detail.
324    ///
325    /// [long-running operation]: https://google.aip.dev/151
326    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
327    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
328    pub fn disable_processor(
329        &self,
330    ) -> super::builder::document_processor_service::DisableProcessor {
331        super::builder::document_processor_service::DisableProcessor::new(self.inner.clone())
332    }
333
334    /// Set the default (active) version of a
335    /// [Processor][google.cloud.documentai.v1.Processor] that will be used in
336    /// [ProcessDocument][google.cloud.documentai.v1.DocumentProcessorService.ProcessDocument]
337    /// and
338    /// [BatchProcessDocuments][google.cloud.documentai.v1.DocumentProcessorService.BatchProcessDocuments].
339    ///
340    /// [google.cloud.documentai.v1.DocumentProcessorService.BatchProcessDocuments]: crate::client::DocumentProcessorService::batch_process_documents
341    /// [google.cloud.documentai.v1.DocumentProcessorService.ProcessDocument]: crate::client::DocumentProcessorService::process_document
342    /// [google.cloud.documentai.v1.Processor]: crate::model::Processor
343    ///
344    /// # Long running operations
345    ///
346    /// This method is used to start, and/or poll a [long-running Operation].
347    /// The [Working with long-running operations] chapter in the [user guide]
348    /// covers these operations in detail.
349    ///
350    /// [long-running operation]: https://google.aip.dev/151
351    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
352    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
353    pub fn set_default_processor_version(
354        &self,
355    ) -> super::builder::document_processor_service::SetDefaultProcessorVersion {
356        super::builder::document_processor_service::SetDefaultProcessorVersion::new(
357            self.inner.clone(),
358        )
359    }
360
361    /// Send a document for Human Review. The input document should be processed by
362    /// the specified processor.
363    ///
364    /// # Long running operations
365    ///
366    /// This method is used to start, and/or poll a [long-running Operation].
367    /// The [Working with long-running operations] chapter in the [user guide]
368    /// covers these operations in detail.
369    ///
370    /// [long-running operation]: https://google.aip.dev/151
371    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
372    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
373    pub fn review_document(&self) -> super::builder::document_processor_service::ReviewDocument {
374        super::builder::document_processor_service::ReviewDocument::new(self.inner.clone())
375    }
376
377    /// Evaluates a ProcessorVersion against annotated documents, producing an
378    /// Evaluation.
379    ///
380    /// # Long running operations
381    ///
382    /// This method is used to start, and/or poll a [long-running Operation].
383    /// The [Working with long-running operations] chapter in the [user guide]
384    /// covers these operations in detail.
385    ///
386    /// [long-running operation]: https://google.aip.dev/151
387    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
388    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
389    pub fn evaluate_processor_version(
390        &self,
391    ) -> super::builder::document_processor_service::EvaluateProcessorVersion {
392        super::builder::document_processor_service::EvaluateProcessorVersion::new(
393            self.inner.clone(),
394        )
395    }
396
397    /// Retrieves a specific evaluation.
398    pub fn get_evaluation(&self) -> super::builder::document_processor_service::GetEvaluation {
399        super::builder::document_processor_service::GetEvaluation::new(self.inner.clone())
400    }
401
402    /// Retrieves a set of evaluations for a given processor version.
403    pub fn list_evaluations(&self) -> super::builder::document_processor_service::ListEvaluations {
404        super::builder::document_processor_service::ListEvaluations::new(self.inner.clone())
405    }
406
407    /// Lists information about the supported locations for this service.
408    pub fn list_locations(&self) -> super::builder::document_processor_service::ListLocations {
409        super::builder::document_processor_service::ListLocations::new(self.inner.clone())
410    }
411
412    /// Gets information about a location.
413    pub fn get_location(&self) -> super::builder::document_processor_service::GetLocation {
414        super::builder::document_processor_service::GetLocation::new(self.inner.clone())
415    }
416
417    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
418    ///
419    /// [google.longrunning.Operations]: google-cloud-longrunning::client::Operations
420    pub fn list_operations(&self) -> super::builder::document_processor_service::ListOperations {
421        super::builder::document_processor_service::ListOperations::new(self.inner.clone())
422    }
423
424    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
425    ///
426    /// [google.longrunning.Operations]: google-cloud-longrunning::client::Operations
427    pub fn get_operation(&self) -> super::builder::document_processor_service::GetOperation {
428        super::builder::document_processor_service::GetOperation::new(self.inner.clone())
429    }
430
431    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
432    ///
433    /// [google.longrunning.Operations]: google-cloud-longrunning::client::Operations
434    pub fn cancel_operation(&self) -> super::builder::document_processor_service::CancelOperation {
435        super::builder::document_processor_service::CancelOperation::new(self.inner.clone())
436    }
437}