In order to reduce the number of API calls to the Sheets API and aviod the dreaded 'error 429' message, I wish to utilise the Sheets API 'batchGet' function. I have placed all of my relevant information into one google spreadsheet spreadsheet_id, containing multiple worksheets ranges. The next step is to convert this batchGet request into a Pandas Dataframe.
Here is my code... If anyone can provide guidance on next steps to get this into a pandas df that would be great.
from googleapiclient.discovery import build
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request
from oauth2client.service_account import ServiceAccountCredentials
import pandas as pd
SCOPES = [ 'https://www.googleapis.com/auth/drive', 'https://www.googleapis.com/auth/spreadsheets']
credentials = ServiceAccountCredentials.from_json_keyfile_name('creds.json', SCOPES)
service = discovery.build('sheets', 'v4', credentials=credentials)
# The ID of the spreadsheet to retrieve data from.
spreadsheet_id = 'my_spreadheet_id' # TODO: Update placeholder value.
# The A1 notation of the values to retrieve.
ranges = ['2016_IGA!A2:BD', '2017_IGA!A2:BD', '2018_IGA!A2:BD', '2019_IGA!A2:BD', '2020_IGA!A2:BD',
'2016_Coles!A2:BD', '2017_Coles!A2:BD', '2018_Coles!A2:BD', '2019_Coles!A2:BD', '2020_Coles!A2:BD', # TODO: Update placeholder value.
'2016_WW!A2:BD', '2017_WW!A2:BD', '2018_WW!A2:BD', '2019_WW!A2:BD', '2020_WW!A2:BD',
'2018_Aldi!A2:BD', '2019_Aldi!A2:BD', '2020_Aldi!A2:BD']
value_render_option = 'FORMATTED_VALUE'
request = service.spreadsheets().values().batchGet(spreadsheetId=spreadsheet_id, ranges=ranges, valueRenderOption=value_render_option)
response = request.execute()