Skip to content

Instantly share code, notes, and snippets.

@salvadorgascon
Created February 23, 2024 12:52
Show Gist options
  • Save salvadorgascon/7b706af7a5b3e200353fdb186a1f2d72 to your computer and use it in GitHub Desktop.
Save salvadorgascon/7b706af7a5b3e200353fdb186a1f2d72 to your computer and use it in GitHub Desktop.
Check if exists a dataset object in Google Cloud BigQuery
from google.cloud import bigquery
from google.cloud.exceptions import NotFound
def BigQueryDatasetExists(bigquery_client, bigquery_dataset_name):
exists_dataset = False
print("Checking dataset " + bigquery_dataset_name, '...', end="")
try:
bigquery_client.get_dataset(bigquery_dataset_name)
print("OK")
return True
except NotFound:
print("FAIL")
pass
return exists_dataset
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment