SheetsBatchReadDataTool()Create a tool from an API key.
Tool for reading data from multiple ranges in Google Sheets efficiently.
Inherits from
BaseReadTool.
Reads multiple ranges in a single API call, reducing network overhead and improving performance.
Tool Output:
success (bool): Whether operation succeeded. spreadsheet_id (str): The spreadsheet ID. requested_ranges (list): The ranges that were requested. total_ranges (int): Total number of ranges processed. successful_ranges (int): Number of successfully processed ranges. failed_ranges (int): Number of failed ranges. results (list): List of results for each range with data and error fields. value_render_option (str): Applied value rendering option. date_time_render_option (str): Applied date/time rendering option. major_dimension (str): Applied major dimension. convert_to_records (bool): Whether data was converted to records. numericise_values (bool): Whether values were numericised.
Read multiple ranges in one call:
from langchain_google_community.sheets import SheetsBatchReadDataTool
tool = SheetsBatchReadDataTool(api_key="your_api_key")
result = tool.run(
{
"spreadsheet_id": "1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms",
"ranges": ["A1:C5", "F1:H5", "Sheet2!A1:D10"],
}
)
for r in result["results"]:
print(f"{r['range']}: {len(r['data'])} rows")Read and convert to dictionaries:
result = tool.run(
{
"spreadsheet_id": "1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms",
"ranges": ["Sheet1!A1:D10", "Sheet2!A1:E10"],
"convert_to_records": True,
}
)