This page shows how to get started with the Cloud Client Libraries for the Document AI Toolbox API. Client libraries make it easier to access Google Cloud APIs from a supported language. Although you can use Google Cloud APIs directly by making raw requests to the server, client libraries provide simplifications that significantly reduce the amount of code you need to write.
Read more about the Cloud Client Libraries and the older Google API Client Libraries in Client libraries explained.
Install the client library
Python
pip install --upgrade google-cloud-documentai-toolbox
For more information, see Setting Up a Python Development Environment.
Set up authentication
To authenticate calls to Google Cloud APIs, client libraries support Application Default Credentials (ADC); the libraries look for credentials in a set of defined locations and use those credentials to authenticate requests to the API. With ADC, you can make credentials available to your application in a variety of environments, such as local development or production, without needing to modify your application code.For production environments, the way you set up ADC depends on the service and context. For more information, see Set up Application Default Credentials.
For a local development environment, you can set up ADC with the credentials that are associated with your Google Account:
-
Install the Google Cloud CLI, then initialize it by running the following command:
gcloud init
-
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
A sign-in screen appears. After you sign in, your credentials are stored in the local credential file used by ADC.
Use the client library
Document AI Toolbox is an SDK for Python that provides utility
functions for managing, manipulating, and extracting information from the document response.
It creates a "wrapped" document object from a processed document response from JSON files in
Cloud Storage, local JSON files, or output directly from the process_document()
method.
It can perform the following actions:
- Combine fragmented
Document
JSON files from Batch Processing into a single "wrapped" document. - Export shards as a unified
Document
. -
Get
Document
output from: - Access text from
Pages
,Lines
,Paragraphs
,FormFields
, andTables
without handlingLayout
information. - Search for a
Pages
containing a target string or matching a regular expression. - Search for
FormFields
by name. - Search for
Entities
by type. - Convert
Tables
to a Pandas Dataframe or CSV. - Insert
Entities
andFormFields
into a BigQuery table. - Split a PDF file based on output from a Splitter/Classifier processor.
- Extract image
Entities
fromDocument
bounding boxes. -
Convert
Documents
to and from commonly used formats:- Cloud Vision API
AnnotateFileResponse
- hOCR
- Third-party document processing formats
- Cloud Vision API
- Create batches of documents for processing from a Cloud Storage folder.
Code Samples
The following code samples demonstrate how to use Document AI Toolbox.
Quickstart
Tables
BigQuery export
PDF split
Image extraction
Vision conversion
hOCR conversion
Third-party conversion
Document batches
Merge Document shards
Additional resources
Python
The following list contains links to more resources related to the client library for Python: