Files
weirdAAL/libs/gcp/gcp_bigquery.py
carnal0wnage 5f27bcdfe6 gcp
2018-09-26 16:54:49 -04:00

28 lines
775 B
Python

'''
GCP BigQuery functions for WeirdAAL
'''
import google.auth
import googleapiclient.discovery
import os
import sys
from google.oauth2 import service_account
from googleapiclient.errors import HttpError
from google.cloud import bigquery, exceptions
from google.cloud.exceptions import *
def gcp_bigquery_list_datasets(project_id, credentials):
bigquery_client = bigquery.Client(project=credentials.project_id)
datasets = list(bigquery_client.list_datasets())
project = bigquery_client.project
if datasets:
print('Datasets in project {}:'.format(project))
for dataset in datasets: # API request(s)
print('\t{}'.format(dataset.dataset_id))
else:
print('{} project does not contain any datasets.'.format(project))