python 3.6.1 にて動作。
bq_runnner.py
import argparse
import pandas as pd
def run_query(sql_file):
with open(sql_file, 'r') as f:
query = f.read()
project_id = 'YOUR_PROJECT_ID'
df = pd.read_gbq(query, project_id=project_id, dialect='standard')
return df
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('sql_file')
parser.add_argument('--output_csv', default='output.csv')
args = parser.parse_args()
df = run_query(args.sql_file)
df.to_csv(args.output_csv, index=False)
使い方
$ python bq_runnner.py YOUR_QUERY.sql
csvファイル名はお好みで。
必要ライブラリ
requirements.txt
pandas==0.25.3
pandas-gbq==0.13.0