Extract bigquery dataset and table list with python and output as CSV

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

Extract bigquery dataset and table list with python and output as CSV
Read JSON with Python and output as CSV
Extract the TOP command result with USER and output it as CSV
Sort and output the elements in the list as elements and multiples in Python.
Output to csv file with Python
Reading and writing CSV with Python
Extract database tables with CSV [ODBC connection from R and python]
Read CSV file with Python and convert it to DataFrame as it is
Csv output from Google search with [Python]! 【Easy】
Scraping tabelog with python and outputting to CSV
[Automation] Extract the table in PDF with Python
Example of reading and writing CSV with Python
[Python] How to name table data and output it in csv (to_csv method)
Extract "current date only" and "current date and time" with python datetime.
Extract the table of image files with OneDrive & Python
Procedure to load MNIST with python and output to png
A python script that imports a dated csv file into BigQuery as a time partition table
Read and analyze arff format dataset with python scipy.io
[Python] Read Japanese csv with pandas without garbled characters (and extract columns written in Japanese)
python input and output
Read json file with Python, format it, and output json
[Python-pptx] Output PowerPoint font information to csv with python
Csv tinkering with python
Initialize list with python
Get a list of CloudWatch Metrics and a correspondence table for Unit units with Python boto
[Python] Read the csv file and display the figure with matplotlib
Solving with Ruby and Python AtCoder ABC138 D Adjacency list
Programming with Python and Tkinter
Connect to BigQuery with Python
Encryption and decryption with Python
Read csv with python pandas
Python and hardware-Using RS232C with Python-
Extract Twitter data with CSV
Try Python output with Haxe 3.2
Write to csv with Python
Python list and tuples and commas
Python list comprehensions and generators
python with pyenv and venv
Download csv file with python
Works with Python and R
Extract csv data and calculate
[Python] How to scrape a local html file and output it as CSV using Beautiful Soup
Operate Jupyter with REST API to extract and save Python code
How to import CSV and TSV files into SQLite with Python
[python] Extract text from pdf and read characters aloud with Open-Jtalk
List split and join strings with split and join (Perl / PowerShell / Java / Kotlin / Python)
Solving with Ruby, Python and networkx AtCoder ABC168 D Adjacency list
[python3] Implement debug log output function easily with logging and Click
Output the report as PDF from DB with Python and automatically attach it to an email and send it
[Python] How to create a dictionary type list, add / change / delete elements, and extract with a for statement
Communicate with FX-5204PS with Python and PyUSB
Extract multiple list duplicates in Python
Shining life with Python and OpenCV
Extract the xz file with python
Robot running with Arduino and python
Install Python 2.7.9 and Python 3.4.x with pip.
Difference between list () and [] in Python
Output 2017 Premium Friday list in Python
Grayscale image and save as csv
Neural network with OpenCV 3 and Python 3
AM modulation and demodulation with python