Google Cloud BigQuery Reservation

1.23.0 · active · verified Fri Apr 17

The `google-cloud-bigquery-reservation` library provides a Python client for the Google Cloud BigQuery Reservation API. This API allows users to manage BigQuery reservations, which are dedicated slots for running queries. The library is currently at version 1.23.0 and is part of the `google-cloud-python` monorepo, receiving frequent updates, often daily, alongside other Google Cloud client libraries.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to instantiate the `ReservationServiceClient` and list existing BigQuery reservations within a specified Google Cloud project and location. Ensure your `GOOGLE_APPLICATION_CREDENTIALS` are set or you are authenticated via `gcloud` and have the necessary IAM permissions (e.g., `bigquery.reservations.list`).

import os
from google.cloud.bigquery_reservation_v1 import ReservationServiceClient

# Instantiate a client. The client will automatically pick up credentials
# from GOOGLE_APPLICATION_CREDENTIALS environment variable or gcloud CLI.
client = ReservationServiceClient()

# Replace with your actual GCP project ID
# You can also set this as an environment variable: export GCP_PROJECT_ID='your-project-id'
project_id = os.environ.get("GCP_PROJECT_ID", "your-project-id")
location = "us-central1" # Example location
parent = f"projects/{project_id}/locations/{location}"

print(f"Attempting to list reservations in {parent}...")

try:
    # List reservations for a given project and location
    reservations = client.list_reservations(parent=parent)
    
    found_reservations = False
    for reservation in reservations:
        print(f"- Reservation found: {reservation.name} (Slots: {reservation.slot_capacity})")
        found_reservations = True
    
    if not found_reservations:
        print("No reservations found. You might need to create one first.")

except Exception as e:
    print(f"An error occurred: {e}")
    print("Please ensure you have correct project ID, location, and permissions.")

view raw JSON →