Document AI Warehouse client libraries

This page shows how to get started with the Cloud Client Libraries for the Document AI Warehouse 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


See Setting up a C++ development environment for details about this client library's requirements and install dependencies.


If you are using Maven, add the following to your pom.xml file. For more information about BOMs, see The Google Cloud Platform Libraries BOM.



If you are using Gradle, add the following to your dependencies:

implementation ''

If you are using sbt, add the following to your dependencies:

libraryDependencies += "" % "google-cloud-contentwarehouse" % "0.32.0"

If you're using Visual Studio Code, IntelliJ, or Eclipse, you can add client libraries to your project using the following IDE plugins:

The plugins provide additional functionality, such as key management for service accounts. Refer to each plugin's documentation for details.

For more information, see Setting Up a Java Development Environment.


npm install @google-cloud/contentwarehouse

For more information, see Setting Up a Node.js Development Environment.


pip install --upgrade google-cloud-contentwarehouse

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:

  1. Install and initialize the gcloud CLI.

    When you initialize the gcloud CLI, be sure to specify a Google Cloud project in which you have permission to access the resources your application needs.

  2. Create your credential file:

    gcloud auth application-default login

    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

The following example shows how to use the client library.


#include "google/cloud/contentwarehouse/v1/document_client.h"
#include "google/cloud/location.h"
#include <iostream>

