I managed to load a sheet into a pandas dataframe using pd.read_csv(sheet_url)
but first I had to make the sheet public, which is not desirable.
Is there a way to authenticate somehow when running pd.read_csv(sheet_url)
from the cloud function?
I managed to load a sheet into a pandas dataframe using pd.read_csv(sheet_url)
but first I had to make the sheet public, which is not desirable.
Is there a way to authenticate somehow when running pd.read_csv(sheet_url)
from the cloud function?
I am suggesting below the different approaches which you can try to resolve your query:
GCP provides service accounts for sharing the sheet only with that account rather than making it public and steps for that are: Create the service account. Save the service account key Create an API key Save the API key Grant spreadsheet access to the service account Here is the quickstart which you can perform to get yourself familiar with the official Python APIs for Google Drive. Additionally, you can refer to how to access Google Sheet using OAuth and Python API as mentioned here.
Pandas support the Google Cloud BigQuery APIs including Authenticating with a Service Account, but similar out-of-box APIs are not available for Google Drive/Sheets. However, you can look at this StackOverflow answer on how to achieve this using pandas.
I’ve found a guide to Google Sheets with Python which can help, it uses a python package called pygsheets.