BigQuery Connection API Client Libraries

This page shows how to get started with the Cloud Client Libraries for theBigQuery Connection API. Client libraries make it easier to accessGoogle Cloud APIs from a supported language. Although you can useGoogle Cloud APIs directly by making raw requests to the server, clientlibraries provide simplifications that significantly reduce the amount of codeyou need to write.

Read more about the Cloud Client Librariesand the older Google API Client Libraries inClient libraries explained.

Beta

This library is subject to the "Pre-GA Offerings Terms" in the General Service Terms section of theService Specific Terms. Pre-GA libraries are available "as is" and might have limited support. For more information, see thelaunch stage descriptions.

Install the client library

C#

Install-Package Google.Cloud.BigQuery.Connection.V1 -Pre

For more information, seeSetting Up a C# Development Environment.

Go

go get cloud.google.com/go/bigquery

For more information, seeSetting Up a Go Development Environment.

Java

If you are usingMaven, addthe following to yourpom.xml file. For more information aboutBOMs, seeThe Google Cloud Platform Libraries BOM.

<dependency>  <groupId>com.google.cloud</groupId>  <artifactId>google-cloud-bigqueryconnection</artifactId>  <version>2.5.6</version></dependency>

If you are usingGradle,add the following to your dependencies:

implementation'com.google.cloud:google-cloud-bigqueryconnection:2.20.0'

If you are usingsbt, addthe following to your dependencies:

libraryDependencies+="com.google.cloud"%"google-cloud-bigqueryconnection"%"2.20.0"

If you're using Visual Studio Code or IntelliJ, 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.

Note: Cloud Java client libraries do not currently support Android.

For more information, seeSetting Up a Java Development Environment.

Node.js

npm install @google-cloud/bigquery-connection

For more information, seeSetting Up a Node.js Development Environment.

PHP

composer require google/cloud-bigquery-connection

For more information, seeUsing PHP on Google Cloud.

Python

pip install --upgrade google-cloud-bigquery-connection

For more information, seeSetting Up a Python Development Environment.

Ruby

gem install google-cloud-bigquery-connection

For more information, seeSetting Up a Ruby Development Environment.

Set up authentication

To authenticate calls to Google Cloud APIs, client libraries supportApplication Default Credentials (ADC);the libraries look for credentials in a set of defined locations and use those credentialsto authenticate requests to the API. With ADC, you can makecredentials available to your application in a variety of environments, such as localdevelopment or production, without needing to modify your application code.

For production environments, the way you set up ADC depends on the serviceand context. For more information, seeSet up Application Default Credentials.

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

  1. Install the Google Cloud CLI. After installation,initialize the Google Cloud CLI by running the following command:

    gcloudinit

    If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

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

    gcloudauthapplication-defaultlogin

    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.

    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 demonstrates some basic interactions with the BigQuery Connection API.

Go

// The bigquery_connection_quickstart application demonstrates basic usage of the// BigQuery connection API.packagemainimport("bytes""context""flag""fmt""log""time"connection"cloud.google.com/go/bigquery/connection/apiv1""cloud.google.com/go/bigquery/connection/apiv1/connectionpb""google.golang.org/api/iterator")funcmain(){// Define two command line flags for controlling the behavior of this quickstart.projectID:=flag.String("project_id","","Cloud Project ID, used for session creation.")location:=flag.String("location","US","BigQuery location used for interactions.")// Parse flags and do some minimal validation.flag.Parse()if*projectID==""{log.Fatal("empty --project_id specified, please provide a valid project ID")}if*location==""{log.Fatal("empty --location specified, please provide a valid location")}ctx:=context.Background()connClient,err:=connection.NewClient(ctx)iferr!=nil{log.Fatalf("NewClient: %v",err)}deferconnClient.Close()s,err:=reportConnections(ctx,connClient,*projectID,*location)iferr!=nil{log.Fatalf("printCapacityCommitments: %v",err)}fmt.Println(s)}// reportConnections gathers basic information about existing connections in a given project and location.funcreportConnections(ctxcontext.Context,client*connection.Client,projectID,locationstring)(string,error){varbufbytes.Bufferfmt.Fprintf(&buf,"Current connections defined in project %s in location %s:\n",projectID,location)req:=&connectionpb.ListConnectionsRequest{Parent:fmt.Sprintf("projects/%s/locations/%s",projectID,location),}totalConnections:=0it:=client.ListConnections(ctx,req)for{conn,err:=it.Next()iferr==iterator.Done{break}iferr!=nil{return"",err}fmt.Fprintf(&buf,"\tConnection %s was created %s\n",conn.GetName(),unixMillisToTime(conn.GetCreationTime()).Format(time.RFC822Z))totalConnections++}fmt.Fprintf(&buf,"\n%d connections processed.\n",totalConnections)returnbuf.String(),nil}// unixMillisToTime converts epoch-millisecond representations used by the API into a time.Time representation.funcunixMillisToTime(mint64)time.Time{ifm==0{returntime.Time{}}returntime.Unix(0,m*1e6)}

Java

importcom.google.cloud.bigquery.connection.v1.ListConnectionsRequest;importcom.google.cloud.bigquery.connection.v1.LocationName;importcom.google.cloud.bigqueryconnection.v1.ConnectionServiceClient;importjava.io.IOException;// Sample to demonstrates basic usage of the BigQuery connection API.publicclassQuickstartSample{publicstaticvoidmain(String[]args)throwsIOException{// TODO(developer): Replace these variables before running the sample.StringprojectId="MY_PROJECT_ID";Stringlocation="MY_LOCATION";listConnections(projectId,location);}staticvoidlistConnections(StringprojectId,Stringlocation)throwsIOException{try(ConnectionServiceClientconnectionServiceClient=ConnectionServiceClient.create()){LocationNameparent=LocationName.of(projectId,location);intpageSize=10;ListConnectionsRequestrequest=ListConnectionsRequest.newBuilder().setParent(parent.toString()).setPageSize(pageSize).build();ConnectionServiceClient.ListConnectionsPagedResponseresponse=connectionServiceClient.listConnections(request);// Print the results.System.out.println("List of connections:");response.iterateAll().forEach(connection->System.out.println("Connection Name: "+connection.getName()));}}}

Python

fromgoogle.cloudimportbigquery_connection_v1asbq_connectiondefmain(project_id:str="your-project-id",location:str="US",transport:str="grpc")->None:"""Prints details and summary information about connections for a given admin project and location"""client=bq_connection.ConnectionServiceClient(transport=transport)print(f"List of connections in project{project_id} in location{location}")req=bq_connection.ListConnectionsRequest(parent=client.common_location_path(project_id,location))forconnectioninclient.list_connections(request=req):print(f"\tConnection{connection.friendly_name} ({connection.name})")

Additional resources

C#

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

Go

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

Java

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

Node.js

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

PHP

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

Python

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

Ruby

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

What's next?

For more background, seeWorking with connections.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-12-15 UTC.