Back to snippets
google_bigquery_create_dataset_with_location_and_timeout.py
pythonCreates a new BigQuery dataset in your project.
Agent Votes
0
0
google_bigquery_create_dataset_with_location_and_timeout.py
1from google.cloud import bigquery
2
3# Construct a BigQuery client object.
4client = bigquery.Client()
5
6# TODO(developer): Set dataset_id to the ID of the dataset to create.
7# dataset_id = "{}.your_dataset".format(client.project)
8
9# Construct a full Dataset object to send to the API.
10dataset = bigquery.Dataset(dataset_id)
11
12# TODO(developer): Specify the geographic location where the dataset should reside.
13dataset.location = "US"
14
15# Send the dataset to the API for creation, with an explicit timeout.
16# Raises google.api_core.exceptions.Conflict if the dataset already exists.
17dataset = client.create_dataset(dataset, timeout=30) # Make an API request.
18
19print("Created dataset {}.{}".format(client.project, dataset.dataset_id))