You can connect to BigQuery from an environment which is outside GCP.
You need to setup two things:
Bigquery client library of your choice of language. Looking at the above code, it looks like you want to use python. You can install Bigquery python client lib by running
pip install --upgrade google-cloud-bigquery
Authentication to BigQuery -
a. Get your GCP creds by running following command:
gcloud auth application-default login
This should create a credential JSON file at location "~/.config/gcloud/"
b. You can set an environment variable pointing to the JSON creds file on the command line
export GOOGLE_APPLICATION_CREDENTIALS="~/.config/gcloud/application_default_credentials.json"
Or, you can set the above environment variable in your python program by adding the following lines:
import os
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] =
'~/.config/gcloud/application_default_credentials.json'
Hope this helps.