How to specify the default project to use with the BigQuery python client?

44 Views Asked by At

Writing a python cloud functions such as

from google.cloud.bigquery import Client

client = Client(
    project="my_gcloud_project",
    location="my_zone",
    )
sql_statement = "SELECT * FROM `my_dataset.my_table`"
query_job = client.query(sql_statement)
query_job.result()

I get a

ValueError: When default_project is not set, table_id must be a fully-qualified ID in standard SQL format, e.g., "project.dataset_id.table_id"

I understand that changing the query to SELECT * FROM `my_project.my_dataset.my_table` solves the error, but is there a way to tell the BigQuery client what is the default project so we do not have to specify it in every query ?

0

There are 0 best solutions below