tessl install tessl/pypi-pygsheets@2.0.0Google Spreadsheets Python API v4
Agent Success
Agent success rate when using this tile
76%
Improvement
Agent success rate improvement when using this tile compared to baseline
1.23x
Baseline
Agent success rate without this tile
62%
Build a small auth helper that produces an authenticated Google Sheets session using a service account JSON file and optional drive scope. The helper should request spreadsheet access by default, add drive access only when explicitly asked, and let callers choose whether to validate the connection immediately or defer checks until first use.
build_client returns a session whose verify_access(spreadsheet_id) yields a dict containing the spreadsheet title and a positive sheet_count. @testbuild_client raises FileNotFoundError mentioning credentials. @testenable_drive=True and the drive scope is provided, drive_available() returns True and verify_access still succeeds for the same spreadsheet id. @testenable_drive=False, drive_available() returns False even if other scopes are provided. @testretries=0 and validate=False builds a session without performing network checks; verify_access is only executed when explicitly called. @test@generates
from typing import Iterable, Mapping, Any, Optional
class SheetsSession:
def verify_access(self, spreadsheet_id: str) -> dict:
"""Open the spreadsheet and return {'title': str, 'sheet_count': int}."""
def drive_available(self) -> bool:
"""Return True when drive-level access is active for this session."""
def build_client(
*,
service_account_file: Optional[str] = None,
service_account_json: Optional[Mapping[str, Any]] = None,
scopes: Optional[Iterable[str]] = None,
enable_drive: bool = False,
retries: int = 2,
validate: bool = True,
) -> SheetsSession:
"""Create an authenticated Sheets session using a service account.
Defaults request spreadsheet scopes; include drive scope when enable_drive is True.
Skip eager network validation when validate is False.
"""Provides authenticated access to Google Sheets and Drive APIs.