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/v2/datasets.

Parameters:
  • role (string) –

    Role granted to the entity. One of

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

    May also be None if the entity_type is view.

  • entity_type (string) – Type of entity being granted the role. One of ENTITY_TYPES.
  • entity_id (string) – 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=())[source]#

Bases: object

Datasets are containers for tables.

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

Parameters:
  • name (string) – 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
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/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:string, 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:integer, 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/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:string, or NoneType
Returns:The description as set by the user, or None (the default).
etag#

ETag for the dataset resource.

Return type:string, 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/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:string, 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/v2/tables/list

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

tuple, (list, str)

Returns:

list of google.cloud.bigquery.table.Table, plus a “next page token” string: if not None, indicates that more tables can be retrieved with another call (pass that value as page_token).

location#

Location in which the dataset is hosted.

Return type:string, 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/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:string
Returns:the path based on project and dataste name.
project#

Project bound to the dataset.

Return type:string
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/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:string, or NoneType
Returns:the URL (None until set from the server).
table(name, schema=())[source]#

Construct a table bound to this dataset.

Parameters:
  • name (string) – 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/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.