airflow.providers.google.suite.hooks.sheets

This module contains a Google Sheets API hook.

Module Contents

Classes

GSheetsHook

Interact with Google Sheets via Google Cloud connection.

class airflow.providers.google.suite.hooks.sheets.GSheetsHook(gcp_conn_id='google_cloud_default', api_version='v4', impersonation_chain=None)[source]

Bases: airflow.providers.google.common.hooks.base_google.GoogleBaseHook

Interact with Google Sheets via Google Cloud connection.

Reading and writing cells in Google Sheet: https://developers.google.com/sheets/api/guides/values

Parameters
  • gcp_conn_id (str) – The connection ID to use when fetching connection info.

  • api_version (str) – API Version

  • impersonation_chain (str | collections.abc.Sequence[str] | None) – Optional service account to impersonate using short-term credentials, or chained list of accounts required to get the access_token of the last account in the list, which will be impersonated in the request. If set as a string, the account must grant the originating account the Service Account Token Creator IAM role. If set as a sequence, the identities from the list must grant Service Account Token Creator IAM role to the directly preceding identity, with first account from the list granting this role to the originating account.

get_conn()[source]

Retrieve connection to Google Sheets.

Returns

Google Sheets services object.

Return type

Any

get_values(spreadsheet_id, range_, major_dimension='DIMENSION_UNSPECIFIED', value_render_option='FORMATTED_VALUE', date_time_render_option='SERIAL_NUMBER')[source]

Get values from Google Sheet from a single range.

https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/get

Parameters
  • spreadsheet_id (str) – The Google Sheet ID to interact with

  • range – The A1 notation of the values to retrieve.

  • major_dimension (str) – Indicates which dimension an operation should apply to. DIMENSION_UNSPECIFIED, ROWS, or COLUMNS

  • value_render_option (str) – Determines how values should be rendered in the output. FORMATTED_VALUE, UNFORMATTED_VALUE, or FORMULA

  • date_time_render_option (str) – Determines how dates should be rendered in the output. SERIAL_NUMBER or FORMATTED_STRING

Returns

An array of sheet values from the specified sheet.

Return type

list

batch_get_values(spreadsheet_id, ranges, major_dimension='DIMENSION_UNSPECIFIED', value_render_option='FORMATTED_VALUE', date_time_render_option='SERIAL_NUMBER')[source]

Get values from Google Sheet from a list of ranges.

https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/batchGet

Parameters
  • spreadsheet_id (str) – The Google Sheet ID to interact with

  • ranges (list) – The A1 notation of the values to retrieve.

  • major_dimension (str) – Indicates which dimension an operation should apply to. DIMENSION_UNSPECIFIED, ROWS, or COLUMNS

  • value_render_option (str) – Determines how values should be rendered in the output. FORMATTED_VALUE, UNFORMATTED_VALUE, or FORMULA

  • date_time_render_option (str) – Determines how dates should be rendered in the output. SERIAL_NUMBER or FORMATTED_STRING

Returns

Google Sheets API response.

Return type

dict

update_values(spreadsheet_id, range_, values, major_dimension='ROWS', value_input_option='RAW', include_values_in_response=False, value_render_option='FORMATTED_VALUE', date_time_render_option='SERIAL_NUMBER')[source]

Update values from Google Sheet from a single range.

https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/update

Parameters
  • spreadsheet_id (str) – The Google Sheet ID to interact with.

  • range – The A1 notation of the values to retrieve.

  • values (list) – Data within a range of the spreadsheet.

  • major_dimension (str) – Indicates which dimension an operation should apply to. DIMENSION_UNSPECIFIED, ROWS, or COLUMNS

  • value_input_option (str) – Determines how input data should be interpreted. RAW or USER_ENTERED

  • include_values_in_response (bool) – Determines if the update response should include the values of the cells that were updated.

  • value_render_option (str) – Determines how values should be rendered in the output. FORMATTED_VALUE, UNFORMATTED_VALUE, or FORMULA

  • date_time_render_option (str) – Determines how dates should be rendered in the output. SERIAL_NUMBER or FORMATTED_STRING

