csa-google-workspace 0.1.0__tar.gz

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.
Files changed (64) hide show
  1. csa_google_workspace-0.1.0/LICENSE +202 -0
  2. csa_google_workspace-0.1.0/PKG-INFO +144 -0
  3. csa_google_workspace-0.1.0/README.md +107 -0
  4. csa_google_workspace-0.1.0/pyproject.toml +102 -0
  5. csa_google_workspace-0.1.0/setup.cfg +4 -0
  6. csa_google_workspace-0.1.0/src/csa_google_workspace/__init__.py +19 -0
  7. csa_google_workspace-0.1.0/src/csa_google_workspace/_cellmap.py +112 -0
  8. csa_google_workspace-0.1.0/src/csa_google_workspace/_content.py +54 -0
  9. csa_google_workspace-0.1.0/src/csa_google_workspace/_errors.py +90 -0
  10. csa_google_workspace-0.1.0/src/csa_google_workspace/_services.py +32 -0
  11. csa_google_workspace-0.1.0/src/csa_google_workspace/auth.py +69 -0
  12. csa_google_workspace-0.1.0/src/csa_google_workspace/backend.py +336 -0
  13. csa_google_workspace-0.1.0/src/csa_google_workspace/base.py +71 -0
  14. csa_google_workspace-0.1.0/src/csa_google_workspace/comments.py +237 -0
  15. csa_google_workspace-0.1.0/src/csa_google_workspace/documents/__init__.py +1 -0
  16. csa_google_workspace-0.1.0/src/csa_google_workspace/documents/doc.py +51 -0
  17. csa_google_workspace-0.1.0/src/csa_google_workspace/documents/sheet.py +136 -0
  18. csa_google_workspace-0.1.0/src/csa_google_workspace/documents/slides.py +55 -0
  19. csa_google_workspace-0.1.0/src/csa_google_workspace/exceptions.py +59 -0
  20. csa_google_workspace-0.1.0/src/csa_google_workspace/py.typed +0 -0
  21. csa_google_workspace-0.1.0/src/csa_google_workspace/suggestions.py +54 -0
  22. csa_google_workspace-0.1.0/src/csa_google_workspace/workspace.py +53 -0
  23. csa_google_workspace-0.1.0/src/csa_google_workspace.egg-info/PKG-INFO +144 -0
  24. csa_google_workspace-0.1.0/src/csa_google_workspace.egg-info/SOURCES.txt +62 -0
  25. csa_google_workspace-0.1.0/src/csa_google_workspace.egg-info/dependency_links.txt +1 -0
  26. csa_google_workspace-0.1.0/src/csa_google_workspace.egg-info/requires.txt +10 -0
  27. csa_google_workspace-0.1.0/src/csa_google_workspace.egg-info/top_level.txt +1 -0
  28. csa_google_workspace-0.1.0/tests/test_apibackend_contract.py +101 -0
  29. csa_google_workspace-0.1.0/tests/test_apibackend_errors.py +80 -0
  30. csa_google_workspace-0.1.0/tests/test_auth.py +45 -0
  31. csa_google_workspace-0.1.0/tests/test_auth_lifecycle.py +160 -0
  32. csa_google_workspace-0.1.0/tests/test_backend.py +26 -0
  33. csa_google_workspace-0.1.0/tests/test_backend_comments.py +52 -0
  34. csa_google_workspace-0.1.0/tests/test_backend_conformance.py +42 -0
  35. csa_google_workspace-0.1.0/tests/test_backend_content.py +43 -0
  36. csa_google_workspace-0.1.0/tests/test_backend_write.py +34 -0
  37. csa_google_workspace-0.1.0/tests/test_cellmap.py +77 -0
  38. csa_google_workspace-0.1.0/tests/test_cellmap_bounds.py +61 -0
  39. csa_google_workspace-0.1.0/tests/test_comment_detached.py +39 -0
  40. csa_google_workspace-0.1.0/tests/test_comment_model.py +51 -0
  41. csa_google_workspace-0.1.0/tests/test_comment_mutation.py +95 -0
  42. csa_google_workspace-0.1.0/tests/test_comments_collection.py +83 -0
  43. csa_google_workspace-0.1.0/tests/test_content_aliasing.py +45 -0
  44. csa_google_workspace-0.1.0/tests/test_doc_content.py +41 -0
  45. csa_google_workspace-0.1.0/tests/test_doc_suggestions.py +50 -0
  46. csa_google_workspace-0.1.0/tests/test_doc_write.py +68 -0
  47. csa_google_workspace-0.1.0/tests/test_document.py +31 -0
  48. csa_google_workspace-0.1.0/tests/test_document_lifecycle.py +62 -0
  49. csa_google_workspace-0.1.0/tests/test_errors.py +176 -0
  50. csa_google_workspace-0.1.0/tests/test_errors_edge.py +57 -0
  51. csa_google_workspace-0.1.0/tests/test_exceptions.py +24 -0
  52. csa_google_workspace-0.1.0/tests/test_packaging.py +17 -0
  53. csa_google_workspace-0.1.0/tests/test_public_api.py +32 -0
  54. csa_google_workspace-0.1.0/tests/test_repr_redaction.py +41 -0
  55. csa_google_workspace-0.1.0/tests/test_services.py +17 -0
  56. csa_google_workspace-0.1.0/tests/test_sheet_cellmap.py +107 -0
  57. csa_google_workspace-0.1.0/tests/test_sheet_content.py +63 -0
  58. csa_google_workspace-0.1.0/tests/test_sheet_create_comment.py +71 -0
  59. csa_google_workspace-0.1.0/tests/test_sheet_quoting.py +46 -0
  60. csa_google_workspace-0.1.0/tests/test_sheet_write.py +79 -0
  61. csa_google_workspace-0.1.0/tests/test_slides_content.py +69 -0
  62. csa_google_workspace-0.1.0/tests/test_slides_write.py +68 -0
  63. csa_google_workspace-0.1.0/tests/test_suggestions.py +67 -0
  64. csa_google_workspace-0.1.0/tests/test_workspace.py +55 -0
