Skip to content

Instantly share code, notes, and snippets.

@shibacow
Created September 9, 2024 09:15
Show Gist options
  • Save shibacow/537006edd2a245fac4ee710feabb80a9 to your computer and use it in GitHub Desktop.
Save shibacow/537006edd2a245fac4ee710feabb80a9 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
from google.cloud import bigquery
from google.oauth2 import service_account
key_path = 'xxxxxxxxxxxxxxxxxxx.json'
credentials = service_account.Credentials.from_service_account_file(
key_path,
scopes=[
'https://www.googleapis.com/auth/bigquery',
'https://www.googleapis.com/auth/cloud-platform',
'https://www.googleapis.com/auth/drive.readonly'
],
)
query='''
SELECT count(1) as cnt FROM `dataset.external_table_from_google_sheet`
'''
client = bigquery.Client(
credentials=credentials,
project=credentials.project_id,
)
query_job = client.query(query)
rows = query_job.result()
for row in rows:
print(row.cnt)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment