This page shows how to get started with the Cloud Client Libraries for the
Data Catalog 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](https://docs.cloud.google.com/apis/docs/client-libraries-explained).

## Install the client library

### C#

```
Install-Package Google.Cloud.DataCatalog.V1
```

For more information, see [Setting Up a C# Development Environment](https://docs.cloud.google.com/dotnet/docs/setup).

### Go

```
go get cloud.google.com/go/datacatalog/apiv1
```

For more information, see [Setting Up a Go Development Environment](https://docs.cloud.google.com/go/docs/setup).

### Java

If you are using Maven, add this to your pom.xml file:

```java
Maven:
<dependency>
    <groupId>com.google.cloud</groupId>
    <artifactId>google-cloud-datacatalog</artifactId>
    <version>DATA_CATALOG_LIBRARY_VERSION</version>
</dependency>
```
If you are using Gradle, add this to your dependencies:

```java
compile group: 'com.google.cloud', name: 'google-cloud-datacatalog', version: 'DATA_CATALOG_LIBRARY_VERSION'
```
See [Data Catalog Java Cloud Client Library reference](https://cloud.google.com/java/docs/reference) for the latest Data Catalog version.

For more information, see [Setting Up a Java Development Environment](https://docs.cloud.google.com/java/docs/setup).

### Node.js

```
npm install @google-cloud/datacatalog
```

For more information, see [Setting Up a Node.js Development Environment](https://docs.cloud.google.com/nodejs/docs/setup).

### PHP

```
composer require google/cloud-data-catalog
```

For more information, see [Using PHP on Google Cloud](https://docs.cloud.google.com/php/docs).

### Python

```
pip install --upgrade google-cloud-datacatalog
```

For more information, see [Setting Up a Python Development Environment](https://docs.cloud.google.com/python/docs/setup).

### Ruby

```
gem install google-cloud-data_catalog
```

For more information, see [Setting Up a Ruby Development Environment](https://docs.cloud.google.com/ruby/docs/setup).

<br />

## Set up authentication

To authenticate calls to Google Cloud APIs, client libraries support [Application Default Credentials (ADC)](https://docs.cloud.google.com/docs/authentication/application-default-credentials); 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](https://docs.cloud.google.com/docs/authentication/provide-credentials-adc).

For a local development environment, you can set up ADC with the credentials
that are associated with your Google Account:

1.
   [Install](https://docs.cloud.google.com/sdk/docs/install) the Google Cloud CLI.

   After installation,
   [initialize](https://docs.cloud.google.com/sdk/docs/initializing) the Google Cloud CLI by running the following command:

   ```bash
   gcloud init
   ```


   If you're using an external identity provider (IdP), you must first
   [sign in to the gcloud CLI with your federated identity](https://docs.cloud.google.com/iam/docs/workforce-log-in-gcloud).
2.

   If you're using a local shell, then create local authentication credentials for your user
   account:

   ```bash
   gcloud auth application-default login
   ```

   You don't need to do this if you're using Cloud Shell.


   If an authentication error is returned, and you are using an external identity provider
   (IdP), confirm that you have
   [signed in to the gcloud CLI with your federated identity](https://docs.cloud.google.com/iam/docs/workforce-log-in-gcloud).


   A sign-in screen appears. After you sign in, your credentials are stored in the
   [local credential file used by ADC](https://docs.cloud.google.com/docs/authentication/application-default-credentials#personal).

## Use the client library


The following example shows how to use the client library.

### Java

    import com.google.cloud.datacatalog.v1.https://docs.cloud.google.com/java/docs/reference/google-cloud-datacatalog/latest/com.google.cloud.datacatalog.v1.DataCatalogClient.html;
    import com.google.cloud.datacatalog.v1.https://docs.cloud.google.com/java/docs/reference/google-cloud-datacatalog/latest/com.google.cloud.datacatalog.v1.Entry.html;
    import com.google.cloud.datacatalog.v1.https://docs.cloud.google.com/java/docs/reference/google-cloud-datacatalog/latest/com.google.cloud.datacatalog.v1.LookupEntryRequest.html;

    public class LookupEntryBigQueryDataset {

      /**
       * Lookup the Data Catalog entry referring to a BigQuery Dataset
       *
       * @param projectId The project ID to which the Dataset belongs, e.g. 'my-project'
       * @param datasetId The dataset ID to which the Catalog Entry refers, e.g. 'my_dataset'
       */
      public static void lookupEntry(String projectId, String datasetId) {
        // String projectId = "my-project"
        // String datasetId = "my_dataset"

        // Get an entry by the resource name from the source Google Cloud Platform service.
        String linkedResource =
            String.format("//bigquery.googleapis.com/projects/%s/datasets/%s", projectId, datasetId);
        https://docs.cloud.google.com/java/docs/reference/google-cloud-datacatalog/latest/com.google.cloud.datacatalog.v1.LookupEntryRequest.html request =
            https://docs.cloud.google.com/java/docs/reference/google-cloud-datacatalog/latest/com.google.cloud.datacatalog.v1.LookupEntryRequest.html.newBuilder().setLinkedResource(linkedResource).build();

        // Alternatively, lookup by the SQL name of the entry would have the same result:
        // String sqlResource = String.format("bigquery.dataset.`%s`.`%s`", projectId, datasetId);
        // LookupEntryRequest request =
        // LookupEntryRequest.newBuilder().setSqlResource(sqlResource).build();

        // Initialize client that will be used to send requests. This client only needs to be created
        // once, and can be reused for multiple requests. After completing all of your requests, call
        // the "close" method on the client to safely clean up any remaining background resources.
        try (https://docs.cloud.google.com/java/docs/reference/google-cloud-datacatalog/latest/com.google.cloud.datacatalog.v1.DataCatalogClient.html dataCatalogClient = https://docs.cloud.google.com/java/docs/reference/google-cloud-datacatalog/latest/com.google.cloud.datacatalog.v1.DataCatalogClient.html.create()) {
          https://docs.cloud.google.com/java/docs/reference/google-cloud-datacatalog/latest/com.google.cloud.datacatalog.v1.Entry.html entry = dataCatalogClient.lookupEntry(request);
          System.out.printf("Entry name: %s\n", entry.https://docs.cloud.google.com/java/docs/reference/google-cloud-datacatalog/latest/com.google.cloud.datacatalog.v1.Entry.html#com_google_cloud_datacatalog_v1_Entry_getName__());
        } catch (Exception e) {
          System.out.print("Error during lookupEntryBigQueryDataset:\n" + e.toString());
        }
      }
    }

### Node.js

    // ---
    // Import required modules.
    // ---
    const {DataCatalogClient} = require('https://docs.cloud.google.com/nodejs/docs/reference/datacatalog/latest/overview.html').v1;
    const datacatalog = new https://docs.cloud.google.com/nodejs/docs/reference/datacatalog/latest/overview.html();

    const lookup = async () => {
      // TODO(developer): Uncomment the following lines before running the sample.
      // const projectId = 'my-project'
      // const datasetId = 'my_dataset'
      const resourceName = `//bigquery.googleapis.com/projects/${projectId}/datasets/${datasetId}`;
      const request = {linkedResource: resourceName};
      const [result] = await datacatalog.lookupEntry(request);
      return result;
    };

    const response = await lookup();
    console.log(response);

### Python

    from google.cloud import https://docs.cloud.google.com/python/docs/reference/datacatalog/latest

    datacatalog = https://docs.cloud.google.com/python/docs/reference/datacatalog/latest.https://docs.cloud.google.com/python/docs/reference/datacatalog/latest/google.cloud.datacatalog_v1.services.data_catalog.DataCatalogClient.html()

    bigquery_project_id = "my_bigquery_project"
    dataset_id = "my_dataset"
    table_id = "my_table"
    pubsub_project_id = "my_pubsub_project"
    topic_id = "my_topic"


    # To facilitate testing, we replace values with alternatives
    # provided by the testing harness.
    bigquery_project_id = override_values.get(
        "bigquery_project_id", bigquery_project_id
    )
    dataset_id = override_values.get("dataset_id", dataset_id)
    table_id = override_values.get("table_id", table_id)
    pubsub_project_id = override_values.get("pubsub_project_id", pubsub_project_id)
    topic_id = override_values.get("topic_id", topic_id)

    # BigQuery Dataset via linked_resource
    resource_name = f"//bigquery.googleapis.com/projects/{bigquery_project_id}/datasets/{dataset_id}"

    entry = datacatalog.https://docs.cloud.google.com/python/docs/reference/datacatalog/latest/google.cloud.datacatalog_v1.services.data_catalog.DataCatalogClient.html#google_cloud_datacatalog_v1_services_data_catalog_DataCatalogClient_lookup_entry(request={"linked_resource": resource_name})
    print(
        f"Retrieved entry {entry.name} for BigQuery Dataset resource {entry.linked_resource}"
    )

    # BigQuery Dataset via sql_resource
    sql_resource = f"bigquery.dataset.`{bigquery_project_id}`.`{dataset_id}`"

    entry = datacatalog.https://docs.cloud.google.com/python/docs/reference/datacatalog/latest/google.cloud.datacatalog_v1.services.data_catalog.DataCatalogClient.html#google_cloud_datacatalog_v1_services_data_catalog_DataCatalogClient_lookup_entry(request={"sql_resource": sql_resource})
    print(
        f"Retrieved entry {entry.name} for BigQuery Dataset resource {entry.linked_resource}"
    )

    # BigQuery Table via linked_resource
    resource_name = (
        f"//bigquery.googleapis.com/projects/{bigquery_project_id}/datasets/{dataset_id}"
        f"/tables/{table_id}"
    )

    entry = datacatalog.https://docs.cloud.google.com/python/docs/reference/datacatalog/latest/google.cloud.datacatalog_v1.services.data_catalog.DataCatalogClient.html#google_cloud_datacatalog_v1_services_data_catalog_DataCatalogClient_lookup_entry(request={"linked_resource": resource_name})
    print(f"Retrieved entry {entry.name} for BigQuery Table {entry.linked_resource}")

    # BigQuery Table via sql_resource
    sql_resource = f"bigquery.table.`{bigquery_project_id}`.`{dataset_id}`.`{table_id}`"

    entry = datacatalog.https://docs.cloud.google.com/python/docs/reference/datacatalog/latest/google.cloud.datacatalog_v1.services.data_catalog.DataCatalogClient.html#google_cloud_datacatalog_v1_services_data_catalog_DataCatalogClient_lookup_entry(request={"sql_resource": sql_resource})
    print(
        f"Retrieved entry {entry.name} for BigQuery Table resource {entry.linked_resource}"
    )

    # Pub/Sub Topic via linked_resource
    resource_name = (
        f"//pubsub.googleapis.com/projects/{pubsub_project_id}/topics/{topic_id}"
    )

    entry = datacatalog.https://docs.cloud.google.com/python/docs/reference/datacatalog/latest/google.cloud.datacatalog_v1.services.data_catalog.DataCatalogClient.html#google_cloud_datacatalog_v1_services_data_catalog_DataCatalogClient_lookup_entry(request={"linked_resource": resource_name})
    print(
        f"Retrieved entry {entry.name} for Pub/Sub Topic resource {entry.linked_resource}"
    )

    # Pub/Sub Topic via sql_resource
    sql_resource = f"pubsub.topic.`{pubsub_project_id}`.`{topic_id}`"

    entry = datacatalog.https://docs.cloud.google.com/python/docs/reference/datacatalog/latest/google.cloud.datacatalog_v1.services.data_catalog.DataCatalogClient.html#google_cloud_datacatalog_v1_services_data_catalog_DataCatalogClient_lookup_entry(request={"sql_resource": sql_resource})
    print(
        f"Retrieved entry {entry.name} for Pub/Sub Topic resource {entry.linked_resource}"
    )

<br />

## Additional resources

### C#

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

- [API reference](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.DataCatalog.V1/latest)
- [Client libraries best practices](https://docs.cloud.google.com/apis/docs/client-libraries-best-practices)
- [Issue tracker](https://github.com/googleapis/google-cloud-dotnet/issues)
- [`google-data-catalog` on Stack Overflow](https://stackoverflow.com/search?q=%5Bgoogle-data-catalog%5D+%5Bc%23%5D)
- [Source code](https://github.com/googleapis/google-cloud-dotnet)

### Go

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

- [API reference](https://docs.cloud.google.com/go/docs/reference/cloud.google.com/go/latest/datacatalog/apiv1)
- [Client libraries best practices](https://docs.cloud.google.com/apis/docs/client-libraries-best-practices)
- [Issue tracker](https://github.com/googleapis/google-cloud-go/issues)
- [`google-data-catalog` on Stack Overflow](https://stackoverflow.com/search?q=%5Bgoogle-data-catalog%5D+%5Bgo%5D)
- [Source code](https://github.com/googleapis/google-cloud-go)

### Java

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

- [API reference](https://cloud.google.com/java/docs/reference/google-cloud-datacatalog/latest/overview)
- [Client libraries best practices](https://docs.cloud.google.com/apis/docs/client-libraries-best-practices)
- [Issue tracker](https://github.com/googleapis/google-cloud-java/issues)
- [`google-data-catalog` on Stack Overflow](https://stackoverflow.com/search?q=%5Bgoogle-data-catalog%5D+%5Bjava%5D)
- [Source code](https://github.com/googleapis/google-cloud-java)

### Node.js

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

- [API reference](https://docs.cloud.google.com/nodejs/docs/reference/datacatalog/latest)
- [Client libraries best practices](https://docs.cloud.google.com/apis/docs/client-libraries-best-practices)
- [Issue tracker](https://github.com/GoogleCloudPlatform/google-cloud-node/issues)
- [`google-data-catalog` on Stack Overflow](https://stackoverflow.com/search?q=%5Bgoogle-data-catalog%5D+%5Bnode.js%5D)
- [Source code](https://github.com/GoogleCloudPlatform/google-cloud-node)

### PHP

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

- [API reference](https://docs.cloud.google.com/php/docs/reference/cloud-data-catalog/latest)
- [Client libraries best practices](https://docs.cloud.google.com/apis/docs/client-libraries-best-practices)
- [Issue tracker](https://github.com/googleapis/google-cloud-php/issues)
- [`google-data-catalog` on Stack Overflow](https://stackoverflow.com/search?q=%5Bgoogle-data-catalog%5D+%5Bphp%5D)
- [Source code](https://github.com/googleapis/google-cloud-php)

### Python

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

- [API reference](https://docs.cloud.google.com/python/docs/reference/datacatalog/latest)
- [Client libraries best practices](https://docs.cloud.google.com/apis/docs/client-libraries-best-practices)
- [Issue tracker](https://github.com/googleapis/google-cloud-python/issues)
- [`google-data-catalog` on Stack Overflow](https://stackoverflow.com/search?q=%5Bgoogle-data-catalog%5D+%5Bpython%5D)
- [Source code](https://github.com/googleapis/google-cloud-python)

### Ruby

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

- [API reference](https://googleapis.dev/ruby/google-cloud-data_catalog/latest/index.html)
- [Client libraries best practices](https://docs.cloud.google.com/apis/docs/client-libraries-best-practices)
- [Issue tracker](https://github.com/googleapis/google-cloud-ruby/issues)
- [`google-data-catalog` on Stack Overflow](https://stackoverflow.com/search?q=%5Bgoogle-data-catalog%5D+%5Bruby%5D)
- [Source code](https://github.com/googleapis/google-cloud-ruby)

<br />