Skip to content

Instantly share code, notes, and snippets.

@vinoaj
Created April 2, 2019 21:27
Show Gist options
  • Save vinoaj/0b94da8b66e3937fc0ae76b5d7f7b46a to your computer and use it in GitHub Desktop.
Save vinoaj/0b94da8b66e3937fc0ae76b5d7f7b46a to your computer and use it in GitHub Desktop.
Connect to Google BigQuery using a Google Cloud service account
import os
from google.cloud import bigquery
# Set this to the path to your credentials file
os.environ[
'GOOGLE_APPLICATION_CREDENTIALS'] = 'drd-cloud-sandbox-e21f6cf4f15b.json'
def main():
# Instantiate a Google BigQuery client
client = bigquery.Client()
# Create a query job
query_job = client.query("""
SELECT 1 AS result""")
# Run the query and retrieve results
results = query_job.result()
for row in results:
print(row.result)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment