Skip to content

Instantly share code, notes, and snippets.

@Shuaib-8
Created March 25, 2020 10:13
Show Gist options
  • Save Shuaib-8/ef1ab3e6d68ee241ec6e7a8ab552ce4b to your computer and use it in GitHub Desktop.
Save Shuaib-8/ef1ab3e6d68ee241ec6e7a8ab552ce4b to your computer and use it in GitHub Desktop.
from google.cloud import bigquery
from google.oauth2 import service_account
credentials = service_account.Credentials.from_service_account_file('FILE PATH JSON')
project_id = 'PROJECT ID'
client = bigquery.Client(credentials = credentials, project = project_id)
# Example querying
dataset_ref = client.dataset("hacker_news", project="bigquery-public-data")
# API request - fetch the dataset
dataset = client.get_dataset(dataset_ref)
# List all the tables in the "hacker_news" dataset
tables = list(client.list_tables(dataset))
# Print names of all tables in the dataset (there are four!)
for table in tables:
print(table.table_id)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment