```Hello everyone, I can't figure out how to use n...
# ask-community
k
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
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
Read table rows
Copy code
i have the string "<https://docs.google.com/spreadsheets/d/15FMPFFa5KFsLPo7JRsJf2Zz>..." and the sheet_name
a
did you provide those to the task?
Copy code
ReadGsheetRow(credentials_filename=None, sheet_key=None, worksheet_name=None, **kwargs)
k
I'm having trouble using Task Sheets Read
a
do you get a specific error?
k
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
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
@Anna Geller is the path to the file in the cloud that was shared with
a
it’s a file local to the agent
k
Copy code
something like that
sample
a
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
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
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
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
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
in that case, you need to generate this credentials file as I mentioned before
k
Thank you 🙏
👍 1