GoogleSheetsUtils¶
GoogleSheetsUtils makes it easy to read from and write to Google Sheets — a common destination for eval results, test reports, and conversation analytics that need to be shared with non-technical stakeholders.
You'll typically reach for this class after running a batch of evaluations with ToolEvals or SimulationEvals and wanting to push the results DataFrame into a shared spreadsheet automatically.
Quick Example¶
from cxas_scrapi import GoogleSheetsUtils
import pandas as pd
gs = GoogleSheetsUtils(creds_path="/path/to/service_account.json")
# Read data from a sheet
df = gs.read_sheet(
spreadsheet_id="1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgVE2upms",
sheet_name="Tool Eval Results",
)
print(df.head())
# Write a DataFrame back to a sheet
results_df = pd.DataFrame([
{"test": "lookup_account", "status": "PASSED", "latency_ms": 145.2},
{"test": "set_session_state", "status": "FAILED", "latency_ms": 88.0},
])
gs.write_sheet(
spreadsheet_id="1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgVE2upms",
sheet_name="Tool Eval Results",
data=results_df,
)
print("Results uploaded to Google Sheets!")
Reference¶
GoogleSheetsUtils ¶
Bases: Common
Utility class for dataframe functions and Google Sheets integrations.
Source code in src/cxas_scrapi/utils/google_sheets_utils.py
sheets_to_dataframe ¶
Move data from Google Sheets to a pandas DataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sheet_name | str | The name of the Google Sheet document. | required |
worksheet_name | Optional[str] | The name of the specific worksheet tab. If None, defaults to the first sheet. | None |
Returns:
| Type | Description |
|---|---|
DataFrame | A pandas DataFrame containing the sheet data. |
Source code in src/cxas_scrapi/utils/google_sheets_utils.py
dataframe_to_sheets ¶
Move data from a pandas DataFrame to Google Sheets.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataframe | DataFrame | The pandas DataFrame to write. | required |
sheet_name | str | The name of the Google Sheet document. | required |
worksheet_name | Optional[str] | The name of the specific worksheet tab. If None, defaults to the first sheet. | None |
Source code in src/cxas_scrapi/utils/google_sheets_utils.py
append_dataframe_to_sheets ¶
Append data from a pandas DataFrame to an existing Google Sheet tab.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataframe | DataFrame | The pandas DataFrame to append. | required |
sheet_name | str | The name of the Google Sheet document. | required |
worksheet_name | Optional[str] | The name of the specific worksheet tab. If None, defaults to the first sheet. | None |