BigQuery Reservation API Client Libraries Stay organized with collections Save and categorize content based on your preferences.
This page shows how to get started with the Cloud Client Libraries for theBigQuery Reservation 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.
Install the client library
C#
Install-Package Google.Cloud.BigQuery.Reservation.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.
<dependencyManagement><dependencies><dependency><groupId>com.google.cloud</groupId><artifactId>libraries-bom</artifactId><version>26.72.0</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement><dependencies><dependency><groupId>com.google.cloud</groupId><artifactId>google-cloud-bigqueryreservation</artifactId></dependency></dependencies>If you are usingGradle,add the following to your dependencies:
implementation'com.google.cloud:google-cloud-bigqueryreservation:2.81.0'If you are usingsbt, addthe following to your dependencies:
libraryDependencies+="com.google.cloud"%"google-cloud-bigqueryreservation"%"2.81.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-reservation
For more information, seeSetting Up a Node.js Development Environment.
PHP
composer require google/cloud-bigquery-reservation
For more information, seeUsing PHP on Google Cloud.
Python
pip install --upgrade google-cloud-bigquery-reservation
For more information, seeSetting Up a Python Development Environment.
Ruby
gem install google-cloud-bigquery-reservation
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:
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.
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 Reservation API by enumerating resources, namely reservations and capacitycommitments.
Go
// The bigquery_reservation_quickstart application demonstrates usage of the// BigQuery reservation API by enumerating some of the resources that can be// associated with a cloud project.packagemainimport("bytes""context""flag""fmt""log"reservation"cloud.google.com/go/bigquery/reservation/apiv1""google.golang.org/api/iterator"reservationpb"google.golang.org/genproto/googleapis/cloud/bigquery/reservation/v1")funcmain(){// Define two command line flags for controlling the behavior of this quickstart.var(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()bqResClient,err:=reservation.NewClient(ctx)iferr!=nil{log.Fatalf("NewClient: %v",err)}deferbqResClient.Close()s,err:=reportCapacityCommitments(ctx,bqResClient,*projectID,*location)iferr!=nil{log.Fatalf("printCapacityCommitments: %v",err)}fmt.Println(s)s,err=reportReservations(ctx,bqResClient,*projectID,*location)iferr!=nil{log.Fatalf("printReservations: %v",err)}fmt.Println(s)}// printCapacityCommitments iterates through the capacity commitments and returns a byte buffer with details.funcreportCapacityCommitments(ctxcontext.Context,client*reservation.Client,projectID,locationstring)(string,error){varbufbytes.Bufferfmt.Fprintf(&buf,"Capacity commitments in project %s in location %s:\n",projectID,location)req:=&reservationpb.ListCapacityCommitmentsRequest{Parent:fmt.Sprintf("projects/%s/locations/%s",projectID,location),}totalCommitments:=0it:=client.ListCapacityCommitments(ctx,req)for{commitment,err:=it.Next()iferr==iterator.Done{break}iferr!=nil{return"",err}fmt.Fprintf(&buf,"\tCommitment %s in state %s\n",commitment.GetName(),commitment.GetState().String())totalCommitments++}fmt.Fprintf(&buf,"\n%d commitments processed.\n",totalCommitments)returnbuf.String(),nil}// printReservations iterates through reservations defined in an admin project.funcreportReservations(ctxcontext.Context,client*reservation.Client,projectID,locationstring)(string,error){varbufbytes.Bufferfmt.Fprintf(&buf,"Reservations in project %s in location %s:\n",projectID,location)req:=&reservationpb.ListReservationsRequest{Parent:fmt.Sprintf("projects/%s/locations/%s",projectID,location),}totalReservations:=0it:=client.ListReservations(ctx,req)for{reservation,err:=it.Next()iferr==iterator.Done{break}iferr!=nil{return"",err}fmt.Fprintf(&buf,"\tReservation %s has %d slot capacity.\n",reservation.GetName(),reservation.GetSlotCapacity())totalReservations++}fmt.Fprintf(&buf,"\n%d reservations processed.\n",totalReservations)returnbuf.String(),nil}Java
importcom.google.cloud.bigquery.reservation.v1.ReservationServiceClient;importjava.io.IOException;publicclassQuickstartSample{publicstaticvoidmain(String...args)throwsException{// TODO(developer): Replace these variables before running the sample.StringprojectId="YOUR_PROJECT_ID";Stringlocation="LOCATION";quickStartSample(projectId,location);}publicstaticvoidquickStartSample(StringprojectId,Stringlocation)throwsIOException{try(ReservationServiceClientclient=ReservationServiceClient.create()){// list reservations in the projectStringparent=String.format("projects/%s/locations/%s",projectId,location);client.listReservations(parent).iterateAll().forEach(res->System.out.println("Reservation resource name: "+res.getName()));// list capacity commitments in the projectclient.listCapacityCommitments(parent).iterateAll().forEach(commitment->System.out.println("Capacity commitment resource name: "+commitment.getName()));}}}Node.js
// Imports the Google Cloud client libraryconst{ReservationServiceClient,}=require('@google-cloud/bigquery-reservation');// Creates a clientconstclient=newReservationServiceClient();// project = 'my-project' // Project to list reservations for.// location = 'US' // BigQuery location.asyncfunctionlistReservations(){const[reservations]=awaitclient.listReservations({parent:`projects/${project}/locations/${location}`,});console.info(`found${reservations.length} reservations`);console.info(reservations);}asyncfunctionlistCapacityCommitments(){const[commitments]=awaitclient.listCapacityCommitments({parent:`projects/${project}/locations/${location}`,});console.info(`found${commitments.length} commitments`);console.info(commitments);}listReservations();listCapacityCommitments();Python
importargparsefromgoogle.cloudimportbigquery_reservation_v1defmain(project_id:str="your-project-id",location:str="US",transport:str="grpc")->None:# Constructs the client for interacting with the service.client=bigquery_reservation_v1.ReservationServiceClient(transport=transport)report_reservations(client,project_id,location)defreport_reservations(client:bigquery_reservation_v1.ReservationServiceClient,project_id:str,location:str,)->None:"""Prints details and summary information about reservations defined within a given admin project and location. """print("Reservations in project{} in location{}".format(project_id,location))req=bigquery_reservation_v1.ListReservationsRequest(parent=client.common_location_path(project_id,location))total_reservations=0forreservationinclient.list_reservations(request=req):print(f"\tReservation{reservation.name} "f"has{reservation.slot_capacity} slot capacity.")total_reservations=total_reservations+1print(f"\n{total_reservations} reservations processed.")if__name__=="__main__":parser=argparse.ArgumentParser()parser.add_argument("--project_id",type=str)parser.add_argument("--location",default="US",type=str)args=parser.parse_args()main(project_id=args.project_id,location=args.location)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 and conceptual information about reservations, seeIntroduction to Reservations.
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.