Created
March 25, 2020 10:13
-
-
Save Shuaib-8/ef1ab3e6d68ee241ec6e7a8ab552ce4b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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