airflow.gcp.hooks.gsheets

This module contains a Google Sheets API hook

Module Contents

class airflow.gcp.hooks.gsheets.GSheetsHook(spreadsheet_id:str, gcp_conn_id:str='google_cloud_default', api_version:str='v4', delegate_to:str=None)[source]

Bases: airflow.contrib.hooks.gcp_api_base_hook.GoogleCloudBaseHook

Interact with Google Sheets via GCP 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.

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

  • api_version (str) – API Version

  • delegate_to (str) – The account to impersonate, if any. For this to work, the service account making the request must have domain-wide delegation enabled.

get_conn(self)[source]

Retrieves connection to Google Sheets.

Returns

Google Sheets services object.

Return type

Any

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

Gets values from Google Sheet from a single range https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/get

Parameters
  • range (str) – 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

batch_get_values(self, ranges:List, major_dimension:str='DIMENSION_UNSPECIFIED', value_render_option:str='FORMATTED_VALUE', date_time_render_option:str='SERIAL_NUMBER')[source]

Gets values from Google Sheet from a list of ranges https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/batchGet

Parameters
  • 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(self, range_:str, values:List, major_dimension:str='ROWS', value_input_option:str='RAW', include_values_in_response:bool=False, value_render_option:str='FORMATTED_VALUE', date_time_render_option:str='SERIAL_NUMBER')[source]

Updates values from Google Sheet from a single range https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/update

Parameters
  • range (str) – 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(self, ranges:List, values:List, major_dimension:str='ROWS', value_input_option:str='RAW', include_values_in_response:bool=False, value_render_option:str='FORMATTED_VALUE', date_time_render_option:str='SERIAL_NUMBER')[source]

Updates values from Google Sheet for multiple ranges https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/batchUpdate

Parameters
  • 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(self, range_:str, values:List, major_dimension:str='ROWS', value_input_option:str='RAW', insert_data_option:str='OVERWRITE', include_values_in_response:bool=False, value_render_option:str='FORMATTED_VALUE', date_time_render_option:str='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
  • range (str) – 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(self, range_:str)[source]

Clear values from Google Sheet from a single range https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/clear

Parameters

range (str) – The A1 notation of the values to retrieve.

Returns

Google Sheets API response.

Return type

Dict

batch_clear(self, ranges:List)[source]

Clear values from Google Sheet from a list of ranges https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/batchClear

Parameters

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

Returns

Google Sheets API response.

Return type

Dict