PyCharm 2022.3 Help

BigQuery

Prerequisites

Prerequisites for Google service account authentication:

  • Project ID

  • Service account email identifier

  • JSON file with a private key

Prerequisites for access and refresh tokens authentication:

  • Access and refresh tokens

  • Client ID

  • Client secret

If you are missing some prerequisites, consider reading the following tutorial.

This topic presents a general procedure on how you can connect to BigQuery from PyCharm. It is assumed that you already have the necessary prerequisites.

  1. In the Database tool window ( View | Tool Windows | Database), click the Data Source Properties icon The Data Source Properties icon.

  2. On the Data Sources tab in the Data Sources and Drivers dialog, click the Add icon (The Add icon) and select BigQuery.

  3. Check if there is a Download missing driver files link at the bottom of the data source settings area. As you click this link, PyCharm downloads drivers that are required to interact with a database. The IDE does not include bundled drivers in order to have a smaller size of the installation package and to keep driver versions up-to-date for each IDE version.

    You can specify your drivers for the data source if you do not want to download the provided drivers. For more information about creating a database connection with your driver, see Add a user driver to an existing connection.

  4. Specify database connection details. Alternatively, paste the JDBC URL in the URL field.

    To delete a password, right-click the Password field and select Set Empty.

  5. Specify information about the project to which you want to connect.

    • Project ID:: a unique identifier for your project.

    • OAuthType:: an option that specifies how the driver obtains or provides the credentials for OAuth 2.0 authentication. You can select between the following options:

      • Google Service Account: authenticate the connection with a Google service account. In the URL field, add the following options: OAuthServiceAcctEmail (a Google service account email address), OAuthPvtKeyPath (the full path to a private key file for the service account), and OAuthType=0. Consider the following example JDBC URL.

        jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443; ProjectId=ConnectToBigQuery; OAuthType=0; OAuthServiceAcctEmail=my_google_service_account@connect-to-bigquery.iam.gserviceaccount.com; OAuthPvtKeyPath=/Users/jetbrains/DatagripProjects/keyFile.p12;
      • Google User Account: authenticate the connection with a Google user account. You must provide your Google user account credentials to connect to the server.

        jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443; ProjectId=ConnectToBigQuery; OAuthType=1;
      • Pre-Generated Access and Refresh Tokens: authenticate the connection using access or refresh tokens that have already been generated from the Google Authorization Server. In the URL field, add the following options: OAuthAccessToken (an access token), OAuthClientId (a refresh token), OAuthClientSecret (a client secret), and OAuthType=2. If you are using a refresh token, set the OAuthClientId property to to your client ID and set the OAuthClientSecret property to your client secret. For more information about tokens, see Using OAuth 2.0 to Access Google APIs at developers.google.com.

        jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443; OAuthType=2; ProjectId=ConnectToBigQuery; OAuthAccessToken=FI1vf0PSMMu9; OAuthRefreshToken=@3GANwIJk2n3lk3n5g2k45; OAuthClientId=234k5j23l4kf; OAuthClientSecret=lkegjle+2435mn;
      • Application Default Credentials: authenticate the connection using credentials obtained through Application Default Credentials (ADC). For more information about ADC and how to obtain them, see Authenticating as a service account at cloud.google.com.

        jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443; OAuthType=3; ProjectId=ConnectToBigQuery;
  6. To ensure that the connection to the data source is successful, click the Test Connection link.

Last modified: 05 December 2022