int main(int argc, char* argv[]) try {
  if (argc != 3) {
    std::cerr << "Usage: " << argv[0] << " project-number location-id\n";
    return 1;

  auto const location = google::cloud::Location(argv[1], argv[2]);

  namespace contentwarehouse = ::google::cloud::contentwarehouse_v1;
  auto client = contentwarehouse::DocumentServiceClient(

  for (auto md : client.SearchDocuments(location.FullName())) {
    if (!md) throw std::move(md).status();
    std::cout << md->DebugString() << "\n";

  return 0;
} catch (google::cloud::Status const& status) {
  std::cerr << "google::cloud::Status thrown: " << status << "\n";
  return 1;


public class QuickStart {

  public static void main(String[] args)
      throws IOException, InterruptedException, ExecutionException, TimeoutException {
    // TODO(developer): Replace these variables before running the sample.
    String projectId = "your-project-id";
    String location = "your-region"; // Format is "us" or "eu".
    String userId = "your-user-id"; // Format is user:<user-id>
    quickStart(projectId, location, userId);

  public static void quickStart(String projectId, String location, String userId)
      throws IOException, InterruptedException, ExecutionException, TimeoutException {
    String projectNumber = getProjectNumber(projectId);

    String endpoint = "";
    if (!"us".equals(location)) {
      endpoint = String.format("%s-%s", location, endpoint);
    DocumentSchemaServiceSettings documentSchemaServiceSettings = 

    // Create a Schema Service client
    try (DocumentSchemaServiceClient documentSchemaServiceClient =
        DocumentSchemaServiceClient.create(documentSchemaServiceSettings)) {
      /*  The full resource name of the location, e.g.:
      projects/{project_number}/locations/{location} */
      String parent = LocationName.format(projectNumber, location);

      /* Create Document Schema with Text Type Property Definition
       * More detail on managing Document Schemas: 
       * */
      DocumentSchema documentSchema = DocumentSchema.newBuilder()
          .setDisplayName("My Test Schema")
          .setDescription("My Test Schema's Description")
              .setDisplayName("Searchable text")

      // Define Document Schema request
      CreateDocumentSchemaRequest createDocumentSchemaRequest =

      // Create Document Schema
      DocumentSchema documentSchemaResponse =

      // Create Document Service Client Settings
      DocumentServiceSettings documentServiceSettings = 

      // Create Document Service Client and Document with relevant properties 
      try (DocumentServiceClient documentServiceClient =
          DocumentServiceClient.create(documentServiceSettings)) {
        TextArray textArray = TextArray.newBuilder().addValues("Test").build();
        Document document = Document.newBuilder()
              .setDisplayName("My Test Document")
              .setPlainText("This is a sample of a document's text.")

        // Define Request Metadata for enforcing access control
        RequestMetadata requestMetadata = RequestMetadata.newBuilder()

        // Define Create Document Request 
        CreateDocumentRequest createDocumentRequest = CreateDocumentRequest.newBuilder()

        // Create Document
        CreateDocumentResponse createDocumentResponse =


  private static String getProjectNumber(String projectId) throws IOException { 
    try (ProjectsClient projectsClient = ProjectsClient.create()) { 
      ProjectName projectName = ProjectName.of(projectId); 
      Project project = projectsClient.getProject(projectName);
      String projectNumber = project.getName(); // Format returned is projects/xxxxxx
      return projectNumber.substring(projectNumber.lastIndexOf("/") + 1);


 * This snippet has been automatically generated and should be regarded as a code template only.
 * It will require modifications to work.
 * It may require correct/in-range values for request initialization.
 * TODO(developer): Uncomment these variables before running the sample.
 *  Required. The parent, which owns this collection of document.
 *  Format: projects/{project_number}/locations/{location}.
// const parent = 'abc123'
 *  The maximum number of rule sets to return. The service may return
 *  fewer than this value.
 *  If unspecified, at most 50 rule sets will be returned.
 *  The maximum value is 1000; values above 1000 will be coerced to 1000.
// const pageSize = 1234
 *  A page token, received from a previous `ListRuleSets` call.
 *  Provide this to retrieve the subsequent page.
 *  When paginating, all other parameters provided to `ListRuleSets`
 *  must match the call that provided the page token.
// const pageToken = 'abc123'

// Imports the Contentwarehouse library
const {RuleSetServiceClient} = require('@google-cloud/contentwarehouse').v1;

// Instantiates a client
const contentwarehouseClient = new RuleSetServiceClient();

async function callListRuleSets() {
  // Construct request
  const request = {

  // Run request
  const iterable = await contentwarehouseClient.listRuleSetsAsync(request);
  for await (const response of iterable) {



from import contentwarehouse

# TODO(developer): Uncomment these variables before running the sample.
# project_number = 'YOUR_PROJECT_NUMBER'
# location = 'YOUR_PROJECT_LOCATION' # Format is 'us' or 'eu'
# user_id = "" # Format is ""

def quickstart(project_number: str, location: str, user_id: str) -> None:
    # Create a Schema Service client
    document_schema_client = contentwarehouse.DocumentSchemaServiceClient()

    # The full resource name of the location, e.g.:
    # projects/{project_number}/locations/{location}
    parent = document_schema_client.common_location_path(
        project=project_number, location=location

    # Define Schema Property of Text Type
    property_definition = contentwarehouse.PropertyDefinition(
        name="stock_symbol",  # Must be unique within a document schema (case insensitive)
        display_name="Searchable text",

    # Define Document Schema Request
    create_document_schema_request = contentwarehouse.CreateDocumentSchemaRequest(
            display_name="My Test Schema",

    # Create a Document schema
    document_schema = document_schema_client.create_document_schema(

    # Create a Document Service client
    document_client = contentwarehouse.DocumentServiceClient()

    # The full resource name of the location, e.g.:
    # projects/{project_number}/locations/{location}
    parent = document_client.common_location_path(
        project=project_number, location=location

    # Define Document Property Value
    document_property = contentwarehouse.Property(

    # Define Document
    document = contentwarehouse.Document(
        display_name="My Test Document",,
        plain_text="This is a sample of a document's text.",

    # Define Request
    create_document_request = contentwarehouse.CreateDocumentRequest(

    # Create a Document for the given schema
    response = document_client.create_document(request=create_document_request)

    # Read the output
    print(f"Rule Engine Output: {response.rule_engine_output}")
    print(f"Document Created: {response.document}")

Additional resources


The following list contains links to more resources related to the client library for C++:


The following list contains links to more resources related to the client library for Java:


The following list contains links to more resources related to the client library for Node.js:


The following list contains links to more resources related to the client library for Python: