Created
April 2, 2019 21:27
-
-
Save vinoaj/0b94da8b66e3937fc0ae76b5d7f7b46a to your computer and use it in GitHub Desktop.
Connect to Google BigQuery using a Google Cloud service account
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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