Links

Google Sheets

Fetch data from a sheet in google spreadsheet and get a data frame in your notebook.

Pre-requisite: share your Google Sheet with our service account

For the driver to fetch the contents of your google sheet, you need to share it with the service account linked with Naas.
Now you can fetch data from the sheet as a pandas data frame.
Get your spreadsheetId for your spreadsheet URL like this :

Get

import naas_drivers
spreadsheet_id = "idd"
sheet_name = "sheet_name"
# Dataframe is returned
df = naas_drivers.gsheet.connect(spreadsheet_id).get(
sheet_name=sheet_name
)

Send

Append

Append to the current sheet.
import naas_drivers
spreadsheet_id = "idd"
sheet_name = "sheet_name"
# Data accepts list of dict or dataframe
data = [{"name": "Jean", "email": "[email protected]"},
{"name": "Bunny", "email": "[email protected]"}]
naas_drivers.gsheet.connect(spreadsheet_id).send(
sheet_name=sheet_name,
data=data
)

Erase and replace

When you need to clear the sheet before filling it!
import naas_drivers
spreadsheet_id = "idd"
sheet_name = "sheet_name"
# Data accepts list of dict or dataframe
data = [{"name": "Jean", "email": "[email protected]"},
{"name": "Bunny", "email": "[email protected]"}]
naas_drivers.gsheet.connect(spreadsheet_id).send(
sheet_name=sheet_name,
data=data,
append=False
)

Delete

delete rows to the current sheet.
import naas_drivers
spreadsheet_id = "idd"
sheet_name = "sheet_name"
# Data accepts list of dict or dataframe
rows = [3, 4, 5]
naas_drivers.gsheet.connect(spreadsheet_id).delete(
sheet_name=sheet_name,
rows=rows
)

Connect

You can also save your connection and don't repeat it for each method.
import naas_drivers
gsheet = naas_drivers.gsheet.connect("spreadsheet_id")

Official documentation