universal-mcp-applications 0.1.17__py3-none-any.whl → 0.1.33__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of universal-mcp-applications might be problematic. Click here for more details.
- universal_mcp/applications/BEST_PRACTICES.md +166 -0
- universal_mcp/applications/ahrefs/README.md +3 -3
- universal_mcp/applications/airtable/README.md +3 -3
- universal_mcp/applications/airtable/app.py +0 -1
- universal_mcp/applications/apollo/app.py +0 -1
- universal_mcp/applications/asana/README.md +3 -3
- universal_mcp/applications/aws_s3/README.md +29 -0
- universal_mcp/applications/aws_s3/app.py +40 -39
- universal_mcp/applications/bill/README.md +249 -0
- universal_mcp/applications/browser_use/README.md +1 -0
- universal_mcp/applications/browser_use/__init__.py +0 -0
- universal_mcp/applications/browser_use/app.py +71 -0
- universal_mcp/applications/calendly/README.md +45 -45
- universal_mcp/applications/calendly/app.py +125 -125
- universal_mcp/applications/canva/README.md +35 -35
- universal_mcp/applications/canva/app.py +95 -99
- universal_mcp/applications/clickup/README.md +4 -4
- universal_mcp/applications/confluence/app.py +0 -1
- universal_mcp/applications/contentful/README.md +1 -2
- universal_mcp/applications/contentful/app.py +4 -5
- universal_mcp/applications/crustdata/README.md +3 -3
- universal_mcp/applications/domain_checker/README.md +2 -2
- universal_mcp/applications/domain_checker/app.py +11 -15
- universal_mcp/applications/e2b/README.md +4 -4
- universal_mcp/applications/e2b/app.py +4 -4
- universal_mcp/applications/elevenlabs/README.md +3 -77
- universal_mcp/applications/elevenlabs/app.py +18 -15
- universal_mcp/applications/exa/README.md +7 -7
- universal_mcp/applications/exa/app.py +17 -17
- universal_mcp/applications/falai/README.md +13 -12
- universal_mcp/applications/falai/app.py +34 -35
- universal_mcp/applications/figma/README.md +3 -3
- universal_mcp/applications/file_system/README.md +13 -0
- universal_mcp/applications/file_system/app.py +9 -9
- universal_mcp/applications/firecrawl/README.md +9 -9
- universal_mcp/applications/firecrawl/app.py +46 -46
- universal_mcp/applications/fireflies/README.md +14 -14
- universal_mcp/applications/fireflies/app.py +164 -57
- universal_mcp/applications/fpl/README.md +12 -12
- universal_mcp/applications/fpl/app.py +54 -55
- universal_mcp/applications/ghost_content/app.py +0 -1
- universal_mcp/applications/github/README.md +10 -10
- universal_mcp/applications/github/app.py +50 -52
- universal_mcp/applications/google_calendar/README.md +10 -10
- universal_mcp/applications/google_calendar/app.py +50 -49
- universal_mcp/applications/google_docs/README.md +14 -14
- universal_mcp/applications/google_docs/app.py +307 -233
- universal_mcp/applications/google_drive/README.md +54 -57
- universal_mcp/applications/google_drive/app.py +270 -261
- universal_mcp/applications/google_gemini/README.md +3 -14
- universal_mcp/applications/google_gemini/app.py +15 -18
- universal_mcp/applications/google_mail/README.md +20 -20
- universal_mcp/applications/google_mail/app.py +110 -109
- universal_mcp/applications/google_searchconsole/README.md +10 -10
- universal_mcp/applications/google_searchconsole/app.py +37 -37
- universal_mcp/applications/google_sheet/README.md +25 -25
- universal_mcp/applications/google_sheet/app.py +270 -266
- universal_mcp/applications/hashnode/README.md +6 -3
- universal_mcp/applications/hashnode/app.py +174 -25
- universal_mcp/applications/http_tools/README.md +5 -5
- universal_mcp/applications/http_tools/app.py +10 -11
- universal_mcp/applications/hubspot/api_segments/__init__.py +0 -0
- universal_mcp/applications/hubspot/api_segments/api_segment_base.py +54 -0
- universal_mcp/applications/hubspot/api_segments/crm_api.py +7337 -0
- universal_mcp/applications/hubspot/api_segments/marketing_api.py +1467 -0
- universal_mcp/applications/hubspot/app.py +2 -15
- universal_mcp/applications/jira/app.py +0 -1
- universal_mcp/applications/klaviyo/README.md +0 -36
- universal_mcp/applications/linkedin/README.md +18 -4
- universal_mcp/applications/linkedin/app.py +763 -162
- universal_mcp/applications/mailchimp/README.md +3 -3
- universal_mcp/applications/markitdown/app.py +10 -5
- universal_mcp/applications/ms_teams/README.md +31 -31
- universal_mcp/applications/ms_teams/app.py +151 -151
- universal_mcp/applications/neon/README.md +3 -3
- universal_mcp/applications/onedrive/README.md +24 -0
- universal_mcp/applications/onedrive/__init__.py +1 -0
- universal_mcp/applications/onedrive/app.py +338 -0
- universal_mcp/applications/openai/README.md +18 -17
- universal_mcp/applications/openai/app.py +40 -39
- universal_mcp/applications/outlook/README.md +9 -9
- universal_mcp/applications/outlook/app.py +307 -225
- universal_mcp/applications/perplexity/README.md +4 -4
- universal_mcp/applications/perplexity/app.py +4 -4
- universal_mcp/applications/posthog/README.md +128 -127
- universal_mcp/applications/reddit/README.md +21 -124
- universal_mcp/applications/reddit/app.py +51 -68
- universal_mcp/applications/resend/README.md +29 -29
- universal_mcp/applications/resend/app.py +116 -117
- universal_mcp/applications/rocketlane/app.py +0 -1
- universal_mcp/applications/scraper/README.md +7 -4
- universal_mcp/applications/scraper/__init__.py +1 -1
- universal_mcp/applications/scraper/app.py +341 -103
- universal_mcp/applications/semrush/README.md +3 -0
- universal_mcp/applications/serpapi/README.md +3 -3
- universal_mcp/applications/serpapi/app.py +14 -14
- universal_mcp/applications/sharepoint/README.md +19 -0
- universal_mcp/applications/sharepoint/app.py +285 -173
- universal_mcp/applications/shopify/app.py +0 -1
- universal_mcp/applications/shortcut/README.md +3 -3
- universal_mcp/applications/slack/README.md +23 -0
- universal_mcp/applications/slack/app.py +79 -48
- universal_mcp/applications/spotify/README.md +3 -3
- universal_mcp/applications/supabase/README.md +3 -3
- universal_mcp/applications/tavily/README.md +4 -4
- universal_mcp/applications/tavily/app.py +4 -4
- universal_mcp/applications/twilio/README.md +15 -0
- universal_mcp/applications/twitter/README.md +92 -89
- universal_mcp/applications/twitter/api_segments/compliance_api.py +13 -15
- universal_mcp/applications/twitter/api_segments/dm_conversations_api.py +20 -20
- universal_mcp/applications/twitter/api_segments/dm_events_api.py +12 -12
- universal_mcp/applications/twitter/api_segments/likes_api.py +12 -12
- universal_mcp/applications/twitter/api_segments/lists_api.py +37 -39
- universal_mcp/applications/twitter/api_segments/spaces_api.py +24 -24
- universal_mcp/applications/twitter/api_segments/trends_api.py +4 -4
- universal_mcp/applications/twitter/api_segments/tweets_api.py +105 -105
- universal_mcp/applications/twitter/api_segments/usage_api.py +4 -4
- universal_mcp/applications/twitter/api_segments/users_api.py +136 -136
- universal_mcp/applications/twitter/app.py +15 -11
- universal_mcp/applications/whatsapp/README.md +12 -12
- universal_mcp/applications/whatsapp/app.py +66 -67
- universal_mcp/applications/whatsapp/audio.py +39 -35
- universal_mcp/applications/whatsapp/whatsapp.py +176 -154
- universal_mcp/applications/whatsapp_business/README.md +23 -23
- universal_mcp/applications/whatsapp_business/app.py +92 -92
- universal_mcp/applications/yahoo_finance/README.md +17 -0
- universal_mcp/applications/yahoo_finance/__init__.py +1 -0
- universal_mcp/applications/yahoo_finance/app.py +300 -0
- universal_mcp/applications/youtube/README.md +46 -46
- universal_mcp/applications/youtube/app.py +208 -195
- universal_mcp/applications/zenquotes/README.md +1 -1
- universal_mcp/applications/zenquotes/__init__.py +2 -0
- universal_mcp/applications/zenquotes/app.py +5 -5
- {universal_mcp_applications-0.1.17.dist-info → universal_mcp_applications-0.1.33.dist-info}/METADATA +5 -90
- {universal_mcp_applications-0.1.17.dist-info → universal_mcp_applications-0.1.33.dist-info}/RECORD +137 -128
- universal_mcp/applications/replicate/README.md +0 -18
- universal_mcp/applications/replicate/__init__.py +0 -1
- universal_mcp/applications/replicate/app.py +0 -493
- universal_mcp/applications/unipile/README.md +0 -28
- universal_mcp/applications/unipile/__init__.py +0 -1
- universal_mcp/applications/unipile/app.py +0 -827
- {universal_mcp_applications-0.1.17.dist-info → universal_mcp_applications-0.1.33.dist-info}/WHEEL +0 -0
- {universal_mcp_applications-0.1.17.dist-info → universal_mcp_applications-0.1.33.dist-info}/licenses/LICENSE +0 -0
|
@@ -3,7 +3,7 @@ from typing import Any
|
|
|
3
3
|
from universal_mcp.applications.application import APIApplication
|
|
4
4
|
from universal_mcp.integrations import Integration
|
|
5
5
|
|
|
6
|
-
from .helper import (
|
|
6
|
+
from universal_mcp.applications.google_sheet.helper import (
|
|
7
7
|
analyze_sheet_for_tables,
|
|
8
8
|
analyze_table_schema,
|
|
9
9
|
)
|
|
@@ -21,45 +21,49 @@ class GoogleSheetApp(APIApplication):
|
|
|
21
21
|
|
|
22
22
|
def create_spreadsheet(self, title: str) -> dict[str, Any]:
|
|
23
23
|
"""
|
|
24
|
-
Creates a new, blank Google Spreadsheet file with a specified title. This function generates a completely new document, unlike `add_sheet` which adds a tab to an existing spreadsheet. It returns the API response containing the new spreadsheet's metadata.
|
|
25
|
-
|
|
24
|
+
Creates a new, blank Google Spreadsheet file with a specified title. This function generates a completely new document, unlike `add_sheet` which adds a worksheet (tab) to an existing spreadsheet. It returns the API response containing the new spreadsheet's metadata. Note that you need to call other google_sheet functions (e.g. `google_sheet__write_values_to_sheet`) to actually add content after creating the spreadsheet.
|
|
25
|
+
|
|
26
26
|
Args:
|
|
27
27
|
title: String representing the desired title for the new spreadsheet
|
|
28
|
-
|
|
28
|
+
|
|
29
29
|
Returns:
|
|
30
30
|
Dictionary containing the full response from the Google Sheets API, including the spreadsheet's metadata and properties
|
|
31
|
-
|
|
31
|
+
|
|
32
32
|
Raises:
|
|
33
33
|
HTTPError: When the API request fails due to invalid authentication, network issues, or API limitations
|
|
34
34
|
ValueError: When the title parameter is empty or contains invalid characters
|
|
35
|
-
|
|
35
|
+
|
|
36
36
|
Tags:
|
|
37
37
|
create, spreadsheet, google-sheets, api, important
|
|
38
38
|
"""
|
|
39
39
|
url = self.base_url
|
|
40
40
|
spreadsheet_data = {"properties": {"title": title}}
|
|
41
41
|
response = self._post(url, data=spreadsheet_data)
|
|
42
|
-
|
|
42
|
+
payload = self._handle_response(response)
|
|
43
|
+
payload["Note"] = (
|
|
44
|
+
"You must load and call other google_sheet content functions (like `google_sheet__write_values_to_sheet`)"
|
|
45
|
+
)
|
|
46
|
+
return payload
|
|
43
47
|
|
|
44
|
-
def get_spreadsheet_metadata(self,
|
|
48
|
+
def get_spreadsheet_metadata(self, spreadsheetId: str) -> dict[str, Any]:
|
|
45
49
|
"""
|
|
46
|
-
Retrieves a spreadsheet's metadata and structural properties, such as sheet names, IDs, and named ranges, using its unique ID. This function intentionally excludes cell data, distinguishing it from `get_values` which fetches the actual content within
|
|
47
|
-
|
|
50
|
+
Retrieves a spreadsheet's metadata and structural properties, such as sheet names, IDs, and named ranges, using its unique ID. This function intentionally excludes cell data, distinguishing it from `get_values` which fetches the actual content within cells.
|
|
51
|
+
|
|
48
52
|
Args:
|
|
49
|
-
|
|
50
|
-
|
|
53
|
+
spreadsheetId: The unique identifier of the Google Spreadsheet to retrieve (found in the spreadsheet's URL)
|
|
54
|
+
|
|
51
55
|
Returns:
|
|
52
56
|
A dictionary containing the full spreadsheet metadata and contents, including properties, sheets, named ranges, and other spreadsheet-specific information from the Google Sheets API
|
|
53
|
-
|
|
57
|
+
|
|
54
58
|
Raises:
|
|
55
|
-
HTTPError: When the API request fails due to invalid
|
|
59
|
+
HTTPError: When the API request fails due to invalid spreadsheetId or insufficient permissions
|
|
56
60
|
ConnectionError: When there's a network connectivity issue
|
|
57
61
|
ValueError: When the response cannot be parsed as JSON
|
|
58
|
-
|
|
62
|
+
|
|
59
63
|
Tags:
|
|
60
64
|
get, retrieve, spreadsheet, api, metadata, read, important
|
|
61
65
|
"""
|
|
62
|
-
url = f"{self.base_url}/{
|
|
66
|
+
url = f"{self.base_url}/{spreadsheetId}"
|
|
63
67
|
response = self._get(url)
|
|
64
68
|
return self._handle_response(response)
|
|
65
69
|
|
|
@@ -72,22 +76,22 @@ class GoogleSheetApp(APIApplication):
|
|
|
72
76
|
dateTimeRenderOption: str | None = None,
|
|
73
77
|
) -> dict[str, Any]:
|
|
74
78
|
"""
|
|
75
|
-
Retrieves cell values from a single, specified A1 notation range
|
|
76
|
-
|
|
79
|
+
Retrieves cell values from a single, specified A1 notation range. Unlike `batch_get_values_by_range` which fetches multiple ranges, this function is for a singular query and provides options to control the data's output format (e.g., rows vs. columns, formatted vs. raw values).
|
|
80
|
+
|
|
77
81
|
Args:
|
|
78
82
|
spreadsheetId: The unique identifier of the Google Spreadsheet to retrieve values from
|
|
79
83
|
range: A1 notation range string (e.g., 'Sheet1!A1:B2')
|
|
80
84
|
majorDimension: The major dimension that results should use. "ROWS" or "COLUMNS". Example: "ROWS"
|
|
81
85
|
valueRenderOption: How values should be represented in the output. "FORMATTED_VALUE", "UNFORMATTED_VALUE", or "FORMULA". Example: "FORMATTED_VALUE"
|
|
82
86
|
dateTimeRenderOption: How dates, times, and durations should be represented. "SERIAL_NUMBER" or "FORMATTED_STRING". Example: "FORMATTED_STRING"
|
|
83
|
-
|
|
87
|
+
|
|
84
88
|
Returns:
|
|
85
89
|
A dictionary containing the API response with the requested spreadsheet values and metadata
|
|
86
|
-
|
|
90
|
+
|
|
87
91
|
Raises:
|
|
88
|
-
HTTPError: If the API request fails due to invalid
|
|
89
|
-
ValueError: If the
|
|
90
|
-
|
|
92
|
+
HTTPError: If the API request fails due to invalid spreadsheetId, insufficient permissions, or invalid range format
|
|
93
|
+
ValueError: If the spreadsheetId is empty or invalid
|
|
94
|
+
|
|
91
95
|
Tags:
|
|
92
96
|
get, read, spreadsheet, values, important
|
|
93
97
|
"""
|
|
@@ -105,26 +109,26 @@ class GoogleSheetApp(APIApplication):
|
|
|
105
109
|
return self._handle_response(response)
|
|
106
110
|
|
|
107
111
|
def batch_get_values_by_range(
|
|
108
|
-
self,
|
|
112
|
+
self, spreadsheetId: str, ranges: list[str] | None = None
|
|
109
113
|
) -> dict[str, Any]:
|
|
110
114
|
"""
|
|
111
|
-
Efficiently retrieves values from multiple
|
|
112
|
-
|
|
115
|
+
Efficiently retrieves values from multiple predefined A1 notation ranges in a single API request. Unlike `get_values`, which fetches a single range, or `batch_get_values_by_data_filter`, which uses dynamic filtering criteria, this function operates on a simple list of range strings for bulk data retrieval.
|
|
116
|
+
|
|
113
117
|
Args:
|
|
114
|
-
|
|
118
|
+
spreadsheetId: The unique identifier of the Google Spreadsheet to retrieve values from
|
|
115
119
|
ranges: Optional list of A1 notation or R1C1 notation range strings (e.g., ['Sheet1!A1:B2', 'Sheet2!C3:D4']). If None, returns values from the entire spreadsheet
|
|
116
|
-
|
|
120
|
+
|
|
117
121
|
Returns:
|
|
118
122
|
A dictionary containing the API response with the requested spreadsheet values and metadata
|
|
119
|
-
|
|
123
|
+
|
|
120
124
|
Raises:
|
|
121
|
-
HTTPError: If the API request fails due to invalid
|
|
122
|
-
ValueError: If the
|
|
123
|
-
|
|
125
|
+
HTTPError: If the API request fails due to invalid spreadsheetId, insufficient permissions, or invalid range format
|
|
126
|
+
ValueError: If the spreadsheetId is empty or invalid
|
|
127
|
+
|
|
124
128
|
Tags:
|
|
125
129
|
get, batch, read, spreadsheet, values
|
|
126
130
|
"""
|
|
127
|
-
url = f"{self.base_url}/{
|
|
131
|
+
url = f"{self.base_url}/{spreadsheetId}/values:batchGet"
|
|
128
132
|
params = {}
|
|
129
133
|
if ranges:
|
|
130
134
|
params["ranges"] = ranges
|
|
@@ -133,7 +137,7 @@ class GoogleSheetApp(APIApplication):
|
|
|
133
137
|
|
|
134
138
|
def insert_dimensions(
|
|
135
139
|
self,
|
|
136
|
-
|
|
140
|
+
spreadsheetId: str,
|
|
137
141
|
sheet_id: int,
|
|
138
142
|
dimension: str,
|
|
139
143
|
start_index: int,
|
|
@@ -144,13 +148,13 @@ class GoogleSheetApp(APIApplication):
|
|
|
144
148
|
response_ranges: list[str] | None = None,
|
|
145
149
|
) -> dict[str, Any]:
|
|
146
150
|
"""
|
|
147
|
-
Inserts empty rows or columns at a
|
|
148
|
-
|
|
151
|
+
Inserts a specified number of empty rows or columns at a given index, shifting existing content. Distinct from `append_dimensions`, which only adds to the end, this function creates space within the sheet's data grid, preserving surrounding data and formatting.
|
|
152
|
+
|
|
149
153
|
This function inserts empty rows or columns at a specified location, shifting existing content.
|
|
150
154
|
Use this when you need to add rows/columns in the middle of your data.
|
|
151
|
-
|
|
155
|
+
|
|
152
156
|
Args:
|
|
153
|
-
|
|
157
|
+
spreadsheetId: The ID of the spreadsheet to update. Example: "abc123spreadsheetId"
|
|
154
158
|
sheet_id: The ID of the sheet where the dimensions will be inserted. Example: 0
|
|
155
159
|
dimension: The dimension to insert. Valid values are "ROWS" or "COLUMNS". Example: "ROWS"
|
|
156
160
|
start_index: The start index (0-based) of the dimension range to insert. The inserted dimensions will be placed before this index. Example: 1
|
|
@@ -159,19 +163,19 @@ class GoogleSheetApp(APIApplication):
|
|
|
159
163
|
include_spreadsheet_in_response: True if the updated spreadsheet should be included in the response. Example: True
|
|
160
164
|
response_include_grid_data: True if grid data should be included in the response (if includeSpreadsheetInResponse is true). Example: True
|
|
161
165
|
response_ranges: Limits the ranges of the spreadsheet to include in the response. Example: ["Sheet1!A1:B10"]
|
|
162
|
-
|
|
166
|
+
|
|
163
167
|
Returns:
|
|
164
168
|
A dictionary containing the Google Sheets API response with update details
|
|
165
|
-
|
|
169
|
+
|
|
166
170
|
Raises:
|
|
167
171
|
HTTPError: When the API request fails due to invalid parameters or insufficient permissions
|
|
168
|
-
ValueError: When
|
|
169
|
-
|
|
172
|
+
ValueError: When spreadsheetId is empty or dimension is not "ROWS" or "COLUMNS"
|
|
173
|
+
|
|
170
174
|
Tags:
|
|
171
175
|
insert, modify, spreadsheet, rows, columns, dimensions, important
|
|
172
176
|
"""
|
|
173
|
-
if not
|
|
174
|
-
raise ValueError("
|
|
177
|
+
if not spreadsheetId:
|
|
178
|
+
raise ValueError("spreadsheetId cannot be empty")
|
|
175
179
|
|
|
176
180
|
if dimension not in ["ROWS", "COLUMNS"]:
|
|
177
181
|
raise ValueError('dimension must be either "ROWS" or "COLUMNS"')
|
|
@@ -182,7 +186,7 @@ class GoogleSheetApp(APIApplication):
|
|
|
182
186
|
if start_index >= end_index:
|
|
183
187
|
raise ValueError("end_index must be greater than start_index")
|
|
184
188
|
|
|
185
|
-
url = f"{self.base_url}/{
|
|
189
|
+
url = f"{self.base_url}/{spreadsheetId}:batchUpdate"
|
|
186
190
|
|
|
187
191
|
request_body: dict[str, Any] = {
|
|
188
192
|
"requests": [
|
|
@@ -217,35 +221,35 @@ class GoogleSheetApp(APIApplication):
|
|
|
217
221
|
|
|
218
222
|
def append_dimensions(
|
|
219
223
|
self,
|
|
220
|
-
|
|
224
|
+
spreadsheetId: str,
|
|
221
225
|
sheet_id: int,
|
|
222
226
|
dimension: str,
|
|
223
227
|
length: int,
|
|
224
228
|
) -> dict[str, Any]:
|
|
225
229
|
"""
|
|
226
|
-
Adds a specified number of empty rows or columns to the end of a designated sheet. Unlike `insert_dimensions`, which adds
|
|
227
|
-
|
|
230
|
+
Adds a specified number of empty rows or columns to the end of a designated sheet. Unlike `insert_dimensions`, which adds space at a specific index, this function exclusively extends the sheet's boundaries at the bottom or to the right without affecting existing content.
|
|
231
|
+
|
|
228
232
|
This function adds empty rows or columns to the end of the sheet without affecting existing content.
|
|
229
233
|
Use this when you need to extend the sheet with additional space at the bottom or right.
|
|
230
|
-
|
|
234
|
+
|
|
231
235
|
Args:
|
|
232
|
-
|
|
236
|
+
spreadsheetId: The unique identifier of the Google Spreadsheet to modify
|
|
233
237
|
sheet_id: The ID of the sheet within the spreadsheet (0 for first sheet)
|
|
234
238
|
dimension: The type of dimension to append - "ROWS" or "COLUMNS"
|
|
235
239
|
length: The number of rows or columns to append to the end
|
|
236
|
-
|
|
240
|
+
|
|
237
241
|
Returns:
|
|
238
242
|
A dictionary containing the Google Sheets API response with update details
|
|
239
|
-
|
|
243
|
+
|
|
240
244
|
Raises:
|
|
241
245
|
HTTPError: When the API request fails due to invalid parameters or insufficient permissions
|
|
242
|
-
ValueError: When
|
|
243
|
-
|
|
246
|
+
ValueError: When spreadsheetId is empty, dimension is not "ROWS" or "COLUMNS", or length is not positive
|
|
247
|
+
|
|
244
248
|
Tags:
|
|
245
249
|
append, modify, spreadsheet, rows, columns, dimensions, important
|
|
246
250
|
"""
|
|
247
|
-
if not
|
|
248
|
-
raise ValueError("
|
|
251
|
+
if not spreadsheetId:
|
|
252
|
+
raise ValueError("spreadsheetId cannot be empty")
|
|
249
253
|
|
|
250
254
|
if dimension not in ["ROWS", "COLUMNS"]:
|
|
251
255
|
raise ValueError('dimension must be either "ROWS" or "COLUMNS"')
|
|
@@ -253,7 +257,7 @@ class GoogleSheetApp(APIApplication):
|
|
|
253
257
|
if length <= 0:
|
|
254
258
|
raise ValueError("length must be a positive integer")
|
|
255
259
|
|
|
256
|
-
url = f"{self.base_url}/{
|
|
260
|
+
url = f"{self.base_url}/{spreadsheetId}:batchUpdate"
|
|
257
261
|
|
|
258
262
|
request_body = {
|
|
259
263
|
"requests": [
|
|
@@ -272,7 +276,7 @@ class GoogleSheetApp(APIApplication):
|
|
|
272
276
|
|
|
273
277
|
def delete_dimensions(
|
|
274
278
|
self,
|
|
275
|
-
|
|
279
|
+
spreadsheetId: str,
|
|
276
280
|
sheet_id: int,
|
|
277
281
|
dimension: str,
|
|
278
282
|
start_index: int,
|
|
@@ -282,10 +286,10 @@ class GoogleSheetApp(APIApplication):
|
|
|
282
286
|
response_ranges: list[str] | None = None,
|
|
283
287
|
) -> dict[str, Any]:
|
|
284
288
|
"""
|
|
285
|
-
Deletes a specified range of rows or columns
|
|
286
|
-
|
|
289
|
+
Deletes a specified range of rows or columns, permanently removing them and shifting subsequent cells. This alters the sheet's structure, unlike `clear_values` which only removes cell content. It is the direct counterpart to `insert_dimensions`, which adds space within the data grid.
|
|
290
|
+
|
|
287
291
|
Args:
|
|
288
|
-
|
|
292
|
+
spreadsheetId: The ID of the spreadsheet. Example: "abc123xyz789"
|
|
289
293
|
sheet_id: The ID of the sheet from which to delete the dimension. Example: 0 for first sheet
|
|
290
294
|
dimension: The dimension to delete. Example: "ROWS"
|
|
291
295
|
start_index: The zero-based start index of the range to delete, inclusive. The start index must be less than the end index. Example: 0
|
|
@@ -293,19 +297,19 @@ class GoogleSheetApp(APIApplication):
|
|
|
293
297
|
include_spreadsheet_in_response: Determines if the update response should include the spreadsheet resource. Example: True
|
|
294
298
|
response_include_grid_data: True if grid data should be returned. This parameter is ignored if a field mask was set in the request. Example: True
|
|
295
299
|
response_ranges: Limits the ranges of cells included in the response spreadsheet. Example: ["Sheet1!A1:B2", "Sheet2!C:C"]
|
|
296
|
-
|
|
300
|
+
|
|
297
301
|
Returns:
|
|
298
302
|
A dictionary containing the Google Sheets API response with update details
|
|
299
|
-
|
|
303
|
+
|
|
300
304
|
Raises:
|
|
301
305
|
HTTPError: When the API request fails due to invalid parameters or insufficient permissions
|
|
302
|
-
ValueError: When
|
|
303
|
-
|
|
306
|
+
ValueError: When spreadsheetId is empty, dimension is not "ROWS" or "COLUMNS", or indices are invalid
|
|
307
|
+
|
|
304
308
|
Tags:
|
|
305
309
|
delete, modify, spreadsheet, rows, columns, dimensions, important
|
|
306
310
|
"""
|
|
307
|
-
if not
|
|
308
|
-
raise ValueError("
|
|
311
|
+
if not spreadsheetId:
|
|
312
|
+
raise ValueError("spreadsheetId cannot be empty")
|
|
309
313
|
|
|
310
314
|
if dimension not in ["ROWS", "COLUMNS"]:
|
|
311
315
|
raise ValueError('dimension must be either "ROWS" or "COLUMNS"')
|
|
@@ -316,7 +320,7 @@ class GoogleSheetApp(APIApplication):
|
|
|
316
320
|
if start_index >= end_index:
|
|
317
321
|
raise ValueError("end_index must be greater than start_index")
|
|
318
322
|
|
|
319
|
-
url = f"{self.base_url}/{
|
|
323
|
+
url = f"{self.base_url}/{spreadsheetId}:batchUpdate"
|
|
320
324
|
|
|
321
325
|
request_body: dict[str, Any] = {
|
|
322
326
|
"requests": [
|
|
@@ -371,8 +375,8 @@ class GoogleSheetApp(APIApplication):
|
|
|
371
375
|
responseIncludeGridData: bool = False,
|
|
372
376
|
) -> dict[str, Any]:
|
|
373
377
|
"""
|
|
374
|
-
Adds a new worksheet (tab) to an existing Google Spreadsheet.
|
|
375
|
-
|
|
378
|
+
Adds a new worksheet (tab) to an existing Google Spreadsheet. It allows extensive customization of the new sheet's properties, such as its title, position, and dimensions. This is distinct from `create_spreadsheet`, which generates a completely new spreadsheet file instead of modifying an existing one.
|
|
379
|
+
|
|
376
380
|
Args:
|
|
377
381
|
spreadsheetId: The ID of the spreadsheet to add the sheet to. This is the long string of characters in the URL of your Google Sheet. Example: "abc123xyz789"
|
|
378
382
|
title: The name of the sheet. Example: "Q3 Report"
|
|
@@ -391,14 +395,14 @@ class GoogleSheetApp(APIApplication):
|
|
|
391
395
|
columnGroupControlAfter: True if the column group control toggle is shown after the group, false if before.
|
|
392
396
|
includeSpreadsheetInResponse: Whether the response should include the entire spreadsheet resource. Defaults to false.
|
|
393
397
|
responseIncludeGridData: True if grid data should be returned. This parameter is ignored if includeSpreadsheetInResponse is false. Defaults to false.
|
|
394
|
-
|
|
398
|
+
|
|
395
399
|
Returns:
|
|
396
400
|
A dictionary containing the Google Sheets API response with the new sheet details
|
|
397
|
-
|
|
401
|
+
|
|
398
402
|
Raises:
|
|
399
403
|
HTTPError: When the API request fails due to invalid parameters or insufficient permissions
|
|
400
|
-
ValueError: When
|
|
401
|
-
|
|
404
|
+
ValueError: When spreadsheetId is empty or invalid parameters are provided
|
|
405
|
+
|
|
402
406
|
Tags:
|
|
403
407
|
add, sheet, spreadsheet, create
|
|
404
408
|
"""
|
|
@@ -479,7 +483,7 @@ class GoogleSheetApp(APIApplication):
|
|
|
479
483
|
|
|
480
484
|
def add_basic_chart(
|
|
481
485
|
self,
|
|
482
|
-
|
|
486
|
+
spreadsheetId: str,
|
|
483
487
|
source_sheet_id: int,
|
|
484
488
|
chart_title: str,
|
|
485
489
|
chart_type: str,
|
|
@@ -492,12 +496,12 @@ class GoogleSheetApp(APIApplication):
|
|
|
492
496
|
) -> dict[str, Any]:
|
|
493
497
|
"""
|
|
494
498
|
Adds various axis-based charts (e.g., column, bar, line, area) to a spreadsheet from specified data ranges. The chart can be placed on a new sheet or positioned on an existing one. This is distinct from `add_pie_chart`, which creates proportional visualizations instead of axis-based charts.
|
|
495
|
-
|
|
499
|
+
|
|
496
500
|
This function creates various types of charts from the specified data ranges and places it in a new sheet or existing sheet.
|
|
497
501
|
Use this when you need to visualize data in different chart formats.
|
|
498
|
-
|
|
502
|
+
|
|
499
503
|
Args:
|
|
500
|
-
|
|
504
|
+
spreadsheetId: The unique identifier of the Google Spreadsheet to modify
|
|
501
505
|
source_sheet_id: The ID of the sheet containing the source data
|
|
502
506
|
chart_title: The title for the chart
|
|
503
507
|
chart_type: The type of chart to create. Supported types: "COLUMN", "BAR", "LINE", "AREA", "STEPPED_AREA", "SCATTER", "COMBO"
|
|
@@ -507,24 +511,24 @@ class GoogleSheetApp(APIApplication):
|
|
|
507
511
|
chart_position: Optional positioning for chart when new_sheet=False. Example: {"overlayPosition": {"anchorCell": {"sheetId": 0, "rowIndex": 10, "columnIndex": 5}, "offsetXPixels": 0, "offsetYPixels": 0, "widthPixels": 600, "heightPixels": 400}}
|
|
508
512
|
x_axis_title: Optional title for the X-axis (bottom axis). If not provided, defaults to "Categories"
|
|
509
513
|
y_axis_title: Optional title for the Y-axis (left axis). If not provided, defaults to "Values"
|
|
510
|
-
|
|
514
|
+
|
|
511
515
|
Returns:
|
|
512
516
|
A dictionary containing the Google Sheets API response with the chart details
|
|
513
|
-
|
|
517
|
+
|
|
514
518
|
Raises:
|
|
515
519
|
HTTPError: When the API request fails due to invalid parameters or insufficient permissions
|
|
516
|
-
ValueError: When
|
|
517
|
-
|
|
520
|
+
ValueError: When spreadsheetId is empty or invalid parameters are provided
|
|
521
|
+
|
|
518
522
|
Tags:
|
|
519
523
|
add, chart, basic-chart, visualization
|
|
520
524
|
"""
|
|
521
|
-
if not
|
|
522
|
-
raise ValueError("
|
|
525
|
+
if not spreadsheetId:
|
|
526
|
+
raise ValueError("spreadsheetId cannot be empty")
|
|
523
527
|
|
|
524
528
|
if not chart_title:
|
|
525
529
|
raise ValueError("chart_title cannot be empty")
|
|
526
530
|
|
|
527
|
-
url = f"{self.base_url}/{
|
|
531
|
+
url = f"{self.base_url}/{spreadsheetId}:batchUpdate"
|
|
528
532
|
|
|
529
533
|
# Build the chart specification
|
|
530
534
|
chart_spec = {
|
|
@@ -628,7 +632,7 @@ class GoogleSheetApp(APIApplication):
|
|
|
628
632
|
|
|
629
633
|
def add_pie_chart(
|
|
630
634
|
self,
|
|
631
|
-
|
|
635
|
+
spreadsheetId: str,
|
|
632
636
|
source_sheet_id: int,
|
|
633
637
|
chart_title: str,
|
|
634
638
|
data_range: dict,
|
|
@@ -638,13 +642,13 @@ class GoogleSheetApp(APIApplication):
|
|
|
638
642
|
pie_hole: float | None = None,
|
|
639
643
|
) -> dict[str, Any]:
|
|
640
644
|
"""
|
|
641
|
-
Adds a pie or donut chart to a Google Spreadsheet from a specified data range. Unlike the more general `add_basic_chart`, this
|
|
642
|
-
|
|
645
|
+
Adds a pie or donut chart to a Google Spreadsheet from a specified data range. Unlike the more general `add_basic_chart`, this is specialized for visualizing data as proportions of a whole and supports pie-specific options like creating a donut chart via the `pie_hole` parameter.
|
|
646
|
+
|
|
643
647
|
This function creates a pie chart from the specified data range and places it in a new sheet or existing sheet.
|
|
644
648
|
Use this when you need to visualize data as proportions of a whole.
|
|
645
|
-
|
|
649
|
+
|
|
646
650
|
Args:
|
|
647
|
-
|
|
651
|
+
spreadsheetId: The unique identifier of the Google Spreadsheet to modify
|
|
648
652
|
source_sheet_id: The ID of the sheet containing the source data
|
|
649
653
|
chart_title: The title for the chart
|
|
650
654
|
data_range: Dictionary containing data range info (e.g., {"startRowIndex": 0, "endRowIndex": 7, "startColumnIndex": 0, "endColumnIndex": 2})
|
|
@@ -652,19 +656,19 @@ class GoogleSheetApp(APIApplication):
|
|
|
652
656
|
chart_position: Optional positioning for chart when new_sheet=False. Example: {"overlayPosition": {"anchorCell": {"sheetId": 0, "rowIndex": 10, "columnIndex": 5}, "offsetXPixels": 0, "offsetYPixels": 0, "widthPixels": 600, "heightPixels": 400}}
|
|
653
657
|
legend_position: Position of the legend. Options: "BOTTOM_LEGEND", "LEFT_LEGEND", "RIGHT_LEGEND", "TOP_LEGEND", "NO_LEGEND"
|
|
654
658
|
pie_hole: Optional hole size for creating a donut chart (0.0 to 1.0). 0.0 = solid pie, 0.5 = 50% hole
|
|
655
|
-
|
|
659
|
+
|
|
656
660
|
Returns:
|
|
657
661
|
A dictionary containing the Google Sheets API response with the chart details
|
|
658
|
-
|
|
662
|
+
|
|
659
663
|
Raises:
|
|
660
664
|
HTTPError: When the API request fails due to invalid parameters or insufficient permissions
|
|
661
|
-
ValueError: When
|
|
662
|
-
|
|
665
|
+
ValueError: When spreadsheetId is empty or invalid parameters are provided
|
|
666
|
+
|
|
663
667
|
Tags:
|
|
664
668
|
add, chart, pie, visualization
|
|
665
669
|
"""
|
|
666
|
-
if not
|
|
667
|
-
raise ValueError("
|
|
670
|
+
if not spreadsheetId:
|
|
671
|
+
raise ValueError("spreadsheetId cannot be empty")
|
|
668
672
|
|
|
669
673
|
if not chart_title:
|
|
670
674
|
raise ValueError("chart_title cannot be empty")
|
|
@@ -672,7 +676,7 @@ class GoogleSheetApp(APIApplication):
|
|
|
672
676
|
if pie_hole is not None and not 0 <= pie_hole <= 1:
|
|
673
677
|
raise ValueError("pie_hole must be between 0.0 and 1.0")
|
|
674
678
|
|
|
675
|
-
url = f"{self.base_url}/{
|
|
679
|
+
url = f"{self.base_url}/{spreadsheetId}:batchUpdate"
|
|
676
680
|
|
|
677
681
|
# Build the pie chart specification
|
|
678
682
|
pie_chart_spec = {
|
|
@@ -747,7 +751,7 @@ class GoogleSheetApp(APIApplication):
|
|
|
747
751
|
|
|
748
752
|
def add_table(
|
|
749
753
|
self,
|
|
750
|
-
|
|
754
|
+
spreadsheetId: str,
|
|
751
755
|
sheet_id: int,
|
|
752
756
|
table_name: str,
|
|
753
757
|
table_id: str,
|
|
@@ -759,12 +763,12 @@ class GoogleSheetApp(APIApplication):
|
|
|
759
763
|
) -> dict[str, Any]:
|
|
760
764
|
"""
|
|
761
765
|
Creates a structured table within a specified range on a Google Sheet. Defines the table's name, ID, and dimensions, and can optionally configure column properties like data types and validation rules. This action creates a formal table object, distinct from functions that only write cell values.
|
|
762
|
-
|
|
766
|
+
|
|
763
767
|
This function creates a table with specified properties and column types.
|
|
764
768
|
Use this when you need to create structured data with headers, footers, and column types.
|
|
765
|
-
|
|
769
|
+
|
|
766
770
|
Args:
|
|
767
|
-
|
|
771
|
+
spreadsheetId: The unique identifier of the Google Spreadsheet to modify
|
|
768
772
|
sheet_id: The ID of the sheet where the table will be created
|
|
769
773
|
table_name: The name of the table
|
|
770
774
|
table_id: The unique identifier for the table
|
|
@@ -775,16 +779,16 @@ class GoogleSheetApp(APIApplication):
|
|
|
775
779
|
column_properties: Optional list of column properties with types and validation rules. Valid column types: "TEXT", "PERCENT", "DROPDOWN", "DOUBLE", "CURRENCY", "DATE", "TIME", "DATE_TIME". Example: [{"columnIndex": 0, "columnName": "Model Number", "columnType": "TEXT"}, {"columnIndex": 1, "columnName": "Sales - Jan", "columnType": "DOUBLE"}, {"columnIndex": 2, "columnName": "Price", "columnType": "CURRENCY"}, {"columnIndex": 3, "columnName": "Progress", "columnType": "PERCENT"}, {"columnIndex": 4, "columnName": "Created Date", "columnType": "DATE"}, {"columnIndex": 5, "columnName": "Status", "columnType": "DROPDOWN", "dataValidationRule": {"condition": {"type": "ONE_OF_LIST", "values": [{"userEnteredValue": "Active"}, {"userEnteredValue": "Inactive"}]}}}]
|
|
776
780
|
Returns:
|
|
777
781
|
A dictionary containing the Google Sheets API response with the table details
|
|
778
|
-
|
|
782
|
+
|
|
779
783
|
Raises:
|
|
780
784
|
HTTPError: When the API request fails due to invalid parameters or insufficient permissions
|
|
781
|
-
ValueError: When
|
|
782
|
-
|
|
785
|
+
ValueError: When spreadsheetId is empty or invalid parameters are provided
|
|
786
|
+
|
|
783
787
|
Tags:
|
|
784
788
|
add, table, structured-data
|
|
785
789
|
"""
|
|
786
|
-
if not
|
|
787
|
-
raise ValueError("
|
|
790
|
+
if not spreadsheetId:
|
|
791
|
+
raise ValueError("spreadsheetId cannot be empty")
|
|
788
792
|
|
|
789
793
|
if not table_name:
|
|
790
794
|
raise ValueError("table_name cannot be empty")
|
|
@@ -827,7 +831,7 @@ class GoogleSheetApp(APIApplication):
|
|
|
827
831
|
f"Invalid column type '{prop['columnType']}' at index {i}. Valid types are: {', '.join(valid_column_types)}"
|
|
828
832
|
)
|
|
829
833
|
|
|
830
|
-
url = f"{self.base_url}/{
|
|
834
|
+
url = f"{self.base_url}/{spreadsheetId}:batchUpdate"
|
|
831
835
|
|
|
832
836
|
# Build the table specification
|
|
833
837
|
table_spec = {
|
|
@@ -854,7 +858,7 @@ class GoogleSheetApp(APIApplication):
|
|
|
854
858
|
|
|
855
859
|
def update_table(
|
|
856
860
|
self,
|
|
857
|
-
|
|
861
|
+
spreadsheetId: str,
|
|
858
862
|
table_id: str,
|
|
859
863
|
table_name: str | None = None,
|
|
860
864
|
start_row_index: int | None = None,
|
|
@@ -865,12 +869,12 @@ class GoogleSheetApp(APIApplication):
|
|
|
865
869
|
) -> dict[str, Any]:
|
|
866
870
|
"""
|
|
867
871
|
Modifies properties of an existing table within a Google Sheet, such as its name, data range, or column specifications. This function updates the table's structural metadata, distinguishing it from `update_values` which alters the cell data within the table's range.
|
|
868
|
-
|
|
872
|
+
|
|
869
873
|
This function modifies table properties such as name, range, and column properties.
|
|
870
874
|
Use this when you need to modify an existing table's structure or properties.
|
|
871
|
-
|
|
875
|
+
|
|
872
876
|
Args:
|
|
873
|
-
|
|
877
|
+
spreadsheetId: The unique identifier of the Google Spreadsheet to modify
|
|
874
878
|
table_id: The unique identifier of the table to update
|
|
875
879
|
table_name: Optional new name for the table
|
|
876
880
|
start_row_index: Optional new starting row index (0-based)
|
|
@@ -878,19 +882,19 @@ class GoogleSheetApp(APIApplication):
|
|
|
878
882
|
start_column_index: Optional new starting column index (0-based)
|
|
879
883
|
end_column_index: Optional new ending column index (exclusive)
|
|
880
884
|
column_properties: Optional list of column properties with types and validation rules. Valid column types: "TEXT", "PERCENT", "DROPDOWN", "DOUBLE", "CURRENCY", "DATE", "TIME", "DATE_TIME". Example: [{"columnIndex": 0, "columnName": "Model Number", "columnType": "TEXT"}, {"columnIndex": 1, "columnName": "Sales - Jan", "columnType": "DOUBLE"}, {"columnIndex": 2, "columnName": "Price", "columnType": "CURRENCY"}, {"columnIndex": 3, "columnName": "Progress", "columnType": "PERCENT"}, {"columnIndex": 4, "columnName": "Created Date", "columnType": "DATE"}, {"columnIndex": 5, "columnName": "Status", "columnType": "DROPDOWN", "dataValidationRule": {"condition": {"type": "ONE_OF_LIST", "values": [{"userEnteredValue": "Active"}, {"userEnteredValue": "Inactive"}]}}}]
|
|
881
|
-
|
|
885
|
+
|
|
882
886
|
Returns:
|
|
883
887
|
A dictionary containing the Google Sheets API response with the updated table details
|
|
884
|
-
|
|
888
|
+
|
|
885
889
|
Raises:
|
|
886
890
|
HTTPError: When the API request fails due to invalid parameters or insufficient permissions
|
|
887
|
-
ValueError: When
|
|
888
|
-
|
|
891
|
+
ValueError: When spreadsheetId or table_id is empty or invalid parameters are provided
|
|
892
|
+
|
|
889
893
|
Tags:
|
|
890
894
|
update, table, modify, structured-data
|
|
891
895
|
"""
|
|
892
|
-
if not
|
|
893
|
-
raise ValueError("
|
|
896
|
+
if not spreadsheetId:
|
|
897
|
+
raise ValueError("spreadsheetId cannot be empty")
|
|
894
898
|
|
|
895
899
|
if not table_id:
|
|
896
900
|
raise ValueError("table_id cannot be empty")
|
|
@@ -943,7 +947,7 @@ class GoogleSheetApp(APIApplication):
|
|
|
943
947
|
f"Invalid column type '{prop['columnType']}' at index {i}. Valid types are: {', '.join(valid_column_types)}"
|
|
944
948
|
)
|
|
945
949
|
|
|
946
|
-
url = f"{self.base_url}/{
|
|
950
|
+
url = f"{self.base_url}/{spreadsheetId}:batchUpdate"
|
|
947
951
|
|
|
948
952
|
# Build the table specification and track fields to update
|
|
949
953
|
table_spec: dict[str, Any] = {"tableId": table_id}
|
|
@@ -995,55 +999,55 @@ class GoogleSheetApp(APIApplication):
|
|
|
995
999
|
response = self._post(url, data=request_body)
|
|
996
1000
|
return self._handle_response(response)
|
|
997
1001
|
|
|
998
|
-
def clear_values(self,
|
|
1002
|
+
def clear_values(self, spreadsheetId: str, range: str) -> dict[str, Any]:
|
|
999
1003
|
"""
|
|
1000
|
-
Clears data from a single, specified cell range
|
|
1001
|
-
|
|
1004
|
+
Clears data from a single, specified cell range while preserving all formatting. Unlike `delete_dimensions`, it only removes content, not the cells themselves. For clearing multiple ranges simultaneously, use the `batch_clear_values` function.
|
|
1005
|
+
|
|
1002
1006
|
Args:
|
|
1003
|
-
|
|
1007
|
+
spreadsheetId: The unique identifier of the Google Spreadsheet to modify
|
|
1004
1008
|
range: The A1 or R1C1 notation range of cells to clear (e.g., 'Sheet1!A1:B2')
|
|
1005
|
-
|
|
1009
|
+
|
|
1006
1010
|
Returns:
|
|
1007
1011
|
A dictionary containing the Google Sheets API response
|
|
1008
|
-
|
|
1012
|
+
|
|
1009
1013
|
Raises:
|
|
1010
|
-
HttpError: When the API request fails due to invalid
|
|
1011
|
-
ValueError: When
|
|
1012
|
-
|
|
1014
|
+
HttpError: When the API request fails due to invalid spreadsheetId, invalid range format, or insufficient permissions
|
|
1015
|
+
ValueError: When spreadsheetId is empty or range is in invalid format
|
|
1016
|
+
|
|
1013
1017
|
Tags:
|
|
1014
1018
|
clear, modify, spreadsheet, api, sheets, data-management, important
|
|
1015
1019
|
"""
|
|
1016
|
-
url = f"{self.base_url}/{
|
|
1020
|
+
url = f"{self.base_url}/{spreadsheetId}/values/{range}:clear"
|
|
1017
1021
|
response = self._post(url, data={})
|
|
1018
1022
|
return self._handle_response(response)
|
|
1019
1023
|
|
|
1020
1024
|
def update_values(
|
|
1021
1025
|
self,
|
|
1022
|
-
|
|
1026
|
+
spreadsheetId: str,
|
|
1023
1027
|
range: str,
|
|
1024
1028
|
values: list[list[Any]],
|
|
1025
1029
|
value_input_option: str = "RAW",
|
|
1026
1030
|
) -> dict[str, Any]:
|
|
1027
1031
|
"""
|
|
1028
|
-
Overwrites cell values within a specific A1 notation range
|
|
1029
|
-
|
|
1032
|
+
Overwrites cell values within a specific A1 notation range using a provided 2D list. This function replaces existing data in a predefined area, distinguishing it from `append_values`, which adds new rows after a table instead of overwriting a specific block of cells.
|
|
1033
|
+
|
|
1030
1034
|
Args:
|
|
1031
|
-
|
|
1035
|
+
spreadsheetId: The unique identifier of the target Google Spreadsheet
|
|
1032
1036
|
range: The A1 notation range where values will be updated (e.g., 'Sheet1!A1:B2')
|
|
1033
1037
|
values: A list of lists containing the data to write, where each inner list represents a row of values
|
|
1034
1038
|
value_input_option: Determines how input data should be interpreted: 'RAW' (as-is) or 'USER_ENTERED' (parsed as UI input). Defaults to 'RAW'
|
|
1035
|
-
|
|
1039
|
+
|
|
1036
1040
|
Returns:
|
|
1037
1041
|
A dictionary containing the Google Sheets API response with update details
|
|
1038
|
-
|
|
1042
|
+
|
|
1039
1043
|
Raises:
|
|
1040
1044
|
RequestError: When the API request fails due to invalid parameters or network issues
|
|
1041
1045
|
AuthenticationError: When authentication with the Google Sheets API fails
|
|
1042
|
-
|
|
1046
|
+
|
|
1043
1047
|
Tags:
|
|
1044
1048
|
update, write, sheets, api, important, data-modification, google-sheets
|
|
1045
1049
|
"""
|
|
1046
|
-
url = f"{self.base_url}/{
|
|
1050
|
+
url = f"{self.base_url}/{spreadsheetId}/values/{range}"
|
|
1047
1051
|
params = {"valueInputOption": value_input_option}
|
|
1048
1052
|
data = {"range": range, "values": values}
|
|
1049
1053
|
response = self._put(url, data=data, params=params)
|
|
@@ -1051,33 +1055,33 @@ class GoogleSheetApp(APIApplication):
|
|
|
1051
1055
|
|
|
1052
1056
|
def batch_clear_values(
|
|
1053
1057
|
self,
|
|
1054
|
-
|
|
1058
|
+
spreadsheetId: str,
|
|
1055
1059
|
ranges: list[str],
|
|
1056
1060
|
) -> dict[str, Any]:
|
|
1057
1061
|
"""
|
|
1058
1062
|
Clears cell values from multiple specified ranges in a single batch operation, preserving existing formatting. Unlike `clear_values`, which handles a single range, this method efficiently processes a list of ranges at once, removing only the content and not the cells themselves.
|
|
1059
|
-
|
|
1063
|
+
|
|
1060
1064
|
Args:
|
|
1061
|
-
|
|
1065
|
+
spreadsheetId: The ID of the spreadsheet to update. Example: "1q2w3e4r5t6y7u8i9o0p"
|
|
1062
1066
|
ranges: The ranges to clear, in A1 notation or R1C1 notation. Example: ["Sheet1!A1:B2", "Sheet1!C3:D4"]
|
|
1063
|
-
|
|
1067
|
+
|
|
1064
1068
|
Returns:
|
|
1065
1069
|
A dictionary containing the Google Sheets API response with clear details
|
|
1066
|
-
|
|
1070
|
+
|
|
1067
1071
|
Raises:
|
|
1068
1072
|
HTTPError: When the API request fails due to invalid parameters or insufficient permissions
|
|
1069
|
-
ValueError: When
|
|
1070
|
-
|
|
1073
|
+
ValueError: When spreadsheetId is empty or ranges is empty
|
|
1074
|
+
|
|
1071
1075
|
Tags:
|
|
1072
1076
|
clear, batch, values, spreadsheet
|
|
1073
1077
|
"""
|
|
1074
|
-
if not
|
|
1075
|
-
raise ValueError("
|
|
1078
|
+
if not spreadsheetId:
|
|
1079
|
+
raise ValueError("spreadsheetId cannot be empty")
|
|
1076
1080
|
|
|
1077
1081
|
if not ranges or not isinstance(ranges, list) or len(ranges) == 0:
|
|
1078
1082
|
raise ValueError("ranges must be a non-empty list")
|
|
1079
1083
|
|
|
1080
|
-
url = f"{self.base_url}/{
|
|
1084
|
+
url = f"{self.base_url}/{spreadsheetId}/values:batchClear"
|
|
1081
1085
|
|
|
1082
1086
|
request_body = {"ranges": ranges}
|
|
1083
1087
|
|
|
@@ -1086,36 +1090,36 @@ class GoogleSheetApp(APIApplication):
|
|
|
1086
1090
|
|
|
1087
1091
|
def batch_get_values_by_data_filter(
|
|
1088
1092
|
self,
|
|
1089
|
-
|
|
1093
|
+
spreadsheetId: str,
|
|
1090
1094
|
data_filters: list[dict],
|
|
1091
1095
|
major_dimension: str | None = None,
|
|
1092
1096
|
value_render_option: str | None = None,
|
|
1093
1097
|
date_time_render_option: str | None = None,
|
|
1094
1098
|
) -> dict[str, Any]:
|
|
1095
1099
|
"""
|
|
1096
|
-
Retrieves values from spreadsheet ranges matching a list of data filters. This method provides dynamic, criteria-based selection using A1 notation or grid coordinates, unlike `
|
|
1097
|
-
|
|
1100
|
+
Retrieves values from spreadsheet ranges matching a list of data filters. This method provides dynamic, criteria-based selection using A1 notation or grid coordinates, unlike `batch_get_values_by_range` which uses a simple list of range strings. It is ideal for fetching multiple, specific datasets in one request.
|
|
1101
|
+
|
|
1098
1102
|
Args:
|
|
1099
|
-
|
|
1103
|
+
spreadsheetId: The ID of the spreadsheet to retrieve data from. Example: "1q2w3e4r5t6y7u8i9o0p"
|
|
1100
1104
|
data_filters: The data filters used to match the ranges of values to retrieve. Ranges that match any of the specified data filters are included in the response. Each filter can contain:
|
|
1101
1105
|
- a1Range: Selects data that matches the specified A1 range. Example: "Sheet1!A1:B5"
|
|
1102
1106
|
- gridRange: Selects data that matches the specified grid range. Example: {"sheetId": 0, "startRowIndex": 0, "endRowIndex": 5, "startColumnIndex": 0, "endColumnIndex": 2}
|
|
1103
1107
|
major_dimension: The major dimension that results should use. For example, if the spreadsheet data is: A1=1,B1=2,A2=3,B2=4, then a request that selects that range and sets majorDimension=ROWS returns [[1,2],[3,4]], whereas a request that sets majorDimension=COLUMNS returns [[1,3],[2,4]]. Options: "ROWS" or "COLUMNS". Example: "ROWS"
|
|
1104
1108
|
value_render_option: How values should be represented in the output. The default render option is FORMATTED_VALUE. Options: "FORMATTED_VALUE", "UNFORMATTED_VALUE", or "FORMULA". Example: "FORMATTED_VALUE"
|
|
1105
1109
|
date_time_render_option: How dates, times, and durations should be represented in the output. This is ignored if valueRenderOption is FORMATTED_VALUE. The default dateTime render option is SERIAL_NUMBER. Options: "SERIAL_NUMBER" or "FORMATTED_STRING". Example: "SERIAL_NUMBER"
|
|
1106
|
-
|
|
1110
|
+
|
|
1107
1111
|
Returns:
|
|
1108
1112
|
A dictionary containing the filtered values that match the specified data filters
|
|
1109
|
-
|
|
1113
|
+
|
|
1110
1114
|
Raises:
|
|
1111
1115
|
HTTPError: When the API request fails due to invalid parameters or insufficient permissions
|
|
1112
|
-
ValueError: When
|
|
1113
|
-
|
|
1116
|
+
ValueError: When spreadsheetId is empty or data_filters is empty
|
|
1117
|
+
|
|
1114
1118
|
Tags:
|
|
1115
1119
|
get, batch, data-filter, values, spreadsheet
|
|
1116
1120
|
"""
|
|
1117
|
-
if not
|
|
1118
|
-
raise ValueError("
|
|
1121
|
+
if not spreadsheetId:
|
|
1122
|
+
raise ValueError("spreadsheetId cannot be empty")
|
|
1119
1123
|
|
|
1120
1124
|
if (
|
|
1121
1125
|
not data_filters
|
|
@@ -1144,7 +1148,7 @@ class GoogleSheetApp(APIApplication):
|
|
|
1144
1148
|
'date_time_render_option must be either "SERIAL_NUMBER" or "FORMATTED_STRING"'
|
|
1145
1149
|
)
|
|
1146
1150
|
|
|
1147
|
-
url = f"{self.base_url}/{
|
|
1151
|
+
url = f"{self.base_url}/{spreadsheetId}/values:batchGetByDataFilter"
|
|
1148
1152
|
|
|
1149
1153
|
request_body: dict[str, Any] = {"dataFilters": data_filters}
|
|
1150
1154
|
|
|
@@ -1163,48 +1167,48 @@ class GoogleSheetApp(APIApplication):
|
|
|
1163
1167
|
|
|
1164
1168
|
def copy_sheet_to_spreadsheet(
|
|
1165
1169
|
self,
|
|
1166
|
-
|
|
1170
|
+
spreadsheetId: str,
|
|
1167
1171
|
sheet_id: int,
|
|
1168
|
-
|
|
1172
|
+
destination_spreadsheetId: str,
|
|
1169
1173
|
) -> dict[str, Any]:
|
|
1170
1174
|
"""
|
|
1171
|
-
Copies a specific sheet, including all its data and formatting, from a source spreadsheet to a different destination spreadsheet. This action duplicates an entire worksheet into another workbook, returning
|
|
1172
|
-
|
|
1173
|
-
|
|
1175
|
+
Copies a specific sheet, including all its data and formatting, from a source spreadsheet to a different destination spreadsheet. This action duplicates an entire worksheet into another workbook, returning properties of the newly created sheet.
|
|
1176
|
+
|
|
1177
|
+
|
|
1174
1178
|
Args:
|
|
1175
|
-
|
|
1179
|
+
spreadsheetId: The ID of the spreadsheet containing the sheet to copy. Example: "1qZ_..."
|
|
1176
1180
|
sheet_id: The ID of the sheet to copy. Example: 0
|
|
1177
|
-
|
|
1178
|
-
|
|
1181
|
+
destination_spreadsheetId: The ID of the spreadsheet to copy the sheet to. Example: "2rY_..."
|
|
1182
|
+
|
|
1179
1183
|
Returns:
|
|
1180
1184
|
A dictionary containing the Google Sheets API response with copy details
|
|
1181
|
-
|
|
1185
|
+
|
|
1182
1186
|
Raises:
|
|
1183
1187
|
HTTPError: When the API request fails due to invalid parameters or insufficient permissions
|
|
1184
1188
|
ValueError: When any required parameter is empty or invalid
|
|
1185
|
-
|
|
1189
|
+
|
|
1186
1190
|
Tags:
|
|
1187
1191
|
copy, sheet, spreadsheet, duplicate
|
|
1188
1192
|
"""
|
|
1189
|
-
if not
|
|
1190
|
-
raise ValueError("
|
|
1193
|
+
if not spreadsheetId:
|
|
1194
|
+
raise ValueError("spreadsheetId cannot be empty")
|
|
1191
1195
|
|
|
1192
1196
|
if sheet_id is None:
|
|
1193
1197
|
raise ValueError("sheet_id cannot be empty")
|
|
1194
1198
|
|
|
1195
|
-
if not
|
|
1196
|
-
raise ValueError("
|
|
1199
|
+
if not destination_spreadsheetId:
|
|
1200
|
+
raise ValueError("destination_spreadsheetId cannot be empty")
|
|
1197
1201
|
|
|
1198
|
-
url = f"{self.base_url}/{
|
|
1202
|
+
url = f"{self.base_url}/{spreadsheetId}/sheets/{sheet_id}:copyTo"
|
|
1199
1203
|
|
|
1200
|
-
request_body = {"destinationSpreadsheetId":
|
|
1204
|
+
request_body = {"destinationSpreadsheetId": destination_spreadsheetId}
|
|
1201
1205
|
|
|
1202
1206
|
response = self._post(url, data=request_body)
|
|
1203
1207
|
return self._handle_response(response)
|
|
1204
1208
|
|
|
1205
1209
|
def write_values_to_sheet(
|
|
1206
1210
|
self,
|
|
1207
|
-
|
|
1211
|
+
spreadsheetId: str,
|
|
1208
1212
|
sheet_name: str,
|
|
1209
1213
|
values: list[list[Any]],
|
|
1210
1214
|
first_cell_location: str | None = None,
|
|
@@ -1212,28 +1216,28 @@ class GoogleSheetApp(APIApplication):
|
|
|
1212
1216
|
include_values_in_response: bool = False,
|
|
1213
1217
|
) -> dict[str, Any]:
|
|
1214
1218
|
"""
|
|
1215
|
-
Writes a 2D list of values to a sheet, overwriting existing data. Data is written starting from a specified cell, or defaults to cell A1 if no location is provided. This differs from `append_values`, which adds new rows after existing data.
|
|
1216
|
-
|
|
1219
|
+
Writes a 2D list of values to a sheet, overwriting existing data. Data is written starting from a specified cell, or defaults to cell A1 if no location is provided. This differs from `append_values`, which adds new rows after existing data without replacing content.
|
|
1220
|
+
|
|
1217
1221
|
Args:
|
|
1218
|
-
|
|
1222
|
+
spreadsheetId: The unique identifier of the Google Sheets spreadsheet to be updated. Example: "1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms"
|
|
1219
1223
|
sheet_name: The name of the specific sheet within the spreadsheet to update. Example: "Sheet1"
|
|
1220
1224
|
values: A 2D list of cell values. Each inner list represents a row. Values can be strings, numbers, or booleans. Ensure columns are properly aligned across rows. Example: [['Item', 'Cost', 'Stocked', 'Ship Date'], ['Wheel', 20.5, True, '2020-06-01'], ['Screw', 0.5, True, '2020-06-03'], ['Nut', 0.25, False, '2020-06-02']]
|
|
1221
1225
|
first_cell_location: The starting cell for the update range, specified in A1 notation (e.g., 'A1', 'B2'). The update will extend from this cell to the right and down, based on the provided values. If omitted, values are appended to the end of the sheet. Example: "A1"
|
|
1222
1226
|
value_input_option: How input data is interpreted. 'USER_ENTERED': Values parsed as if typed by a user (e.g., strings may become numbers/dates, formulas are calculated); recommended for formulas. 'RAW': Values stored as-is without parsing (e.g., '123' stays string, '=SUM(A1:B1)' stays string). Defaults to 'USER_ENTERED'. Example: "USER_ENTERED"
|
|
1223
1227
|
include_values_in_response: If set to True, the response will include the updated values from the spreadsheet. Defaults to False. Example: True
|
|
1224
|
-
|
|
1228
|
+
|
|
1225
1229
|
Returns:
|
|
1226
1230
|
A dictionary containing the Google Sheets API response with update details
|
|
1227
|
-
|
|
1231
|
+
|
|
1228
1232
|
Raises:
|
|
1229
1233
|
HTTPError: When the API request fails due to invalid parameters or insufficient permissions
|
|
1230
|
-
ValueError: When
|
|
1231
|
-
|
|
1234
|
+
ValueError: When spreadsheetId is empty, sheet_name is empty, or values is empty
|
|
1235
|
+
|
|
1232
1236
|
Tags:
|
|
1233
1237
|
batch, update, write, sheets, api, important, data-modification, google-sheets
|
|
1234
1238
|
"""
|
|
1235
|
-
if not
|
|
1236
|
-
raise ValueError("
|
|
1239
|
+
if not spreadsheetId:
|
|
1240
|
+
raise ValueError("spreadsheetId cannot be empty")
|
|
1237
1241
|
|
|
1238
1242
|
if not sheet_name:
|
|
1239
1243
|
raise ValueError("sheet_name cannot be empty")
|
|
@@ -1254,7 +1258,7 @@ class GoogleSheetApp(APIApplication):
|
|
|
1254
1258
|
# Append to the sheet (no specific range)
|
|
1255
1259
|
range_str = f"{sheet_name}"
|
|
1256
1260
|
|
|
1257
|
-
url = f"{self.base_url}/{
|
|
1261
|
+
url = f"{self.base_url}/{spreadsheetId}/values/{range_str}"
|
|
1258
1262
|
|
|
1259
1263
|
params = {
|
|
1260
1264
|
"valueInputOption": value_input_option,
|
|
@@ -1268,7 +1272,7 @@ class GoogleSheetApp(APIApplication):
|
|
|
1268
1272
|
|
|
1269
1273
|
def append_values(
|
|
1270
1274
|
self,
|
|
1271
|
-
|
|
1275
|
+
spreadsheetId: str,
|
|
1272
1276
|
range: str,
|
|
1273
1277
|
value_input_option: str,
|
|
1274
1278
|
values: list[list[Any]],
|
|
@@ -1278,10 +1282,10 @@ class GoogleSheetApp(APIApplication):
|
|
|
1278
1282
|
response_date_time_render_option: str | None = None,
|
|
1279
1283
|
) -> dict[str, Any]:
|
|
1280
1284
|
"""
|
|
1281
|
-
Appends rows of data after a table
|
|
1282
|
-
|
|
1285
|
+
Appends rows of data after a specified table in a Google Sheet. Distinct from `update_values` which overwrites data, this function adds new rows at the end of the table. It can also insert rows, shifting existing cells down, offering finer control over data addition.
|
|
1286
|
+
|
|
1283
1287
|
Args:
|
|
1284
|
-
|
|
1288
|
+
spreadsheetId: The ID of the spreadsheet to update. Example: "1q0gLhLdGXYZblahblahblah"
|
|
1285
1289
|
range: The A1 notation of a range to search for a logical table of data. Values are appended after the last row of the table. Example: "Sheet1!A1:B2"
|
|
1286
1290
|
value_input_option: How the input data should be interpreted. Required. Options: "RAW" or "USER_ENTERED". Example: "USER_ENTERED"
|
|
1287
1291
|
values: The data to be written. This is an array of arrays, the outer array representing all the data and each inner array representing a major dimension. Each item in the inner array corresponds with one cell. Example: [["A1_val1", "A1_val2"], ["A2_val1", "A2_val2"]]
|
|
@@ -1289,19 +1293,19 @@ class GoogleSheetApp(APIApplication):
|
|
|
1289
1293
|
include_values_in_response: Determines if the update response should include the values of the cells that were appended. By default, responses do not include the updated values. Example: True
|
|
1290
1294
|
response_value_render_option: Determines how values in the response should be rendered. The default render option is FORMATTED_VALUE. Options: "FORMATTED_VALUE", "UNFORMATTED_VALUE", or "FORMULA". Example: "FORMATTED_VALUE"
|
|
1291
1295
|
response_date_time_render_option: Determines how dates, times, and durations in the response should be rendered. This is ignored if responseValueRenderOption is FORMATTED_VALUE. The default dateTime render option is SERIAL_NUMBER. Options: "SERIAL_NUMBER" or "FORMATTED_STRING". Example: "SERIAL_NUMBER"
|
|
1292
|
-
|
|
1296
|
+
|
|
1293
1297
|
Returns:
|
|
1294
1298
|
A dictionary containing the Google Sheets API response with append details
|
|
1295
|
-
|
|
1299
|
+
|
|
1296
1300
|
Raises:
|
|
1297
1301
|
HTTPError: When the API request fails due to invalid parameters or insufficient permissions
|
|
1298
1302
|
ValueError: When required parameters are empty or invalid
|
|
1299
|
-
|
|
1303
|
+
|
|
1300
1304
|
Tags:
|
|
1301
1305
|
append, values, spreadsheet, data, important
|
|
1302
1306
|
"""
|
|
1303
|
-
if not
|
|
1304
|
-
raise ValueError("
|
|
1307
|
+
if not spreadsheetId:
|
|
1308
|
+
raise ValueError("spreadsheetId cannot be empty")
|
|
1305
1309
|
|
|
1306
1310
|
if not range:
|
|
1307
1311
|
raise ValueError("range cannot be empty")
|
|
@@ -1343,7 +1347,7 @@ class GoogleSheetApp(APIApplication):
|
|
|
1343
1347
|
'response_date_time_render_option must be either "SERIAL_NUMBER" or "FORMATTED_STRING"'
|
|
1344
1348
|
)
|
|
1345
1349
|
|
|
1346
|
-
url = f"{self.base_url}/{
|
|
1350
|
+
url = f"{self.base_url}/{spreadsheetId}/values/{range}:append"
|
|
1347
1351
|
|
|
1348
1352
|
params: dict[str, Any] = {"valueInputOption": value_input_option}
|
|
1349
1353
|
|
|
@@ -1367,33 +1371,33 @@ class GoogleSheetApp(APIApplication):
|
|
|
1367
1371
|
|
|
1368
1372
|
def clear_basic_filter(
|
|
1369
1373
|
self,
|
|
1370
|
-
|
|
1374
|
+
spreadsheetId: str,
|
|
1371
1375
|
sheet_id: int,
|
|
1372
1376
|
) -> dict[str, Any]:
|
|
1373
1377
|
"""
|
|
1374
|
-
Removes the basic filter from a specified sheet
|
|
1375
|
-
|
|
1378
|
+
Removes the basic filter from a specified sheet, clearing active sorting and filtering criteria to restore the default data view. As the direct counterpart to `set_basic_filter`, this function removes the entire filter object, not just the cell content.
|
|
1379
|
+
|
|
1376
1380
|
Args:
|
|
1377
|
-
|
|
1381
|
+
spreadsheetId: The ID of the spreadsheet. Example: "abc123xyz789"
|
|
1378
1382
|
sheet_id: The ID of the sheet on which the basic filter should be cleared. Example: 0
|
|
1379
|
-
|
|
1383
|
+
|
|
1380
1384
|
Returns:
|
|
1381
1385
|
A dictionary containing the Google Sheets API response with update details
|
|
1382
|
-
|
|
1386
|
+
|
|
1383
1387
|
Raises:
|
|
1384
1388
|
HTTPError: When the API request fails due to invalid parameters or insufficient permissions
|
|
1385
|
-
ValueError: When
|
|
1386
|
-
|
|
1389
|
+
ValueError: When spreadsheetId is empty or sheet_id is negative
|
|
1390
|
+
|
|
1387
1391
|
Tags:
|
|
1388
1392
|
clear, filter, basic-filter, spreadsheet
|
|
1389
1393
|
"""
|
|
1390
|
-
if not
|
|
1391
|
-
raise ValueError("
|
|
1394
|
+
if not spreadsheetId:
|
|
1395
|
+
raise ValueError("spreadsheetId cannot be empty")
|
|
1392
1396
|
|
|
1393
1397
|
if sheet_id < 0:
|
|
1394
1398
|
raise ValueError("sheet_id must be non-negative")
|
|
1395
1399
|
|
|
1396
|
-
url = f"{self.base_url}/{
|
|
1400
|
+
url = f"{self.base_url}/{spreadsheetId}:batchUpdate"
|
|
1397
1401
|
|
|
1398
1402
|
request_body = {"requests": [{"clearBasicFilter": {"sheetId": sheet_id}}]}
|
|
1399
1403
|
|
|
@@ -1402,33 +1406,33 @@ class GoogleSheetApp(APIApplication):
|
|
|
1402
1406
|
|
|
1403
1407
|
def delete_sheet(
|
|
1404
1408
|
self,
|
|
1405
|
-
|
|
1409
|
+
spreadsheetId: str,
|
|
1406
1410
|
sheet_id: int,
|
|
1407
1411
|
) -> dict[str, Any]:
|
|
1408
1412
|
"""
|
|
1409
1413
|
Permanently deletes a specific sheet (worksheet) from a Google Spreadsheet using its sheet ID. This operation removes the target sheet and all its contents, acting as the direct counterpart to the `add_sheet` function which creates new sheets within a spreadsheet.
|
|
1410
|
-
|
|
1414
|
+
|
|
1411
1415
|
Args:
|
|
1412
|
-
|
|
1416
|
+
spreadsheetId: The ID of the spreadsheet from which to delete the sheet. Example: "abc123xyz789"
|
|
1413
1417
|
sheet_id: The ID of the sheet to delete. If the sheet is of DATA_SOURCE type, the associated DataSource is also deleted. Example: 123456789
|
|
1414
|
-
|
|
1418
|
+
|
|
1415
1419
|
Returns:
|
|
1416
1420
|
A dictionary containing the Google Sheets API response with update details
|
|
1417
|
-
|
|
1421
|
+
|
|
1418
1422
|
Raises:
|
|
1419
1423
|
HTTPError: When the API request fails due to invalid parameters or insufficient permissions
|
|
1420
|
-
ValueError: When
|
|
1421
|
-
|
|
1424
|
+
ValueError: When spreadsheetId is empty or sheet_id is negative
|
|
1425
|
+
|
|
1422
1426
|
Tags:
|
|
1423
1427
|
delete, sheet, spreadsheet, worksheet
|
|
1424
1428
|
"""
|
|
1425
|
-
if not
|
|
1426
|
-
raise ValueError("
|
|
1429
|
+
if not spreadsheetId:
|
|
1430
|
+
raise ValueError("spreadsheetId cannot be empty")
|
|
1427
1431
|
|
|
1428
1432
|
if sheet_id < 0:
|
|
1429
1433
|
raise ValueError("sheet_id must be non-negative")
|
|
1430
1434
|
|
|
1431
|
-
url = f"{self.base_url}/{
|
|
1435
|
+
url = f"{self.base_url}/{spreadsheetId}:batchUpdate"
|
|
1432
1436
|
|
|
1433
1437
|
request_body = {"requests": [{"deleteSheet": {"sheetId": sheet_id}}]}
|
|
1434
1438
|
|
|
@@ -1437,32 +1441,32 @@ class GoogleSheetApp(APIApplication):
|
|
|
1437
1441
|
|
|
1438
1442
|
def discover_tables(
|
|
1439
1443
|
self,
|
|
1440
|
-
|
|
1444
|
+
spreadsheetId: str,
|
|
1441
1445
|
min_rows: int = 2,
|
|
1442
1446
|
min_columns: int = 1,
|
|
1443
1447
|
min_confidence: float = 0.5,
|
|
1444
1448
|
) -> dict[str, Any]:
|
|
1445
1449
|
"""
|
|
1446
|
-
|
|
1447
|
-
|
|
1450
|
+
Heuristically analyzes a spreadsheet to discover and list all table-like data structures, identifying headers and data boundaries. It returns informal data blocks meeting specified size criteria, distinguishing it from functions like `add_table` that manage formally defined tables.
|
|
1451
|
+
|
|
1448
1452
|
Args:
|
|
1449
|
-
|
|
1453
|
+
spreadsheetId: Google Sheets ID from the URL (e.g., '1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms'). Example: "1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms"
|
|
1450
1454
|
min_rows: Minimum number of data rows to consider a valid table. Example: 2
|
|
1451
1455
|
min_columns: Minimum number of columns to consider a valid table. Example: 1
|
|
1452
1456
|
min_confidence: Minimum confidence score (0.0-1.0) to consider a valid table. Example: 0.5
|
|
1453
|
-
|
|
1457
|
+
|
|
1454
1458
|
Returns:
|
|
1455
1459
|
A dictionary containing the list of discovered tables with their properties
|
|
1456
|
-
|
|
1460
|
+
|
|
1457
1461
|
Raises:
|
|
1458
1462
|
HTTPError: When the API request fails due to invalid parameters or insufficient permissions
|
|
1459
|
-
ValueError: When
|
|
1460
|
-
|
|
1463
|
+
ValueError: When spreadsheetId is empty or parameters are invalid
|
|
1464
|
+
|
|
1461
1465
|
Tags:
|
|
1462
1466
|
list, tables, discover, analyze, spreadsheet, important
|
|
1463
1467
|
"""
|
|
1464
|
-
if not
|
|
1465
|
-
raise ValueError("
|
|
1468
|
+
if not spreadsheetId:
|
|
1469
|
+
raise ValueError("spreadsheetId cannot be empty")
|
|
1466
1470
|
|
|
1467
1471
|
if min_rows < 1:
|
|
1468
1472
|
raise ValueError("min_rows must be at least 1")
|
|
@@ -1474,7 +1478,7 @@ class GoogleSheetApp(APIApplication):
|
|
|
1474
1478
|
raise ValueError("min_confidence must be between 0.0 and 1.0")
|
|
1475
1479
|
|
|
1476
1480
|
# Get spreadsheet structure
|
|
1477
|
-
spreadsheet = self.get_spreadsheet_metadata(
|
|
1481
|
+
spreadsheet = self.get_spreadsheet_metadata(spreadsheetId)
|
|
1478
1482
|
|
|
1479
1483
|
tables = []
|
|
1480
1484
|
|
|
@@ -1486,7 +1490,7 @@ class GoogleSheetApp(APIApplication):
|
|
|
1486
1490
|
# Analyze sheet for tables using helper function
|
|
1487
1491
|
sheet_tables = analyze_sheet_for_tables(
|
|
1488
1492
|
self.get_values, # Pass the get_values method as a function
|
|
1489
|
-
|
|
1493
|
+
spreadsheetId,
|
|
1490
1494
|
sheet_id,
|
|
1491
1495
|
sheet_title,
|
|
1492
1496
|
min_rows,
|
|
@@ -1497,7 +1501,7 @@ class GoogleSheetApp(APIApplication):
|
|
|
1497
1501
|
tables.extend(sheet_tables)
|
|
1498
1502
|
|
|
1499
1503
|
return {
|
|
1500
|
-
"
|
|
1504
|
+
"spreadsheetId": spreadsheetId,
|
|
1501
1505
|
"total_tables": len(tables),
|
|
1502
1506
|
"tables": tables,
|
|
1503
1507
|
"analysis_parameters": {
|
|
@@ -1508,32 +1512,32 @@ class GoogleSheetApp(APIApplication):
|
|
|
1508
1512
|
|
|
1509
1513
|
def analyze_table_schema(
|
|
1510
1514
|
self,
|
|
1511
|
-
|
|
1515
|
+
spreadsheetId: str,
|
|
1512
1516
|
table_name: str,
|
|
1513
1517
|
sheet_name: str | None = None,
|
|
1514
1518
|
sample_size: int = 50,
|
|
1515
1519
|
) -> dict[str, Any]:
|
|
1516
1520
|
"""
|
|
1517
|
-
Infers
|
|
1518
|
-
|
|
1521
|
+
Infers a specified table's schema by analyzing a data sample. After locating the table by name (a value discovered via `discover_tables`), this function determines the most likely data type and properties for each column, providing a detailed structural breakdown of its content.
|
|
1522
|
+
|
|
1519
1523
|
Args:
|
|
1520
|
-
|
|
1524
|
+
spreadsheetId: Google Sheets ID from the URL (e.g., '1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms')
|
|
1521
1525
|
table_name: Specific table name from LIST_TABLES response (e.g., 'Sales_Data', 'Employee_List'). Use 'auto' to analyze the largest/most prominent table
|
|
1522
1526
|
sheet_name: Sheet/tab name if table_name is ambiguous across multiple sheets
|
|
1523
1527
|
sample_size: Number of rows to sample for type inference (1-1000, default 50)
|
|
1524
|
-
|
|
1528
|
+
|
|
1525
1529
|
Returns:
|
|
1526
1530
|
A dictionary containing the table schema with column names, types, and constraints
|
|
1527
|
-
|
|
1531
|
+
|
|
1528
1532
|
Raises:
|
|
1529
1533
|
HTTPError: When the API request fails due to invalid parameters or insufficient permissions
|
|
1530
|
-
ValueError: When
|
|
1531
|
-
|
|
1534
|
+
ValueError: When spreadsheetId is empty, table_name is empty, or sample_size is invalid
|
|
1535
|
+
|
|
1532
1536
|
Tags:
|
|
1533
1537
|
schema, analyze, table, structure, types, columns
|
|
1534
1538
|
"""
|
|
1535
|
-
if not
|
|
1536
|
-
raise ValueError("
|
|
1539
|
+
if not spreadsheetId:
|
|
1540
|
+
raise ValueError("spreadsheetId cannot be empty")
|
|
1537
1541
|
|
|
1538
1542
|
if not table_name:
|
|
1539
1543
|
raise ValueError("table_name cannot be empty")
|
|
@@ -1542,7 +1546,7 @@ class GoogleSheetApp(APIApplication):
|
|
|
1542
1546
|
raise ValueError("sample_size must be between 1 and 1000")
|
|
1543
1547
|
|
|
1544
1548
|
# Get spreadsheet structure
|
|
1545
|
-
spreadsheet = self.get_spreadsheet_metadata(
|
|
1549
|
+
spreadsheet = self.get_spreadsheet_metadata(spreadsheetId)
|
|
1546
1550
|
|
|
1547
1551
|
# Find the target table
|
|
1548
1552
|
target_table = None
|
|
@@ -1558,7 +1562,7 @@ class GoogleSheetApp(APIApplication):
|
|
|
1558
1562
|
# Get tables in this sheet
|
|
1559
1563
|
sheet_tables = analyze_sheet_for_tables(
|
|
1560
1564
|
self.get_values,
|
|
1561
|
-
|
|
1565
|
+
spreadsheetId,
|
|
1562
1566
|
sheet_properties.get("sheetId", 0),
|
|
1563
1567
|
sheet_title,
|
|
1564
1568
|
min_rows=2,
|
|
@@ -1586,19 +1590,19 @@ class GoogleSheetApp(APIApplication):
|
|
|
1586
1590
|
|
|
1587
1591
|
# Use the helper function to analyze the table schema
|
|
1588
1592
|
return analyze_table_schema(
|
|
1589
|
-
self.get_values,
|
|
1593
|
+
self.get_values, spreadsheetId, target_table, sample_size
|
|
1590
1594
|
)
|
|
1591
1595
|
|
|
1592
1596
|
def set_basic_filter(
|
|
1593
1597
|
self,
|
|
1594
|
-
|
|
1598
|
+
spreadsheetId: str,
|
|
1595
1599
|
filter: dict,
|
|
1596
1600
|
) -> dict[str, Any]:
|
|
1597
1601
|
"""
|
|
1598
1602
|
Sets or updates a basic filter on a specified range within a sheet, enabling data sorting and filtering. The filter's target range and optional sort specifications are defined in a dictionary argument. It is the counterpart to `clear_basic_filter`, which removes an existing filter.
|
|
1599
|
-
|
|
1603
|
+
|
|
1600
1604
|
Args:
|
|
1601
|
-
|
|
1605
|
+
spreadsheetId: The ID of the spreadsheet. Example: "abc123xyz789"
|
|
1602
1606
|
filter: The filter to set. This parameter is required. Contains:
|
|
1603
1607
|
- range: The range the filter covers (required)
|
|
1604
1608
|
- sheetId: The sheet this range is on (required)
|
|
@@ -1609,19 +1613,19 @@ class GoogleSheetApp(APIApplication):
|
|
|
1609
1613
|
- sortSpecs: The sort specifications for the filter (optional)
|
|
1610
1614
|
- dimensionIndex: The dimension the sort should be applied to
|
|
1611
1615
|
- sortOrder: The order data should be sorted ("ASCENDING", "DESCENDING", "SORT_ORDER_UNSPECIFIED")
|
|
1612
|
-
|
|
1616
|
+
|
|
1613
1617
|
Returns:
|
|
1614
1618
|
A dictionary containing the Google Sheets API response with filter details
|
|
1615
|
-
|
|
1619
|
+
|
|
1616
1620
|
Raises:
|
|
1617
1621
|
HTTPError: When the API request fails due to invalid parameters or insufficient permissions
|
|
1618
|
-
ValueError: When
|
|
1619
|
-
|
|
1622
|
+
ValueError: When spreadsheetId is empty or filter is missing required fields
|
|
1623
|
+
|
|
1620
1624
|
Tags:
|
|
1621
1625
|
filter, basic-filter, spreadsheet, sort, important
|
|
1622
1626
|
"""
|
|
1623
|
-
if not
|
|
1624
|
-
raise ValueError("
|
|
1627
|
+
if not spreadsheetId:
|
|
1628
|
+
raise ValueError("spreadsheetId cannot be empty")
|
|
1625
1629
|
|
|
1626
1630
|
if not filter:
|
|
1627
1631
|
raise ValueError("filter cannot be empty")
|
|
@@ -1635,7 +1639,7 @@ class GoogleSheetApp(APIApplication):
|
|
|
1635
1639
|
if "sheetId" not in range_data:
|
|
1636
1640
|
raise ValueError("filter range must contain 'sheetId' field")
|
|
1637
1641
|
|
|
1638
|
-
url = f"{self.base_url}/{
|
|
1642
|
+
url = f"{self.base_url}/{spreadsheetId}:batchUpdate"
|
|
1639
1643
|
|
|
1640
1644
|
request_body = {"requests": [{"setBasicFilter": {"filter": filter}}]}
|
|
1641
1645
|
|
|
@@ -1681,8 +1685,8 @@ class GoogleSheetApp(APIApplication):
|
|
|
1681
1685
|
mergeCells: bool = False,
|
|
1682
1686
|
) -> dict[str, Any]:
|
|
1683
1687
|
"""
|
|
1684
|
-
Applies comprehensive formatting to a specified cell range in a worksheet. It modifies visual properties like text style, color, alignment, borders, and can merge cells, without altering the underlying cell values
|
|
1685
|
-
|
|
1688
|
+
Applies comprehensive formatting to a specified cell range in a worksheet. It modifies visual properties like text style, color, alignment, borders, and can merge cells, without altering the underlying cell values, distinguishing it from data-modification functions like `update_values`.
|
|
1689
|
+
|
|
1686
1690
|
Args:
|
|
1687
1691
|
spreadsheetId: Identifier of the Google Sheets spreadsheet. Example: "1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms"
|
|
1688
1692
|
worksheetId: ID (sheetId) of the worksheet. Use `get_spreadsheet_metadata` to find this ID. Example: 123456789
|
|
@@ -1690,44 +1694,44 @@ class GoogleSheetApp(APIApplication):
|
|
|
1690
1694
|
startColumnIndex: 0-based index of the first column in the range. Example: 0
|
|
1691
1695
|
endRowIndex: 0-based index of the row *after* the last row in the range (exclusive). Example: 1
|
|
1692
1696
|
endColumnIndex: 0-based index of the column *after* the last column in the range (exclusive). Example: 2
|
|
1693
|
-
|
|
1694
|
-
|
|
1697
|
+
|
|
1698
|
+
|
|
1695
1699
|
bold: Apply bold formatting. Example: True
|
|
1696
1700
|
italic: Apply italic formatting. Example: False
|
|
1697
1701
|
underline: Apply underline formatting. Example: False
|
|
1698
1702
|
strikethrough: Apply strikethrough formatting. Example: False
|
|
1699
1703
|
fontSize: Font size in points. Example: 12
|
|
1700
1704
|
fontFamily: Font family name. Example: "Arial", "Times New Roman"
|
|
1701
|
-
|
|
1705
|
+
|
|
1702
1706
|
backgroundRed: Red component of background color. Example: 0.9
|
|
1703
1707
|
backgroundGreen: Green component of background color. Example: 0.9
|
|
1704
1708
|
backgroundBlue: Blue component of background color. Example: 0.9
|
|
1705
|
-
|
|
1709
|
+
|
|
1706
1710
|
textRed: Red component of text color. Example: 0.0
|
|
1707
1711
|
textGreen: Green component of text color. Example: 0.0
|
|
1708
1712
|
textBlue: Blue component of text color. Example: 0.0
|
|
1709
|
-
|
|
1713
|
+
|
|
1710
1714
|
horizontalAlignment: "LEFT", "CENTER", or "RIGHT". Example: "CENTER"
|
|
1711
1715
|
verticalAlignment: "TOP", "MIDDLE", or "BOTTOM". Example: "MIDDLE"
|
|
1712
|
-
|
|
1716
|
+
|
|
1713
1717
|
wrapStrategy: "OVERFLOW_CELL", "LEGACY_WRAP", "CLIP", or "WRAP". Example: "WRAP"
|
|
1714
|
-
|
|
1718
|
+
|
|
1715
1719
|
numberFormat: Number format string. Example: "#,##0.00", "0.00%", "$#,##0.00"
|
|
1716
|
-
|
|
1720
|
+
|
|
1717
1721
|
borderTop: Top border settings. Example: {"style": "SOLID", "color": {"red": 0, "green": 0, "blue": 0}}
|
|
1718
1722
|
borderBottom: Bottom border settings. Example: {"style": "SOLID", "color": {"red": 0, "green": 0, "blue": 0}}
|
|
1719
1723
|
borderLeft: Left border settings. Example: {"style": "SOLID", "color": {"red": 0, "green": 0, "blue": 0}}
|
|
1720
1724
|
borderRight: Right border settings. Example: {"style": "SOLID", "color": {"red": 0, "green": 0, "blue": 0}}
|
|
1721
|
-
|
|
1725
|
+
|
|
1722
1726
|
mergeCells: Whether to merge the specified range into a single cell. Example: True
|
|
1723
|
-
|
|
1727
|
+
|
|
1724
1728
|
Returns:
|
|
1725
1729
|
A dictionary containing the Google Sheets API response with formatting details
|
|
1726
|
-
|
|
1730
|
+
|
|
1727
1731
|
Raises:
|
|
1728
1732
|
HTTPError: When the API request fails due to invalid parameters or insufficient permissions
|
|
1729
|
-
ValueError: When
|
|
1730
|
-
|
|
1733
|
+
ValueError: When spreadsheetId is empty, indices are invalid, or color values are out of range
|
|
1734
|
+
|
|
1731
1735
|
Tags:
|
|
1732
1736
|
format, cells, styling, text-formatting, background-color, borders, alignment, merge
|
|
1733
1737
|
"""
|