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/// # tokio_test::block_on(async {
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/// # gax::client_builder::Result::<()>::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 /// # tokio_test::block_on(async {
73 /// # use google_cloud_documentai_v1::client::DocumentProcessorService;
74 /// let client = DocumentProcessorService::builder().build().await?;
75 /// # gax::client_builder::Result::<()>::Ok(()) });
76 /// ```
77 pub fn builder() -> super::builder::document_processor_service::ClientBuilder {
78 gax::client_builder::internal::new_builder(
79 super::builder::document_processor_service::client::Factory,
80 )
81 }
82
83 /// Creates a new client from the provided stub.
84 ///
85 /// The most common case for calling this function is in tests mocking the
86 /// client's behavior.
87 pub fn from_stub<T>(stub: T) -> Self
88 where
89 T: super::stub::DocumentProcessorService + 'static,
90 {
91 Self {
92 inner: std::sync::Arc::new(stub),
93 }
94 }
95
96 pub(crate) async fn new(
97 config: gaxi::options::ClientConfig,
98 ) -> gax::client_builder::Result<Self> {
99 let inner = Self::build_inner(config).await?;
100 Ok(Self { inner })
101 }
102
103 async fn build_inner(
104 conf: gaxi::options::ClientConfig,
105 ) -> gax::client_builder::Result<
106 std::sync::Arc<dyn super::stub::dynamic::DocumentProcessorService>,
107 > {
108 if gaxi::options::tracing_enabled(&conf) {
109 return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
110 }
111 Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
112 }
113
114 async fn build_transport(
115 conf: gaxi::options::ClientConfig,
116 ) -> gax::client_builder::Result<impl super::stub::DocumentProcessorService> {
117 super::transport::DocumentProcessorService::new(conf).await
118 }
119
120 async fn build_with_tracing(
121 conf: gaxi::options::ClientConfig,
122 ) -> gax::client_builder::Result<impl super::stub::DocumentProcessorService> {
123 Self::build_transport(conf)
124 .await
125 .map(super::tracing::DocumentProcessorService::new)
126 }
127
128 /// Processes a single document.
129 pub fn process_document(&self) -> super::builder::document_processor_service::ProcessDocument {
130 super::builder::document_processor_service::ProcessDocument::new(self.inner.clone())
131 }
132
133 /// LRO endpoint to batch process many documents. The output is written
134 /// to Cloud Storage as JSON in the [Document] format.
135 ///
136 /// # Long running operations
137 ///
138 /// This method is used to start, and/or poll a [long-running Operation].
139 /// The [Working with long-running operations] chapter in the [user guide]
140 /// covers these operations in detail.
141 ///
142 /// [long-running operation]: https://google.aip.dev/151
143 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
144 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
145 pub fn batch_process_documents(
146 &self,
147 ) -> super::builder::document_processor_service::BatchProcessDocuments {
148 super::builder::document_processor_service::BatchProcessDocuments::new(self.inner.clone())
149 }
150
151 /// Fetches processor types. Note that we don't use
152 /// [ListProcessorTypes][google.cloud.documentai.v1.DocumentProcessorService.ListProcessorTypes]
153 /// here, because it isn't paginated.
154 ///
155 /// [google.cloud.documentai.v1.DocumentProcessorService.ListProcessorTypes]: crate::client::DocumentProcessorService::list_processor_types
156 pub fn fetch_processor_types(
157 &self,
158 ) -> super::builder::document_processor_service::FetchProcessorTypes {
159 super::builder::document_processor_service::FetchProcessorTypes::new(self.inner.clone())
160 }
161
162 /// Lists the processor types that exist.
163 pub fn list_processor_types(
164 &self,
165 ) -> super::builder::document_processor_service::ListProcessorTypes {
166 super::builder::document_processor_service::ListProcessorTypes::new(self.inner.clone())
167 }
168
169 /// Gets a processor type detail.
170 pub fn get_processor_type(
171 &self,
172 ) -> super::builder::document_processor_service::GetProcessorType {
173 super::builder::document_processor_service::GetProcessorType::new(self.inner.clone())
174 }
175
176 /// Lists all processors which belong to this project.
177 pub fn list_processors(&self) -> super::builder::document_processor_service::ListProcessors {
178 super::builder::document_processor_service::ListProcessors::new(self.inner.clone())
179 }
180
181 /// Gets a processor detail.
182 pub fn get_processor(&self) -> super::builder::document_processor_service::GetProcessor {
183 super::builder::document_processor_service::GetProcessor::new(self.inner.clone())
184 }
185
186 /// Trains a new processor version.
187 /// Operation metadata is returned as
188 /// [TrainProcessorVersionMetadata][google.cloud.documentai.v1.TrainProcessorVersionMetadata].
189 ///
190 /// [google.cloud.documentai.v1.TrainProcessorVersionMetadata]: crate::model::TrainProcessorVersionMetadata
191 ///
192 /// # Long running operations
193 ///
194 /// This method is used to start, and/or poll a [long-running Operation].
195 /// The [Working with long-running operations] chapter in the [user guide]
196 /// covers these operations in detail.
197 ///
198 /// [long-running operation]: https://google.aip.dev/151
199 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
200 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
201 pub fn train_processor_version(
202 &self,
203 ) -> super::builder::document_processor_service::TrainProcessorVersion {
204 super::builder::document_processor_service::TrainProcessorVersion::new(self.inner.clone())
205 }
206
207 /// Gets a processor version detail.
208 pub fn get_processor_version(
209 &self,
210 ) -> super::builder::document_processor_service::GetProcessorVersion {
211 super::builder::document_processor_service::GetProcessorVersion::new(self.inner.clone())
212 }
213
214 /// Lists all versions of a processor.
215 pub fn list_processor_versions(
216 &self,
217 ) -> super::builder::document_processor_service::ListProcessorVersions {
218 super::builder::document_processor_service::ListProcessorVersions::new(self.inner.clone())
219 }
220
221 /// Deletes the processor version, all artifacts under the processor version
222 /// will be deleted.
223 ///
224 /// # Long running operations
225 ///
226 /// This method is used to start, and/or poll a [long-running Operation].
227 /// The [Working with long-running operations] chapter in the [user guide]
228 /// covers these operations in detail.
229 ///
230 /// [long-running operation]: https://google.aip.dev/151
231 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
232 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
233 pub fn delete_processor_version(
234 &self,
235 ) -> super::builder::document_processor_service::DeleteProcessorVersion {
236 super::builder::document_processor_service::DeleteProcessorVersion::new(self.inner.clone())
237 }
238
239 /// Deploys the processor version.
240 ///
241 /// # Long running operations
242 ///
243 /// This method is used to start, and/or poll a [long-running Operation].
244 /// The [Working with long-running operations] chapter in the [user guide]
245 /// covers these operations in detail.
246 ///
247 /// [long-running operation]: https://google.aip.dev/151
248 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
249 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
250 pub fn deploy_processor_version(
251 &self,
252 ) -> super::builder::document_processor_service::DeployProcessorVersion {
253 super::builder::document_processor_service::DeployProcessorVersion::new(self.inner.clone())
254 }
255
256 /// Undeploys the processor version.
257 ///
258 /// # Long running operations
259 ///
260 /// This method is used to start, and/or poll a [long-running Operation].
261 /// The [Working with long-running operations] chapter in the [user guide]
262 /// covers these operations in detail.
263 ///
264 /// [long-running operation]: https://google.aip.dev/151
265 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
266 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
267 pub fn undeploy_processor_version(
268 &self,
269 ) -> super::builder::document_processor_service::UndeployProcessorVersion {
270 super::builder::document_processor_service::UndeployProcessorVersion::new(
271 self.inner.clone(),
272 )
273 }
274
275 /// Creates a processor from the
276 /// [ProcessorType][google.cloud.documentai.v1.ProcessorType] provided. The
277 /// processor will be at `ENABLED` state by default after its creation. Note
278 /// that this method requires the `documentai.processors.create` permission on
279 /// the project, which is highly privileged. A user or service account with
280 /// this permission can create new processors that can interact with any gcs
281 /// bucket in your project.
282 ///
283 /// [google.cloud.documentai.v1.ProcessorType]: crate::model::ProcessorType
284 pub fn create_processor(&self) -> super::builder::document_processor_service::CreateProcessor {
285 super::builder::document_processor_service::CreateProcessor::new(self.inner.clone())
286 }
287
288 /// Deletes the processor, unloads all deployed model artifacts if it was
289 /// enabled and then deletes all artifacts associated with this processor.
290 ///
291 /// # Long running operations
292 ///
293 /// This method is used to start, and/or poll a [long-running Operation].
294 /// The [Working with long-running operations] chapter in the [user guide]
295 /// covers these operations in detail.
296 ///
297 /// [long-running operation]: https://google.aip.dev/151
298 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
299 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
300 pub fn delete_processor(&self) -> super::builder::document_processor_service::DeleteProcessor {
301 super::builder::document_processor_service::DeleteProcessor::new(self.inner.clone())
302 }
303
304 /// Enables a processor
305 ///
306 /// # Long running operations
307 ///
308 /// This method is used to start, and/or poll a [long-running Operation].
309 /// The [Working with long-running operations] chapter in the [user guide]
310 /// covers these operations in detail.
311 ///
312 /// [long-running operation]: https://google.aip.dev/151
313 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
314 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
315 pub fn enable_processor(&self) -> super::builder::document_processor_service::EnableProcessor {
316 super::builder::document_processor_service::EnableProcessor::new(self.inner.clone())
317 }
318
319 /// Disables a processor
320 ///
321 /// # Long running operations
322 ///
323 /// This method is used to start, and/or poll a [long-running Operation].
324 /// The [Working with long-running operations] chapter in the [user guide]
325 /// covers these operations in detail.
326 ///
327 /// [long-running operation]: https://google.aip.dev/151
328 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
329 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
330 pub fn disable_processor(
331 &self,
332 ) -> super::builder::document_processor_service::DisableProcessor {
333 super::builder::document_processor_service::DisableProcessor::new(self.inner.clone())
334 }
335
336 /// Set the default (active) version of a
337 /// [Processor][google.cloud.documentai.v1.Processor] that will be used in
338 /// [ProcessDocument][google.cloud.documentai.v1.DocumentProcessorService.ProcessDocument]
339 /// and
340 /// [BatchProcessDocuments][google.cloud.documentai.v1.DocumentProcessorService.BatchProcessDocuments].
341 ///
342 /// [google.cloud.documentai.v1.DocumentProcessorService.BatchProcessDocuments]: crate::client::DocumentProcessorService::batch_process_documents
343 /// [google.cloud.documentai.v1.DocumentProcessorService.ProcessDocument]: crate::client::DocumentProcessorService::process_document
344 /// [google.cloud.documentai.v1.Processor]: crate::model::Processor
345 ///
346 /// # Long running operations
347 ///
348 /// This method is used to start, and/or poll a [long-running Operation].
349 /// The [Working with long-running operations] chapter in the [user guide]
350 /// covers these operations in detail.
351 ///
352 /// [long-running operation]: https://google.aip.dev/151
353 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
354 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
355 pub fn set_default_processor_version(
356 &self,
357 ) -> super::builder::document_processor_service::SetDefaultProcessorVersion {
358 super::builder::document_processor_service::SetDefaultProcessorVersion::new(
359 self.inner.clone(),
360 )
361 }
362
363 /// Send a document for Human Review. The input document should be processed by
364 /// the specified processor.
365 ///
366 /// # Long running operations
367 ///
368 /// This method is used to start, and/or poll a [long-running Operation].
369 /// The [Working with long-running operations] chapter in the [user guide]
370 /// covers these operations in detail.
371 ///
372 /// [long-running operation]: https://google.aip.dev/151
373 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
374 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
375 pub fn review_document(&self) -> super::builder::document_processor_service::ReviewDocument {
376 super::builder::document_processor_service::ReviewDocument::new(self.inner.clone())
377 }
378
379 /// Evaluates a ProcessorVersion against annotated documents, producing an
380 /// Evaluation.
381 ///
382 /// # Long running operations
383 ///
384 /// This method is used to start, and/or poll a [long-running Operation].
385 /// The [Working with long-running operations] chapter in the [user guide]
386 /// covers these operations in detail.
387 ///
388 /// [long-running operation]: https://google.aip.dev/151
389 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
390 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
391 pub fn evaluate_processor_version(
392 &self,
393 ) -> super::builder::document_processor_service::EvaluateProcessorVersion {
394 super::builder::document_processor_service::EvaluateProcessorVersion::new(
395 self.inner.clone(),
396 )
397 }
398
399 /// Retrieves a specific evaluation.
400 pub fn get_evaluation(&self) -> super::builder::document_processor_service::GetEvaluation {
401 super::builder::document_processor_service::GetEvaluation::new(self.inner.clone())
402 }
403
404 /// Retrieves a set of evaluations for a given processor version.
405 pub fn list_evaluations(&self) -> super::builder::document_processor_service::ListEvaluations {
406 super::builder::document_processor_service::ListEvaluations::new(self.inner.clone())
407 }
408
409 /// Lists information about the supported locations for this service.
410 pub fn list_locations(&self) -> super::builder::document_processor_service::ListLocations {
411 super::builder::document_processor_service::ListLocations::new(self.inner.clone())
412 }
413
414 /// Gets information about a location.
415 pub fn get_location(&self) -> super::builder::document_processor_service::GetLocation {
416 super::builder::document_processor_service::GetLocation::new(self.inner.clone())
417 }
418
419 /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
420 ///
421 /// [google.longrunning.Operations]: longrunning::client::Operations
422 pub fn list_operations(&self) -> super::builder::document_processor_service::ListOperations {
423 super::builder::document_processor_service::ListOperations::new(self.inner.clone())
424 }
425
426 /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
427 ///
428 /// [google.longrunning.Operations]: longrunning::client::Operations
429 pub fn get_operation(&self) -> super::builder::document_processor_service::GetOperation {
430 super::builder::document_processor_service::GetOperation::new(self.inner.clone())
431 }
432
433 /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
434 ///
435 /// [google.longrunning.Operations]: longrunning::client::Operations
436 pub fn cancel_operation(&self) -> super::builder::document_processor_service::CancelOperation {
437 super::builder::document_processor_service::CancelOperation::new(self.inner.clone())
438 }
439}