Datasets#

Define API Datasets.

class google.cloud.bigquery.dataset.AccessGrant(role, entity_type, entity_id)[source]#

Bases: object

Represent grant of an access role to an entity.

Every entry in the access list will have exactly one of userByEmail, groupByEmail, domain, specialGroup or view set. And if anything but view is set, it’ll also have a role specified. role is omitted for a view, since view s are always read-only.

See https://cloud.google.com/bigquery/docs/reference/rest/v2/datasets.

Parameters:
  • role (str) –

    Role granted to the entity. One of

    • 'OWNER'
    • 'WRITER'
    • 'READER'

    May also be None if the entity_type is view.

  • entity_type (str) – Type of entity being granted the role. One of ENTITY_TYPES.
  • entity_id (str) – ID of entity being granted the role.
Raises:

ValueError if the entity_type is not among ENTITY_TYPES, or if a view has role set or a non view does not have a role set.

ENTITY_TYPES = frozenset(['specialGroup', 'groupByEmail', 'userByEmail', 'domain', 'view'])#

Allowed entity types.

class google.cloud.bigquery.dataset.Dataset(name, client, access_grants=(), project=None)[source]#

Bases: object

Datasets are containers for tables.

See: https://cloud.google.com/bigquery/docs/reference/rest/v2/datasets

Parameters:
  • name (str) – the name of the dataset
  • client (google.cloud.bigquery.client.Client) – A client which holds credentials and project configuration for the dataset (which requires a project).
  • access_grants (list of AccessGrant) – roles granted to entities for this dataset
  • project (str) – (Optional) project ID for the dataset (defaults to the project of the client).
access_grants#

Dataset’s access grants.

Return type:list of AccessGrant
Returns:roles granted to entities for this dataset
create(client=None)[source]#

API call: create the dataset via a PUT request.

See: https://cloud.google.com/bigquery/docs/reference/rest/v2/tables/insert

Parameters:client (Client or NoneType) – the client to use. If not passed, falls back to the client stored on the current dataset.
created#

Datetime at which the dataset was created.

Return type:datetime.datetime, or NoneType
Returns:the creation time (None until set from the server).
dataset_id#

ID for the dataset resource.

Return type:str, or NoneType
Returns:the ID (None until set from the server).
default_table_expiration_ms#

Default expiration time for tables in the dataset.

Return type:int, or NoneType
Returns:The time in milliseconds, or None (the default).
delete(client=None)[source]#

API call: delete the dataset via a DELETE request.

See: https://cloud.google.com/bigquery/docs/reference/rest/v2/tables/delete

Parameters:client (Client or NoneType) – the client to use. If not passed, falls back to the client stored on the current dataset.
description#

Description of the dataset.

Return type:str, or NoneType
Returns:The description as set by the user, or None (the default).
etag#

ETag for the dataset resource.

Return type:str, or NoneType
Returns:the ETag (None until set from the server).
exists(client=None)[source]#

API call: test for the existence of the dataset via a GET request

See https://cloud.google.com/bigquery/docs/reference/rest/v2/datasets/get

Parameters:client (Client or NoneType) – the client to use. If not passed, falls back to the client stored on the current dataset.
Return type:bool
Returns:Boolean indicating existence of the dataset.
friendly_name#

Title of the dataset.

Return type:str, or NoneType
Returns:The name as set by the user, or None (the default).
classmethod from_api_repr(resource, client)[source]#

Factory: construct a dataset given its API representation

Parameters:
  • resource (dict) – dataset resource representation returned from the API
  • client (google.cloud.bigquery.client.Client) – Client which holds credentials and project configuration for the dataset.
Return type:

google.cloud.bigquery.dataset.Dataset

Returns:

Dataset parsed from resource.

list_tables(max_results=None, page_token=None)[source]#

List tables for the project associated with this client.

See: https://cloud.google.com/bigquery/docs/reference/rest/v2/tables/list

Parameters:
  • max_results (int) – (Optional) Maximum number of tables to return. If not passed, defaults to a value set by the API.
  • page_token (str) – (Optional) Opaque marker for the next “page” of datasets. If not passed, the API will return the first page of datasets.
Return type:

Iterator

Returns:

Iterator of Table contained within the current dataset.

location#

Location in which the dataset is hosted.

Return type:str, or NoneType
Returns:The location as set by the user, or None (the default).
modified#

Datetime at which the dataset was last modified.

Return type:datetime.datetime, or NoneType
Returns:the modification time (None until set from the server).
patch(client=None, **kw)[source]#

API call: update individual dataset properties via a PATCH request.

See https://cloud.google.com/bigquery/docs/reference/rest/v2/datasets/patch

Parameters:
  • client (Client or NoneType) – the client to use. If not passed, falls back to the client stored on the current dataset.
  • kw (dict) – properties to be patched.
Raises:

ValueError for invalid value types.

path#

URL path for the dataset’s APIs.

Return type:str
Returns:the path based on project and dataste name.
project#

Project bound to the dataset.

Return type:str
Returns:the project (derived from the client).
reload(client=None)[source]#

API call: refresh dataset properties via a GET request.

See https://cloud.google.com/bigquery/docs/reference/rest/v2/datasets/get

Parameters:client (Client or NoneType) – the client to use. If not passed, falls back to the client stored on the current dataset.

URL for the dataset resource.

Return type:str, or NoneType
Returns:the URL (None until set from the server).
table(name, schema=())[source]#

Construct a table bound to this dataset.

Parameters:
  • name (str) – Name of the table.
  • schema (list of google.cloud.bigquery.table.SchemaField) – The table’s schema
Return type:

google.cloud.bigquery.table.Table

Returns:

a new Table instance

update(client=None)[source]#

API call: update dataset properties via a PUT request.

See https://cloud.google.com/bigquery/docs/reference/rest/v2/datasets/update

Parameters:client (Client or NoneType) – the client to use. If not passed, falls back to the client stored on the current dataset.