Easyspread

class easyspread.Gspread(name: str, environ_prefix: str, credentials: str)

Bases: object

Google spreadsheet handler.

Parameters:
  • name (str) – name of spreadsheet to connect to
  • environ_prefix (str) – prefix of environment variables containing valid credits
  • credentials (dict) – path to json containing credentials
Variables:
  • credentials – valid credentials to manipulate a spreadsheet through the API
  • name – attribute to store argument name (spreadsheet name)
  • sheets – stores the worksheets opened with self.open_worksheet() as a dict, with the worksheet’s title as key

Environment variables need to have the form PROJECT_<varname>

PROJECT_ID
PRIVATE_KEY_ID
PRIVATE_KEY
CLIENT_ID
CLIENT_EMAIL
CLIENT_X509_CERT_URL
append_row(worksheet: str, item: list)

Append a row to a worksheet.

The method returns self so that calls to append_row can be chained.

Parameters:
  • worksheet (str) – worksheet to append row to
  • item (list) – values to append
delete_records(worksheet: str, rows: int = 1)

Delete records by resizing a worksheet.

static get_credentials(prefix: str, file: str)

Read private keys from environ and update json credentials

open_worksheet(title: str)

Open a worksheet and store it in self.sheets dictionary

read_records(worksheet: str) → list

Return records from a worksheet.

The method skips the header row.

class easyspread.NetworkWait(delay: int = 10, hostname: str = 'www.google.com')

Bases: object

Wait (infinitely) for an internet connexion.

Parameters:
  • delay (int) – seconds between each ping trial
  • hostname (str) – default www.google.com : the hostname to ping
Variables:

connected – indicates that a connexion was found

static ping(hostname: str) → bool

Ping the hostname to see if an internet connexion is available.

stubborn_ping(delay: int, hostname: str) → None

Ping every delay seconds until a connexion is found.