As of January 1, 2020 this library no longer supports Python 2 on the latest released version. Library versions released prior to that date will continue to be available. For more information please visit Python 2 support on Google Cloud.

google.cloud.bigquery.table.Row

class google.cloud.bigquery.table.Row(values, field_to_index)[source]

A BigQuery row.

Values can be accessed by position (index), by key like a dict, or as properties.

Parameters
  • values (Sequence[object]) – The row values

  • field_to_index (Dict[str, int]) – A mapping from schema field names to indexes

__init__(values, field_to_index)[source]

Initialize self. See help(type(self)) for accurate signature.

Methods

__init__(values, field_to_index)

Initialize self.

get(key[, default])

Return a value for key, with a default value if it does not exist.

items()

Return items as (key, value) pairs.

keys()

Return the keys for using a row as a dict.

values()

Return the values included in this row.

get(key, default=None)[source]

Return a value for key, with a default value if it does not exist.

Parameters
  • key (str) – The key of the column to access

  • default (object) – The default value to use if the key does not exist. (Defaults to None.)

Returns

The value associated with the provided key, or a default value.

Return type

object

Examples

When the key exists, the value associated with it is returned.

>>> Row(('a', 'b'), {'x': 0, 'y': 1}).get('x')
'a'

The default value is None when the key does not exist.

>>> Row(('a', 'b'), {'x': 0, 'y': 1}).get('z')
None

The default value can be overrided with the default parameter.

>>> Row(('a', 'b'), {'x': 0, 'y': 1}).get('z', '')
''
>>> Row(('a', 'b'), {'x': 0, 'y': 1}).get('z', default = '')
''
items()[source]

Return items as (key, value) pairs.

Returns

The (key, value) pairs representing this row.

Return type

Iterable[Tuple[str, object]]

Examples

>>> list(Row(('a', 'b'), {'x': 0, 'y': 1}).items())
[('x', 'a'), ('y', 'b')]
keys()[source]

Return the keys for using a row as a dict.

Returns

The keys corresponding to the columns of a row

Return type

Iterable[str]

Examples

>>> list(Row(('a', 'b'), {'x': 0, 'y': 1}).keys())
['x', 'y']
values()[source]

Return the values included in this row.

Returns

A sequence of length len(row).

Return type

Sequence[object]