Connection

class Connection(credentials_path=None, credentials_dict=None)

Authenticates with Google and holds the underlying gspread client.

Exactly one of credentials_path or credentials_dict must be supplied.

Parameters:
  • credentials_path (Path | str | None) – Path to a service-account JSON key file.

  • credentials_dict (dict | None) – Service-account credentials as a dictionary (useful when loading from an environment variable).

Raises:

ValueError – If neither argument is provided.

Examples

From a file:

from betterspread import Connection

con = Connection(credentials_path="./credentials.json")

From an environment variable:

import json
import os
from betterspread import Connection

con = Connection(credentials_dict=json.loads(os.environ["GOOGLE_CREDENTIALS"]))