This week, I wanted to connect with BigQuery using Python. BigQuery is a service from Google, which helps to store and process large volumes of data quickly. We are using it to store Google billing data and wanted to generate some reports by executing different SQL queries.
from google.cloud import bigquery from google.oauth2 import service_account auth_json = Your JSON for authentication credentials = service_account.Credentials.from_service_account_info(auth_json) client = bigquery.Client(project="project name", credentials=credentials) query_job = client.query("""your query inside""") results = query_job.result() # Waits for job to complete. for row in results: print("{}".format(row.id, any other fields))
The above code shows, how we can connect and query the bigquery. It returns an iteratable, which can allow looping over the rows and access each column as shown in the code.
I hope it would help you in your big projects.