BigQuery
Connecting to GCP BigQuery from a DevZero workspace.
If you're more of a visual learner, check out the video tutorial!
Architecture Diagram
DevZero Workspace
Step 1: Generating Google Authentication Credentials for BigQuery
- Go to IAM & Admin > Service Accounts.
- Click on Create Service Account, enter the Service Account Name and click on Create and Continue.
- Click on Select a role, select BigQuery Admin, and click on Continue.
- Select the new service account and go to Keys.
- Click on Add Key > Create a new key and click on Create.
Step 2: Connecting to BigQuery through Python API
- Connect to your DevZero workspace.
- Store the Google Authentication Credentials on the workspace.
- Install Python and PIP:
sudo apt update
sudo apt install python3 python3-dev python3-venv
sudo apt-get install wget
wget https://bootstrap.pypa.io/get-pip.py
- Install BigQuery API:
pip install google-cloud-bigquery
- Set the GOOGLE_APPLICATION_CREDENTIALS environment variable.
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/the/key.json
- Write a Python scipt to test the BigQuery API Connection:
from google.cloud import bigquery
client = bigquery.Client()
if client:
print("Connected")
else:
print("Connection failed")
- Run the Python Script:
python3 <file-name>.py
If the connection is successful, you should see "Connected" printed in the terminal output.