@@ -0,0 +1,202 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2025 Kurt Seifried kseifried@cloudsecurityalliance.org
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
202
+
@@ -0,0 +1,144 @@
1
+ Metadata-Version: 2.4
2
+ Name: csa-google-workspace
3
+ Version: 0.1.0
4
+ Summary: Read/write content and manage comments on Google Docs, Sheets, and Slides
5
+ Author: Cloud Security Alliance
6
+ Maintainer-email: Kurt Seifried <kseifried@cloudsecurityalliance.org>
7
+ License-Expression: Apache-2.0
8
+ Project-URL: Homepage, https://github.com/CloudSecurityAlliance/csa-google-workspace
9
+ Project-URL: Repository, https://github.com/CloudSecurityAlliance/csa-google-workspace
10
+ Project-URL: Issues, https://github.com/CloudSecurityAlliance/csa-google-workspace/issues
11
+ Project-URL: Changelog, https://github.com/CloudSecurityAlliance/csa-google-workspace/blob/main/CHANGELOG.md
12
+ Keywords: google,google-workspace,google-docs,google-sheets,google-slides,google-drive,comments,suggestions,mcp
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Topic :: Office/Business
22
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
23
+ Classifier: Typing :: Typed
24
+ Requires-Python: >=3.10
25
+ Description-Content-Type: text/markdown
26
+ License-File: LICENSE
27
+ Requires-Dist: google-api-python-client>=2.0
28
+ Requires-Dist: google-auth>=2.0
29
+ Requires-Dist: google-auth-oauthlib>=1.0
30
+ Requires-Dist: defusedxml>=0.7
31
+ Provides-Extra: dev
32
+ Requires-Dist: pytest>=8.0; extra == "dev"
33
+ Requires-Dist: pytest-cov>=5.0; extra == "dev"
34
+ Requires-Dist: ruff>=0.6; extra == "dev"
35
+ Requires-Dist: mypy>=1.11; extra == "dev"
36
+ Dynamic: license-file
37
+
38
+ # csa-google-workspace
39
+
40
+ A **Python library** for managing **comments** and **content** on Google **Docs, Sheets, and Slides**, via the Google APIs. Comments are handled uniformly across all three file types (a single Drive API v3 concern); content read/write and Sheets comment→cell mapping are the variant, per-API parts.
41
+
42
+ It's designed to be **embedded**: a clean, typed Python surface for building AI tooling on top of Google Workspace — **MCP servers, agent/LLM plugins, review bots, and automation services** that need to read documents, triage and reply to comments, and write edits back. The `Workspace(backend=…)` seam (dependency injection / run-as-a-service) and the `Backend` protocol exist for exactly that; an MCP wrapper is a natural (out-of-scope-for-now) layer on top.
43
+
44
+ > **Status:** feature-complete for its scoped roadmap and **live-verified end-to-end against real Google**. Shipped across Docs/Sheets/Slides: comment management, content read/write, Sheets comment→cell mapping, and Docs suggestions read. See [`CHANGELOG.md`](./CHANGELOG.md); design + phased plans under [`docs/superpowers/`](./docs/superpowers/).
45
+
46
+ ## Install & test
47
+
48
+ ```bash
49
+ pip install -e ".[dev]" # src/ layout, Python >=3.10
50
+ pytest -q # unit suite: no network, no credentials (in-memory FakeBackend)
51
+ ruff check src tests && mypy # lint + type-check (the CI `lint` job)
52
+ ```
53
+
54
+ Everything above runs offline and gates CI. Two **opt-in** suites exercise real Google and
55
+ are skipped unless their env vars are set:
56
+
57
+ ```bash
58
+ # Live API suite — real Docs/Sheets/Slides/Drive. Needs OAuth client secrets; a cached token
59
+ # avoids re-consent, otherwise the first run opens a browser to log in:
60
+ CSA_GW_INTEGRATION=1 CSA_GW_CLIENT_SECRETS=path/to/client_secret.json pytest tests/integration/
61
+
62
+ # Interactive OAuth suite — the login flow itself (token caching, file permissions, read-only
63
+ # contract). Separate because it needs a human at a browser + touches the sensitive token:
64
+ CSA_GW_OAUTH=1 CSA_GW_CLIENT_SECRETS=path/to/client_secret.json pytest tests/oauth/
65
+ ```
66
+
67
+ The client secret must be an **installed/desktop-app** OAuth client, and Drive, Docs, Sheets,
68
+ and Slides must be enabled in its Cloud project (a scoped token still 403s until each API is
69
+ enabled). `client_secret.json` and `token*.json` are gitignored — never commit them.
70
+
71
+ ## Usage
72
+
73
+ ```python
74
+ from csa_google_workspace import Workspace
75
+
76
+ ws = Workspace.from_credentials(my_google_creds) # BYO credentials (or .from_oauth("client_secret.json"))
77
+ doc = ws.open("https://docs.google.com/document/d/…/edit") # -> Doc | Sheet | Slides
78
+
79
+ # Comments — uniform across all three file types
80
+ for c in doc.comments.filter(resolved=False): # triage open comments
81
+ print(c.author.display_name, c.content)
82
+ c.reply("looking into it"); c.resolve()
83
+ doc.create_comment("Please review section 3")
84
+
85
+ # Content read + write (type-specific)
86
+ doc.as_text() # plain text of a Doc / Sheet grid / Slides deck
87
+ doc.replace_text("draft", "final") # Doc & Slides; doc.append_text / insert_text / delete_range too
88
+ doc.suggestions # Docs suggesting-mode edits (read-only)
89
+ doc.as_text(suggestions="accepted") # preview as if suggestions accepted / rejected
90
+
91
+ sheet = ws.open(sheet_url)
92
+ sheet.update("Sheet1!A1", [["=SUM(B:B)"]], value_input_option="USER_ENTERED") # formulas ok
93
+ sheet.append_rows("Sheet1!A1", [["new", "row"]]) # append after the last row
94
+ sheet.as_text(tab="Data") # one tab; as_text() renders all tabs
95
+ sheet.comments_by_cell("B11") # comments mapped back to a cell (best-effort)
96
+ ```
97
+
98
+ **Entry points:** `Workspace.from_credentials(creds)` (bring-your-own credentials — user OAuth or a service account), `Workspace(backend=…)` (dependency injection / run-as-a-service), `Workspace.from_oauth(...)` (interactive login). **Writes are on by default**; pass `read_only=True` to lock them (and narrow to read-only OAuth scopes). Public types — `Comment`, `Author`, `Reply`, `Location`, `Suggestion`, `Slide` — are importable from the package root.
99
+
100
+ ## Capability boundaries
101
+
102
+ The library is **document-scoped** and honest about what the Google APIs can't do:
103
+
104
+ - **Suggestions are read/preview only.** `Doc.suggestions` reads suggesting-mode edits and `as_text(suggestions="accepted"|"rejected")` previews the outcome, but **accepting/rejecting is impossible via the API** (`UnsupportedOperation`) — Google exposes no endpoint. Reserved for a future `PlaywrightBackend`.
105
+ - **No document discovery.** You hand the library a file id/URL (`Workspace.open(id)`); there is no `files.list`/search. A "sweep my documents" job enumerates files itself and opens each:
106
+ ```python
107
+ files = drive.files().list(q="mimeType='application/vnd.google-apps.document'",
108
+ fields="files(id)").execute()["files"]
109
+ for f in files:
110
+ doc = ws.open(f["id"])
111
+ ...
112
+ ```
113
+ - **Sheets cell-anchored comments can't be created via the API** — `sheet.create_comment(text, cell=…)` posts a file-level comment with a `#gid=…&range=…` deep-link instead.
114
+
115
+ ## Using it on a user's behalf (production)
116
+
117
+ This library is a building block for MCP servers / agents / automations acting **on a user's behalf** with a full-Drive token. Before deploying, read [`SECURITY.md`](./SECURITY.md) — prompt injection through document/comment content is the primary risk. In short:
118
+
119
+ - **Credential seam:** `from_oauth` + local `token.json` is **PoC/CLI scaffolding** (`run_local_server()` can't run on a server). In production the host runs its own OAuth, stores per-user tokens in a secret store, and passes ready credentials via **`Workspace.from_credentials(creds)`** — the production entry point.
120
+ - **Concurrency:** one `Workspace` per request/user; never share a `Workspace` (or its backend) across threads — `googleapiclient` clients aren't thread-safe. The stack is synchronous; wrap calls in `asyncio.to_thread(...)` from async code.
121
+ - **Isolation & least authority:** a `Workspace` binds one user's credentials — never reuse it across users. Default to `read_only=True` and escalate to a write-capable `Workspace` deliberately, per operation.
122
+
123
+ ## Documents
124
+
125
+ | Document | What it is |
126
+ |----------|------------|
127
+ | [`docs/superpowers/specs/2026-07-20-csa-google-workspace-design.md`](./docs/superpowers/specs/2026-07-20-csa-google-workspace-design.md) | **The design spec.** Scope, two-axis architecture, API surface, error model, phasing. |
128
+ | [`docs/superpowers/plans/`](./docs/superpowers/plans/) | The six phased, TDD implementation plans (foundations · comments · content read · cell-mapping · content write · suggestions read). |
129
+ | [`research/google-drive-comments-reference.md`](./research/google-drive-comments-reference.md) | Canonical reference on how Drive/Sheets comments actually work: the 10 API methods, fields, resolution/deletion models, OAuth scopes, and the hard truth about the `anchor` field. |
130
+ | [`research/docs-suggestions-reference.md`](./research/docs-suggestions-reference.md) | How Docs **suggestions** behave: readable (incl. accepted/rejected previews), but **no accept/reject endpoint** and no author exposed. |
131
+ | [`research/server-landscape.md`](./research/server-landscape.md) | Source-verified survey of prior-art servers that handle Google comments. |
132
+ | [`research/mcp-server-design.md`](./research/mcp-server-design.md) · [`research/mcp-protocol-notes.md`](./research/mcp-protocol-notes.md) | Earlier MCP-server design + protocol notes (kept for reference should an MCP wrapper be added). |
133
+ | [`experiments/`](./experiments/) | Runnable **empirical probes** (with dated `RESULTS.md`): `anchor-probe`, `comment-lifecycle`, `docs-suggestions`, `sheets-cellmap`. Probe beats docs. |
134
+ | [`CHANGELOG.md`](./CHANGELOG.md) | What changed in each refresh, and why. |
135
+
136
+ ## Three things worth knowing
137
+
138
+ 1. **Comments are a Google Drive API v3 concern — not the Sheets/Docs/Slides APIs** (those handle content). One comment API serves all three file types. (Sheets *notes* are separate and out of scope.)
139
+ 2. **You cannot anchor a comment to a specific Sheets cell via the API.** Google treats API-created anchors as unanchored; the real anchor is a `workbook-range` with an opaque id. Mapping a comment back to a cell requires exporting the sheet as XLSX and parsing the comment XML — the central hard problem, which the library solves (best-effort) via `comment.location` / `sheet.comments_by_cell()`.
140
+ 3. **The space isn't greenfield, so the value is in the hard parts** — reliable read-side cell mapping and clean Docs/Sheets/Slides coverage — not merely "supporting comments." See [`server-landscape.md`](./research/server-landscape.md).
141
+
142
+ ## License
143
+
144
+ Licensed under the [Apache License, Version 2.0](./LICENSE).
@@ -0,0 +1,107 @@
1
+ # csa-google-workspace
2
+
3
+ A **Python library** for managing **comments** and **content** on Google **Docs, Sheets, and Slides**, via the Google APIs. Comments are handled uniformly across all three file types (a single Drive API v3 concern); content read/write and Sheets comment→cell mapping are the variant, per-API parts.
4
+
5
+ It's designed to be **embedded**: a clean, typed Python surface for building AI tooling on top of Google Workspace — **MCP servers, agent/LLM plugins, review bots, and automation services** that need to read documents, triage and reply to comments, and write edits back. The `Workspace(backend=…)` seam (dependency injection / run-as-a-service) and the `Backend` protocol exist for exactly that; an MCP wrapper is a natural (out-of-scope-for-now) layer on top.
6
+
7
+ > **Status:** feature-complete for its scoped roadmap and **live-verified end-to-end against real Google**. Shipped across Docs/Sheets/Slides: comment management, content read/write, Sheets comment→cell mapping, and Docs suggestions read. See [`CHANGELOG.md`](./CHANGELOG.md); design + phased plans under [`docs/superpowers/`](./docs/superpowers/).
8
+
9
+ ## Install & test
10
+
11
+ ```bash
12
+ pip install -e ".[dev]" # src/ layout, Python >=3.10
13
+ pytest -q # unit suite: no network, no credentials (in-memory FakeBackend)
14
+ ruff check src tests && mypy # lint + type-check (the CI `lint` job)
15
+ ```
16
+
17
+ Everything above runs offline and gates CI. Two **opt-in** suites exercise real Google and
18
+ are skipped unless their env vars are set:
19
+
20
+ ```bash
21
+ # Live API suite — real Docs/Sheets/Slides/Drive. Needs OAuth client secrets; a cached token
22
+ # avoids re-consent, otherwise the first run opens a browser to log in:
23
+ CSA_GW_INTEGRATION=1 CSA_GW_CLIENT_SECRETS=path/to/client_secret.json pytest tests/integration/
24
+
25
+ # Interactive OAuth suite — the login flow itself (token caching, file permissions, read-only
26
+ # contract). Separate because it needs a human at a browser + touches the sensitive token:
27
+ CSA_GW_OAUTH=1 CSA_GW_CLIENT_SECRETS=path/to/client_secret.json pytest tests/oauth/
28
+ ```
29
+
30
+ The client secret must be an **installed/desktop-app** OAuth client, and Drive, Docs, Sheets,
31
+ and Slides must be enabled in its Cloud project (a scoped token still 403s until each API is
32
+ enabled). `client_secret.json` and `token*.json` are gitignored — never commit them.
33
+
34
+ ## Usage
35
+
36
+ ```python
37
+ from csa_google_workspace import Workspace
38
+
39
+ ws = Workspace.from_credentials(my_google_creds) # BYO credentials (or .from_oauth("client_secret.json"))
40
+ doc = ws.open("https://docs.google.com/document/d/…/edit") # -> Doc | Sheet | Slides
41
+
42
+ # Comments — uniform across all three file types
43
+ for c in doc.comments.filter(resolved=False): # triage open comments
44
+ print(c.author.display_name, c.content)
45
+ c.reply("looking into it"); c.resolve()
46
+ doc.create_comment("Please review section 3")
47
+
48
+ # Content read + write (type-specific)
49
+ doc.as_text() # plain text of a Doc / Sheet grid / Slides deck
50
+ doc.replace_text("draft", "final") # Doc & Slides; doc.append_text / insert_text / delete_range too
51
+ doc.suggestions # Docs suggesting-mode edits (read-only)
52
+ doc.as_text(suggestions="accepted") # preview as if suggestions accepted / rejected
53
+
54
+ sheet = ws.open(sheet_url)
55
+ sheet.update("Sheet1!A1", [["=SUM(B:B)"]], value_input_option="USER_ENTERED") # formulas ok
56
+ sheet.append_rows("Sheet1!A1", [["new", "row"]]) # append after the last row
57
+ sheet.as_text(tab="Data") # one tab; as_text() renders all tabs
58
+ sheet.comments_by_cell("B11") # comments mapped back to a cell (best-effort)
59
+ ```
60
+
61
+ **Entry points:** `Workspace.from_credentials(creds)` (bring-your-own credentials — user OAuth or a service account), `Workspace(backend=…)` (dependency injection / run-as-a-service), `Workspace.from_oauth(...)` (interactive login). **Writes are on by default**; pass `read_only=True` to lock them (and narrow to read-only OAuth scopes). Public types — `Comment`, `Author`, `Reply`, `Location`, `Suggestion`, `Slide` — are importable from the package root.
62
+
63
+ ## Capability boundaries
64
+
65
+ The library is **document-scoped** and honest about what the Google APIs can't do:
66
+
67
+ - **Suggestions are read/preview only.** `Doc.suggestions` reads suggesting-mode edits and `as_text(suggestions="accepted"|"rejected")` previews the outcome, but **accepting/rejecting is impossible via the API** (`UnsupportedOperation`) — Google exposes no endpoint. Reserved for a future `PlaywrightBackend`.
68
+ - **No document discovery.** You hand the library a file id/URL (`Workspace.open(id)`); there is no `files.list`/search. A "sweep my documents" job enumerates files itself and opens each:
69
+ ```python
70
+ files = drive.files().list(q="mimeType='application/vnd.google-apps.document'",
71
+ fields="files(id)").execute()["files"]
72
+ for f in files:
73
+ doc = ws.open(f["id"])
74
+ ...
75
+ ```
76
+ - **Sheets cell-anchored comments can't be created via the API** — `sheet.create_comment(text, cell=…)` posts a file-level comment with a `#gid=…&range=…` deep-link instead.
77
+
78
+ ## Using it on a user's behalf (production)
79
+
80
+ This library is a building block for MCP servers / agents / automations acting **on a user's behalf** with a full-Drive token. Before deploying, read [`SECURITY.md`](./SECURITY.md) — prompt injection through document/comment content is the primary risk. In short:
81
+
82
+ - **Credential seam:** `from_oauth` + local `token.json` is **PoC/CLI scaffolding** (`run_local_server()` can't run on a server). In production the host runs its own OAuth, stores per-user tokens in a secret store, and passes ready credentials via **`Workspace.from_credentials(creds)`** — the production entry point.
83
+ - **Concurrency:** one `Workspace` per request/user; never share a `Workspace` (or its backend) across threads — `googleapiclient` clients aren't thread-safe. The stack is synchronous; wrap calls in `asyncio.to_thread(...)` from async code.
84
+ - **Isolation & least authority:** a `Workspace` binds one user's credentials — never reuse it across users. Default to `read_only=True` and escalate to a write-capable `Workspace` deliberately, per operation.
85
+
86
+ ## Documents
87
+
88
+ | Document | What it is |
89
+ |----------|------------|
90
+ | [`docs/superpowers/specs/2026-07-20-csa-google-workspace-design.md`](./docs/superpowers/specs/2026-07-20-csa-google-workspace-design.md) | **The design spec.** Scope, two-axis architecture, API surface, error model, phasing. |
91
+ | [`docs/superpowers/plans/`](./docs/superpowers/plans/) | The six phased, TDD implementation plans (foundations · comments · content read · cell-mapping · content write · suggestions read). |
92
+ | [`research/google-drive-comments-reference.md`](./research/google-drive-comments-reference.md) | Canonical reference on how Drive/Sheets comments actually work: the 10 API methods, fields, resolution/deletion models, OAuth scopes, and the hard truth about the `anchor` field. |
93
+ | [`research/docs-suggestions-reference.md`](./research/docs-suggestions-reference.md) | How Docs **suggestions** behave: readable (incl. accepted/rejected previews), but **no accept/reject endpoint** and no author exposed. |
94
+ | [`research/server-landscape.md`](./research/server-landscape.md) | Source-verified survey of prior-art servers that handle Google comments. |
95
+ | [`research/mcp-server-design.md`](./research/mcp-server-design.md) · [`research/mcp-protocol-notes.md`](./research/mcp-protocol-notes.md) | Earlier MCP-server design + protocol notes (kept for reference should an MCP wrapper be added). |
96
+ | [`experiments/`](./experiments/) | Runnable **empirical probes** (with dated `RESULTS.md`): `anchor-probe`, `comment-lifecycle`, `docs-suggestions`, `sheets-cellmap`. Probe beats docs. |
97
+ | [`CHANGELOG.md`](./CHANGELOG.md) | What changed in each refresh, and why. |
98
+
99
+ ## Three things worth knowing
100
+
101
+ 1. **Comments are a Google Drive API v3 concern — not the Sheets/Docs/Slides APIs** (those handle content). One comment API serves all three file types. (Sheets *notes* are separate and out of scope.)
102
+ 2. **You cannot anchor a comment to a specific Sheets cell via the API.** Google treats API-created anchors as unanchored; the real anchor is a `workbook-range` with an opaque id. Mapping a comment back to a cell requires exporting the sheet as XLSX and parsing the comment XML — the central hard problem, which the library solves (best-effort) via `comment.location` / `sheet.comments_by_cell()`.
103
+ 3. **The space isn't greenfield, so the value is in the hard parts** — reliable read-side cell mapping and clean Docs/Sheets/Slides coverage — not merely "supporting comments." See [`server-landscape.md`](./research/server-landscape.md).
104
+
105
+ ## License
106
+
107
+ Licensed under the [Apache License, Version 2.0](./LICENSE).
@@ -0,0 +1,102 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "csa-google-workspace"
7
+ dynamic = ["version"]
8
+ description = "Read/write content and manage comments on Google Docs, Sheets, and Slides"
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ license = "Apache-2.0"
12
+ license-files = ["LICENSE"]
13
+ authors = [{ name = "Cloud Security Alliance" }]
14
+ maintainers = [{ name = "Kurt Seifried", email = "kseifried@cloudsecurityalliance.org" }]
15
+ keywords = [
16
+ "google",
17
+ "google-workspace",
18
+ "google-docs",
19
+ "google-sheets",
20
+ "google-slides",
21
+ "google-drive",
22
+ "comments",
23
+ "suggestions",
24
+ "mcp",
25
+ ]
26
+ classifiers = [
27
+ "Development Status :: 4 - Beta",
28
+ "Intended Audience :: Developers",
29
+ "Operating System :: OS Independent",
30
+ "Programming Language :: Python :: 3",
31
+ "Programming Language :: Python :: 3.10",
32
+ "Programming Language :: Python :: 3.11",
33
+ "Programming Language :: Python :: 3.12",
34
+ "Programming Language :: Python :: 3.13",
35
+ "Topic :: Office/Business",
36
+ "Topic :: Software Development :: Libraries :: Python Modules",
37
+ "Typing :: Typed",
38
+ ]
39
+ dependencies = [
40
+ "google-api-python-client>=2.0",
41
+ "google-auth>=2.0",
42
+ "google-auth-oauthlib>=1.0",
43
+ "defusedxml>=0.7",
44
+ ]
45
+
46
+ [project.optional-dependencies]
47
+ dev = ["pytest>=8.0", "pytest-cov>=5.0", "ruff>=0.6", "mypy>=1.11"]
48
+
49
+ [project.urls]
50
+ Homepage = "https://github.com/CloudSecurityAlliance/csa-google-workspace"
51
+ Repository = "https://github.com/CloudSecurityAlliance/csa-google-workspace"
52
+ Issues = "https://github.com/CloudSecurityAlliance/csa-google-workspace/issues"
53
+ Changelog = "https://github.com/CloudSecurityAlliance/csa-google-workspace/blob/main/CHANGELOG.md"
54
+
55
+ # Single source of truth for the version: csa_google_workspace.__version__
56
+ # (setuptools reads it by static AST parse; no need to import the package).
57
+ [tool.setuptools.dynamic]
58
+ version = { attr = "csa_google_workspace.__version__" }
59
+
60
+ [tool.setuptools.packages.find]
61
+ where = ["src"]
62
+
63
+ # Ship the PEP 561 marker so downstream mypy/pyright consume the inline type hints.
64
+ [tool.setuptools.package-data]
65
+ csa_google_workspace = ["py.typed"]
66
+
67
+ [tool.pytest.ini_options]
68
+ pythonpath = ["src"]
69
+ testpaths = ["tests"]
70
+
71
+ [tool.ruff]
72
+ line-length = 120
73
+ extend-exclude = ["experiments", "research", "docs"]
74
+
75
+ [tool.ruff.lint]
76
+ select = ["E", "F", "W", "I", "B", "UP"]
77
+ # E702 (multiple statements on one line via ';') is a deliberate, pervasive style in
78
+ # this codebase (e.g. `self.content = ...; self.html_content = ...`). Not a defect.
79
+ ignore = ["E702"]
80
+
81
+ [tool.mypy]
82
+ python_version = "3.10"
83
+ files = ["src"]
84
+ warn_unused_ignores = true
85
+ warn_redundant_casts = true
86
+ check_untyped_defs = true
87
+
88
+ # The google-api-python-client / google-auth stack ships no type stubs.
89
+ [[tool.mypy.overrides]]
90
+ module = ["googleapiclient.*", "google.*", "google_auth_oauthlib.*", "defusedxml.*"]
91
+ ignore_missing_imports = true
92
+
93
+ [tool.coverage.run]
94
+ source = ["csa_google_workspace"]
95
+ branch = true
96
+
97
+ [tool.coverage.report]
98
+ # Unit suite runs offline against FakeBackend; ApiBackend's real-Google calls and the
99
+ # interactive OAuth flow in auth.py are exercised by the gated integration suite, not here
100
+ # — hence a threshold below 100. Total sits ~87%.
101
+ exclude_lines = ["pragma: no cover", "raise NotImplementedError", "if TYPE_CHECKING:"]
102
+ fail_under = 85
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,19 @@
1
+ from . import exceptions # noqa: F401
2
+ from .backend import Backend
3
+ from .base import Document
4
+ from .comments import Author, Comment, CommentCollection, Location, Reply
5
+ from .documents.doc import Doc
6
+ from .documents.sheet import Sheet
7
+ from .documents.slides import Slide, Slides
8
+ from .exceptions import DetachedError
9
+ from .suggestions import Suggestion
10
+ from .workspace import Workspace
11
+
12
+ __all__ = [
13
+ "Workspace", "Doc", "Sheet", "Slides", "exceptions",
14
+ "Comment", "Author", "Reply", "Location",
15
+ "Suggestion", "Slide",
16
+ # load-bearing types for embedders / custom backends (audit #26)
17
+ "Backend", "Document", "CommentCollection", "DetachedError",
18
+ ]
19
+ __version__ = "0.1.0"