Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Working with the `google-auth` module
import gspread
from google.oauth2 import service_account
from pprint import pprint
# used to retrieve credentials from the *creds.json* file
creds = service_account.Credentials.from_service_account_file("creds.json")
scoped_credentials = creds.with_scopes(
client = gspread.authorize(scoped_credentials)
# We're accessing the sheet 1 of the tester document
sheet ="tester").sheet1
# retrieves all records
print("\nRetrieving all records...")
data = sheet.get_all_records()
# retrieving specific row values
print("\nRetrieving information from row 3...")
row = sheet.row_values(3)
# retrieving specific column values
print("\nRetrieving information from column 3...")
col = sheet.col_values(3)
# retrieving specific cell
print("\nRetrieving value of a cell placed at (1, 2) in the sheet...")
cell = sheet.cell(1, 2).value
# inserting details into the sheet
print("\nInserting details into the sheet...")
insertDetails = ["Adithya", "", "33YEP4554"]
sheet.insert_row(insertDetails, 1)
# updating details in the sheet
print("\nUpdating details in the sheet...")
sheet.update_cell(2, 2, "")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment