Works with 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)
How to use
$ python bq_runnner.py YOUR_QUERY.sql
You can name the csv file as you like.
Required library
requirements.txt
pandas==0.25.3
pandas-gbq==0.13.0
Recommended Posts