> ## Documentation Index
> Fetch the complete documentation index at: https://docs.domino.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Connect to BigQuery

Domino can connect to and query any common database, including Google BigQuery. The easiest way to connect to a [Google BigQuery](https://cloud.google.com/bigquery/) instance from Domino is to create a Domino Data Source as described below.

You must have network connectivity between BigQuery and your Domino deployment.

## Create a BigQuery Data Source

1. From the navigation pane, click **Data > Data Sources**.

2. Click **Create a Data Source**.

3. In the New Data Source window, from **Select Data Store**, select **Google BigQuery**.

4. Optional: Enter the unique identifier for your project in **GCP Project ID**.

5. Enter the **Data Source Name**.

6. Optional: Enter a **Description** to explain the purpose of the Data Source to others.

7. Click **Next**.

8. Copy your **Private Key (JSON format)**. See [creating a service account](https://cloud.google.com/docs/authentication/getting-started#creating_a_service_account) for instructions about creating a service account and downloading the JSON credentials file. You must copy the entire content of the file. The Domino secret store backed by HashiCorp Vault securely stores the credentials.

9. Click **Test Credentials**.

10. When your Data Source authenticates, click **Next**.

11. Enter the users and organizations who can view and use the Data Source in projects.

12. Click **Finish Setup**.

    <img src="https://mintcdn.com/dominodatalab-e871cec4/O7LjTllMke2wnkZN/images/5.2/bigquery-setup.png?fit=max&auto=format&n=O7LjTllMke2wnkZN&q=85&s=9d0991ce53e281c5cfdd140b21c4b3c3" alt="The BigQuery setup" width="3232" height="2668" data-path="images/5.2/bigquery-setup.png" />

## Alternate way to connect to a Google BigQuery Data Source

You can use the [BigQuery API](https://cloud.google.com/bigquery/docs/reference/libraries-overview) to query any Dataset and table to which you have access, whether it’s public or private, by authenticating with your Google Cloud private key.

<Warning>
  This section describes an alternate method to connect to the Google BigQuery Data Source. Domino does not officially support this method.
</Warning>

1. Go to Google’s Service Accounts page. Select a previous project or create a new project.

   <img src="https://mintcdn.com/dominodatalab-e871cec4/Iw2Ru7Jv9XAqgMHp/images/4.x/mceclip2.png?fit=max&auto=format&n=Iw2Ru7Jv9XAqgMHp&q=85&s=e99893736e51e261d79038efa21a8ba4" alt="Select a project" width="866" height="390" data-path="images/4.x/mceclip2.png" />

   If you selected **Create**, the New Project page opens:

   <img src="https://mintcdn.com/dominodatalab-e871cec4/Iw2Ru7Jv9XAqgMHp/images/4.x/mceclip4.png?fit=max&auto=format&n=Iw2Ru7Jv9XAqgMHp&q=85&s=a1505fa1891b4e1d92b255e513c30784" alt="Create a new project" width="938" height="340" data-path="images/4.x/mceclip4.png" />

2. **Create a Service account** for your project.

   <img src="https://mintcdn.com/dominodatalab-e871cec4/Iw2Ru7Jv9XAqgMHp/images/4.x/mceclip5.png?fit=max&auto=format&n=Iw2Ru7Jv9XAqgMHp&q=85&s=131eea4251041150ecdd545d279858ae" alt="Create a service account" width="870" height="438" data-path="images/4.x/mceclip5.png" />

3. Define the access that the Service account must have to BigQuery. See [Google’s Access Control documentation](https://cloud.google.com/bigquery/docs/access-control) for more information.

   <img src="https://mintcdn.com/dominodatalab-e871cec4/Iw2Ru7Jv9XAqgMHp/images/4.x/mceclip6.png?fit=max&auto=format&n=Iw2Ru7Jv9XAqgMHp&q=85&s=0b9925053c132d25fef6c6e297532aaa" alt="Define the access" width="1812" height="1036" data-path="images/4.x/mceclip6.png" />

4. Confirm that your Service account has been created.

   <img src="https://mintcdn.com/dominodatalab-e871cec4/Iw2Ru7Jv9XAqgMHp/images/4.x/mceclip7.png?fit=max&auto=format&n=Iw2Ru7Jv9XAqgMHp&q=85&s=fbcf3902053fb985a8f255427c4f45c7" alt="New service account has been created" width="1019" height="329" data-path="images/4.x/mceclip7.png" />

5. On the Service Accounts page, create a new key.

   <img src="https://mintcdn.com/dominodatalab-e871cec4/Iw2Ru7Jv9XAqgMHp/images/4.x/mceclip8.png?fit=max&auto=format&n=Iw2Ru7Jv9XAqgMHp&q=85&s=e32bf551b81652bec3e40987b089d851" alt="Create a new key" width="1998" height="306" data-path="images/4.x/mceclip8.png" />

6. Download the JSON key and keep it in a safe place. You will use this key later to programmatically authenticate to Google.

   <img src="https://mintcdn.com/dominodatalab-e871cec4/Iw2Ru7Jv9XAqgMHp/images/4.x/mceclip10.png?fit=max&auto=format&n=Iw2Ru7Jv9XAqgMHp&q=85&s=164cfc500ac75e75033f996435ddd542" alt="Obtain the JSON key" width="1017" height="358" data-path="images/4.x/mceclip10.png" />

7. To enable the BigQuery API, click the **Google APIs** logo.

   <img src="https://mintcdn.com/dominodatalab-e871cec4/Iw2Ru7Jv9XAqgMHp/images/4.x/mceclip11.png?fit=max&auto=format&n=Iw2Ru7Jv9XAqgMHp&q=85&s=6093fc38217e0b25dc04425b9ef020c0" alt="Click the Google APIs logo" width="690" height="319" data-path="images/4.x/mceclip11.png" />

8. In the Library page, select the **Big Query API**.

   <img src="https://mintcdn.com/dominodatalab-e871cec4/Iw2Ru7Jv9XAqgMHp/images/4.x/mceclip13.png?fit=max&auto=format&n=Iw2Ru7Jv9XAqgMHp&q=85&s=20e27e96670a1a8f83078df98543d185" alt="Select BigQuery API" width="399" height="155" data-path="images/4.x/mceclip13.png" />

9. If it is not enabled, click **Enable**.

   <img src="https://mintcdn.com/dominodatalab-e871cec4/Iw2Ru7Jv9XAqgMHp/images/4.x/mceclip14.png?fit=max&auto=format&n=Iw2Ru7Jv9XAqgMHp&q=85&s=b00025c1b621d12c15e978ff3066dedc" alt="Enable the BigQuery API" width="573" height="107" data-path="images/4.x/mceclip14.png" />

### Activate your credentials from Domino

Google Cloud uses the [Google Cloud SDK](https://cloud.google.com/sdk/) to activate your credentials. This is already installed in the Domino Default environment.

Execute the following bash command:

```shell theme={null}
/home/ubuntu/google-cloud-sdk/bin/gcloud auth activate-service-account <service account name> --key-file <key file path>
```

For example:

```shell theme={null}
/home/ubuntu/google-cloud-sdk/bin/gcloud auth activate-service-account big-query-example@example-big-query-170823.iam.gserviceaccount.com --key-file key.json
```

You can use a custom Domino compute environment and enter this command in Domino pre-setup script to activate the credentials before each run. Otherwise, you can execute them in workspace sessions. See [how to store your credentials securely](/cloud/platform-capabilities/core-concepts/projects/configure-projects/store-project-credentials).

### Authenticate and query using Python

You need the `gcloud` and `oauth2client==1.4.12` Python packages. Use the following package to install them in your custom Domino compute environment or in your workspace session.

```shell theme={null}
pip install --user gcloud oauth2client==1.4.12
```

Use the following code to authenticate your Google credentials and query a public BigQuery table:

```python theme={null}
from oauth2client.client import GoogleCredentials
from googleapiclient.discovery import build

# Grab the application's default credentials from the environment.
credentials = GoogleCredentials.get_application_default()

# Construct the service object for interacting with the BigQuery API.
bigquery_service = build('bigquery', 'v2', credentials=credentials)

query_request = bigquery_service.jobs()
query_data = {
    'query': (
    'SELECT TOP(corpus, 10) as title, '
    'COUNT(*) as unique_words '
    'FROM [publicdata:samples.shakespeare];')
}

query_response = query_request.query(
    projectId='example-big-query-170823', # Substitute your ProjectId
    body=query_data).execute()

print('Query Results:')
for row in query_response['rows']:
    print(' '.join(field['v'] for field in row['f']))
```

## Next steps

* After connecting to your Data Source, learn how to [Use Data Sources](/cloud/platform-capabilities/core-concepts/data/data-source-connectors/use-data-sources).

* [Share this Data Source](/cloud/platform-capabilities/core-concepts/data/sharing-and-security/share-data-sources) with your collaborators.
