https://prefect.io logo
k

Konstantin

02/01/2022, 12:41 PM
Copy code
Hello everyone, I can't figure out how to use native libraries in Prefect, for example "prefect.tasks.gsheets"
Give an example of the code for using this class
a

Anna Geller

02/01/2022, 12:43 PM
90% of tasks in the task library are community contributed, that’s why sometimes there might be no examples in the docs. But if you have troubles figuring out how to use a specific task, we can certainly help. Do you have issues using GSheets tasks? The Read or Write one?
k

Konstantin

02/01/2022, 12:45 PM
Read table rows
Copy code
i have the string "<https://docs.google.com/spreadsheets/d/15FMPFFa5KFsLPo7JRsJf2Zz>..." and the sheet_name
a

Anna Geller

02/01/2022, 1:07 PM
did you provide those to the task?
Copy code
ReadGsheetRow(credentials_filename=None, sheet_key=None, worksheet_name=None, **kwargs)
k

Konstantin

02/01/2022, 1:08 PM
I'm having trouble using Task Sheets Read
a

Anna Geller

02/01/2022, 1:09 PM
do you get a specific error?
k

Konstantin

02/01/2022, 1:09 PM
Copy code
from prefect.tasks.gsheets import gsheets

filename=None
key=<https://docs.google.com/spreadsheets/d/15FMPFFa5KFsLPo7JRsJf2Zz>.."
worksheet="sheet_name"

value = gsheets.ReadGsheetRow(credentials_filename=filename, sheet_key=key, worksheet_name=worksheet)
a

Anna Geller

02/01/2022, 1:11 PM
I think sheet key should be
Copy code
"15FMPFFa5KFsLPo7JRsJf2Zz"
and credentials file is a local path to your Google JSON file from Google API - did you generate that?
This page explains how you can create the credentials file https://developers.google.com/workspace/guides/create-credentials and this explains the API itself - it’s quite straightforward, probably the credentials is the hardest step here, correct? https://developers.google.com/sheets/api/quickstart/python
k

Konstantin

02/01/2022, 1:14 PM
@Anna Geller is the path to the file in the cloud that was shared with
a

Anna Geller

02/01/2022, 1:14 PM
it’s a file local to the agent
k

Konstantin

02/01/2022, 1:15 PM
Copy code
something like that
sample
a

Anna Geller

02/01/2022, 1:33 PM
Did you intend to share a Google Sheet with me? I can’t access that. You need to create a credentials file first before you can use this task. Can you check the link I shared before?
Copy code
try now
a

Anna Geller

02/01/2022, 1:40 PM
how is this helpful? 😄 you still need to generate a credentials file in order to retrieve this data via Google Python API
I’m afraid you really need to go through the process described here starting with the prerequisites
k

Konstantin

02/01/2022, 1:46 PM
i need to prefect to create any mail account, after go through this link, create api key. After my prefect account give access to google sheet?
a

Anna Geller

02/01/2022, 1:46 PM
Do you need to read this data from Google Sheets on a regular basis? If you need to read it only once, perhaps you can download this table as a CSV file and read it in with Pandas?
so Prefect API key works completely independently from the Google Sheets task. I would recommend to first finish the flow so that it runs fine locally (e.g. using the
flow.run()
command or using
prefect run
CLI) and once that’s finished you can look at how you can deploy it to Prefect Cloud - what do you think?
k

Konstantin

02/01/2022, 1:56 PM
I do not know what to say
Yes, I need to regularly read this data from Google Sheets, I need to read it once in one run, I need to load this table as an array into Pandas
a

Anna Geller

02/01/2022, 2:09 PM
in that case, you need to generate this credentials file as I mentioned before
k

Konstantin

02/01/2022, 2:15 PM
Thank you 🙏
👍 1
6 Views