Skip to main content

Google Sheets

Step 1: Create a connection

To create a Google Sheets connection, go to the Cloud Console and select Google Sheets from the list of connectors. Follow the steps to authorize your Google account.

Creating on Cloud Console

Step 2: Installing gspread package

Once you have created the connection, you can use it in your code. We recommend using the gspread library to interact with Google Sheets.

You can install it using the "Requirements" tab in the Editor or by running the following command in your terminal:

pip install gspread

Step 3: Using the connection

You can use the connection in your code by importing the get_google_sheets_credentials function from the abstra.connectors module. This function will return the credentials you need to access your Google Sheets. The example below shows how to read a cell from a Google Sheet:

Basic Example

from gspread.client import Client as GSpreadClient
from abstra.connectors import get_google_sheets_credentials

gc = GSpreadClient(get_google_sheets_credentials())
worksheet = gc.open_by_url("SHEET_URL") # https://docs.google.com/spreadsheets/d/13...

cell_a1 = worksheet.get_worksheet(0).acell("A1")

print(cell_a1.value)

Getting All Values From a Row or a Column

from gspread.client import Client as GSpreadClient
from abstra.connectors import get_google_sheets_credentials

gc = GSpreadClient(get_google_sheets_credentials())
worksheet = gc.open_by_url("SHEET_URL") # https://docs.google.com/spreadsheets/d/13...
row = worksheet.get_worksheet(0).row_values(1)
column = worksheet.get_worksheet(0).col_values(1)
print(row)
print(column)

Updating a Cell

from gspread.client import Client as GSpreadClient
from abstra.connectors import get_google_sheets_credentials

gc = GSpreadClient(get_google_sheets_credentials())

worksheet = gc.open_by_url("SHEET_URL") # https://docs.google.com/spreadsheets/d/13...
worksheet.get_worksheet(0).update_acell("A1", "New Value")

More Examples

You can find more examples in detail at the gspread documentation.