Returns

Google Sheets API response.

Return type

dict

batch_update_values(spreadsheet_id, ranges, values, major_dimension='ROWS', value_input_option='RAW', include_values_in_response=False, value_render_option='FORMATTED_VALUE', date_time_render_option='SERIAL_NUMBER')[source]

Update values from Google Sheet for multiple ranges.

https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/batchUpdate

Parameters
  • spreadsheet_id (str) – The Google Sheet ID to interact with

  • ranges (list) – The A1 notation of the values to retrieve.

  • values (list) – Data within a range of the spreadsheet.

  • major_dimension (str) – Indicates which dimension an operation should apply to. DIMENSION_UNSPECIFIED, ROWS, or COLUMNS

  • value_input_option (str) – Determines how input data should be interpreted. RAW or USER_ENTERED

  • include_values_in_response (bool) – Determines if the update response should include the values of the cells that were updated.

  • value_render_option (str) – Determines how values should be rendered in the output. FORMATTED_VALUE, UNFORMATTED_VALUE, or FORMULA

  • date_time_render_option (str) – Determines how dates should be rendered in the output. SERIAL_NUMBER or FORMATTED_STRING

Returns

Google Sheets API response.

Return type

dict

append_values(spreadsheet_id, range_, values, major_dimension='ROWS', value_input_option='RAW', insert_data_option='OVERWRITE', include_values_in_response=False, value_render_option='FORMATTED_VALUE', date_time_render_option='SERIAL_NUMBER')[source]

Append values from Google Sheet from a single range.

https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/append

Parameters
  • spreadsheet_id (str) – The Google Sheet ID to interact with

  • range – The A1 notation of the values to retrieve.

  • values (list) – Data within a range of the spreadsheet.

  • major_dimension (str) – Indicates which dimension an operation should apply to. DIMENSION_UNSPECIFIED, ROWS, or COLUMNS

  • value_input_option (str) – Determines how input data should be interpreted. RAW or USER_ENTERED

  • insert_data_option (str) – Determines how existing data is changed when new data is input. OVERWRITE or INSERT_ROWS

  • include_values_in_response (bool) – Determines if the update response should include the values of the cells that were updated.

  • value_render_option (str) – Determines how values should be rendered in the output. FORMATTED_VALUE, UNFORMATTED_VALUE, or FORMULA

  • date_time_render_option (str) – Determines how dates should be rendered in the output. SERIAL_NUMBER or FORMATTED_STRING

Returns

Google Sheets API response.

Return type

dict

clear(spreadsheet_id, range_)[source]

Clear values from Google Sheet from a single range.

https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/clear

Parameters
  • spreadsheet_id (str) – The Google Sheet ID to interact with

  • range – The A1 notation of the values to retrieve.

Returns

Google Sheets API response.

Return type

dict

batch_clear(spreadsheet_id, ranges)[source]

Clear values from Google Sheet from a list of ranges.

https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/batchClear

Parameters
  • spreadsheet_id (str) – The Google Sheet ID to interact with

  • ranges (list) – The A1 notation of the values to retrieve.

Returns

Google Sheets API response.

Return type

dict

get_spreadsheet(spreadsheet_id)[source]

Retrieve spreadsheet matching the given id.

Parameters

spreadsheet_id (str) – The spreadsheet id.

Returns

An spreadsheet that matches the sheet filter.

get_sheet_titles(spreadsheet_id, sheet_filter=None)[source]

Retrieve the sheet titles from a spreadsheet matching the given id and sheet filter.

Parameters
  • spreadsheet_id (str) – The spreadsheet id.

  • sheet_filter (list[str] | None) – List of sheet title to retrieve from sheet.

Returns

An list of sheet titles from the specified sheet that match the sheet filter.

create_spreadsheet(spreadsheet)[source]

Create a spreadsheet, returning the newly created spreadsheet.

Parameters

spreadsheet (dict[str, Any]) – an instance of Spreadsheet https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets#Spreadsheet

Returns

An spreadsheet object.

Return type

dict[str, Any]

Was this entry helpful?