Outputs a CSV with the dataset name in column A and the table name in column B. The target project will be the project displayed when you type the following in the terminal.
gcloud config list
code
import datetime
import pandas as pd
from google.cloud import bigquery
bigquery_data = pd.DataFrame(
index = [] ,
columns = ['dataset','table']
)
client = bigquery.Client()
datasets = list(client.list_datasets())
project = client.project
for dataset in datasets:
dataset_id = '{}.{}'.format(project , dataset.dataset_id)
dataset = client.get_dataset(dataset_id)
tables = list(client.list_tables(dataset))
for table in tables:
dataset_table = pd.Series({'dataset' : dataset.dataset_id ,'table' : table.table_id})
bigquery_data = bigquery_data.append(dataset_table , ignore_index = True)
make_day = datetime.datetime.today().strftime('%Y-%m-%d')
bigquery_data.to_csv('bigquery_data_{}.csv'.format(make_day) , index = False)
Recommended Posts