xippios-google-mail 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 (48) hide show
  1. xippios_google_mail-0.1.0/.gitignore +23 -0
  2. xippios_google_mail-0.1.0/CHANGELOG.md +114 -0
  3. xippios_google_mail-0.1.0/LICENSE +201 -0
  4. xippios_google_mail-0.1.0/PKG-INFO +208 -0
  5. xippios_google_mail-0.1.0/README.md +179 -0
  6. xippios_google_mail-0.1.0/docs/upstream/FETCHED.md +83 -0
  7. xippios_google_mail-0.1.0/docs/upstream/discovery.json +4524 -0
  8. xippios_google_mail-0.1.0/docs/upstream/pages/auth-scopes.md +115 -0
  9. xippios_google_mail-0.1.0/docs/upstream/pages/handle-errors.md +354 -0
  10. xippios_google_mail-0.1.0/docs/upstream/pages/oauth2-native-app.md +826 -0
  11. xippios_google_mail-0.1.0/docs/upstream/pages/oauth2-web-server.md +2594 -0
  12. xippios_google_mail-0.1.0/docs/upstream/pages/oauth2.md +372 -0
  13. xippios_google_mail-0.1.0/docs/upstream/pages/quota.md +255 -0
  14. xippios_google_mail-0.1.0/docs/upstream/pages/search-operators.md +55 -0
  15. xippios_google_mail-0.1.0/pyproject.toml +112 -0
  16. xippios_google_mail-0.1.0/src/xippios/google/mail/__init__.py +41 -0
  17. xippios_google_mail-0.1.0/src/xippios/google/mail/_account_lock.py +189 -0
  18. xippios_google_mail-0.1.0/src/xippios/google/mail/_auth.py +361 -0
  19. xippios_google_mail-0.1.0/src/xippios/google/mail/_cli.py +105 -0
  20. xippios_google_mail-0.1.0/src/xippios/google/mail/_client.py +358 -0
  21. xippios_google_mail-0.1.0/src/xippios/google/mail/_compose.py +225 -0
  22. xippios_google_mail-0.1.0/src/xippios/google/mail/_consent.py +303 -0
  23. xippios_google_mail-0.1.0/src/xippios/google/mail/_decode.py +172 -0
  24. xippios_google_mail-0.1.0/src/xippios/google/mail/_tenants.py +413 -0
  25. xippios_google_mail-0.1.0/src/xippios/google/mail/_version.py +10 -0
  26. xippios_google_mail-0.1.0/src/xippios/google/mail/api/__init__.py +36 -0
  27. xippios_google_mail-0.1.0/src/xippios/google/mail/api/drafts_create.py +49 -0
  28. xippios_google_mail-0.1.0/src/xippios/google/mail/api/drafts_delete.py +32 -0
  29. xippios_google_mail-0.1.0/src/xippios/google/mail/api/get_profile.py +28 -0
  30. xippios_google_mail-0.1.0/src/xippios/google/mail/api/labels_list.py +27 -0
  31. xippios_google_mail-0.1.0/src/xippios/google/mail/api/messages_attachments_get.py +44 -0
  32. xippios_google_mail-0.1.0/src/xippios/google/mail/api/messages_get.py +56 -0
  33. xippios_google_mail-0.1.0/src/xippios/google/mail/api/messages_list.py +55 -0
  34. xippios_google_mail-0.1.0/src/xippios/google/mail/api/messages_modify.py +52 -0
  35. xippios_google_mail-0.1.0/src/xippios/google/mail/api/messages_send.py +47 -0
  36. xippios_google_mail-0.1.0/src/xippios/google/mail/api/messages_trash.py +36 -0
  37. xippios_google_mail-0.1.0/src/xippios/google/mail/api/threads_get.py +52 -0
  38. xippios_google_mail-0.1.0/src/xippios/google/mail/enums.py +3 -0
  39. xippios_google_mail-0.1.0/src/xippios/google/mail/errors.py +11 -0
  40. xippios_google_mail-0.1.0/src/xippios/google/mail/http.py +18 -0
  41. xippios_google_mail-0.1.0/src/xippios/google/mail/mcp.py +54 -0
  42. xippios_google_mail-0.1.0/src/xippios/google/mail/mcp_write.py +58 -0
  43. xippios_google_mail-0.1.0/src/xippios/google/mail/models.py +546 -0
  44. xippios_google_mail-0.1.0/src/xippios/google/mail/params.py +12 -0
  45. xippios_google_mail-0.1.0/src/xippios/google/mail/py.typed +0 -0
  46. xippios_google_mail-0.1.0/src/xippios/google/mail/reference/README.md +13 -0
  47. xippios_google_mail-0.1.0/src/xippios/google/mail/tasks.py +336 -0
  48. xippios_google_mail-0.1.0/src/xippios/google/mail/tasks_write.py +446 -0
@@ -0,0 +1,23 @@
1
+ # environments and caches
2
+ .venv/
3
+ __pycache__/
4
+ *.py[cod]
5
+ .mypy_cache/
6
+ .ruff_cache/
7
+ .pytest_cache/
8
+ .hypothesis/
9
+
10
+ # build artefacts
11
+ dist/
12
+ build/
13
+ *.egg-info/
14
+
15
+ # local secrets are never files, but belt and braces
16
+ .env
17
+ .env.*
18
+ .envrc
19
+ .envrc.*
20
+
21
+ # editors
22
+ .idea/
23
+ .vscode/
@@ -0,0 +1,114 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project are documented here. The format follows
4
+ [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and the project uses
5
+ [Semantic Versioning](https://semver.org/) (pre-1.0: breaking changes bump the minor).
6
+
7
+ ## [Unreleased]
8
+
9
+ ## [0.1.0] - 2026-10-29
10
+
11
+ First release, on xippios-core 0.3.0 from PyPI (`~=0.3.0`), sdk-template v0.3.0 and the
12
+ family's conventions 1.23. It wraps the Gmail API for several Gmail accounts at once. The
13
+ environment names the operator's Desktop-app OAuth client (`GOOGLE_CLIENT_ID`,
14
+ `GOOGLE_CLIENT_SECRET`), the accounts (`GOOGLE_ACCOUNTS`) and one refresh token per
15
+ account (`GOOGLE_<NAME>_REFRESH_TOKEN`); the client renews each account's access token
16
+ in memory and writes nothing to disk, and the consent tool `xippios-google-mail-auth`
17
+ gets an account's refresh token, for reading (`gmail.readonly`) or for writing as well
18
+ (`gmail.modify`). Seven read tasks name the accounts and read an account's profile, its
19
+ labels, a page of message ids, the messages a search finds, one message's decoded view
20
+ and a thread's; they are the tools of the read server, `xippios-google-mail-mcp-read`,
21
+ and routes of the FastAPI router. Five write tasks store and delete a draft, send a
22
+ message, change a message's labels and move a message to the trash; each previews and
23
+ changes nothing unless it is called with `confirm=True`, and they are the tools of a
24
+ server of their own, `xippios-google-mail-mcp-write`, never routes. Either server runs on
25
+ stdio by default and, over `--http`, serves streamable HTTP on a loopback host only unless
26
+ `--allow-remote` is passed, since neither carries authentication. The client keeps a
27
+ self-imposed pace of 60 requests a minute per account. The documentation snapshot of
28
+ 2026-10-29 under `docs/upstream/`, Gmail's discovery document among it, is the reference
29
+ for names and semantics.
30
+
31
+ ### Added
32
+
33
+ - Scaffold from [sdk-template](https://github.com/xippios/sdk-template): configured
34
+ client for Gmail, empty task layer, MCP server and FastAPI router
35
+ wired to it, test harness with core's family check, CI, the nightly live tests and
36
+ the release train, in which a release PR's merge tags and publishes.
37
+ - The documentation snapshot in `docs/upstream/`, captured on 2026-10-29 by
38
+ `scripts/refresh_upstream.py`: Gmail's discovery document (revision 20261026, kept
39
+ with its keys sorted), the API's usage limits, errors and scopes, the Gmail Help
40
+ article on search operators, and Google's OAuth 2.0 overview with its guides for
41
+ desktop apps and web server applications, the pages as Markdown.
42
+ - README and CLAUDE.md name the credentials the API takes, an OAuth 2.0 bearer renewed
43
+ from a refresh token per account with the operator's Desktop-app client, where the
44
+ scaffold, rendered without a key, said none was needed; CLAUDE.md's rate-limit row
45
+ names upstream's quota, 6,000 units per minute per user per project, where it said
46
+ upstream documents no limit.
47
+ - Several Gmail accounts from the environment: `GOOGLE_ACCOUNTS` names them, one
48
+ `GOOGLE_<NAME>_REFRESH_TOKEN` each, and the test account `demo` is declared by
49
+ `GOOGLE_DEMO_REFRESH_TOKEN` alone. Each account has a client of its own, whose auth
50
+ exchanges the refresh token at Google's token endpoint with the operator's OAuth client
51
+ (`GOOGLE_CLIENT_ID`, `GOOGLE_CLIENT_SECRET`) and sends the access token as a bearer,
52
+ renewed in memory before it expires and once more on a 401; nothing is written to disk.
53
+ A revoked or expired refresh token is an `AuthError` that says how to consent again; a
54
+ client the token endpoint refuses is a `ConfigError` naming the two client variables.
55
+ - `xippios-google-mail-auth --account <name> [--scopes read|write]`, the consent tool
56
+ (`read` by default): a loopback redirect with PKCE that prints the account's refresh
57
+ token once and stores nothing.
58
+ - Gmail's error answers mapped: a spent per-minute or daily quota is a `RateLimitError`
59
+ (60 s, 3,600 s), a grant without the scope a call needs an `AuthError` naming the
60
+ scopes granted and the consent to re-run, a domain policy or a refused access token an
61
+ `AuthError`; each account's requests are paced at 60 a minute and held back for a
62
+ minute after a spent quota.
63
+ - `list_accounts`, the declared accounts by name, and `get_profile(account)`, the
64
+ account's address, message and thread counts and history id (`users.getProfile`).
65
+ - The read tasks on a mailbox, each with the account first: `list_labels`, the labels
66
+ whose ids `label_ids` takes (`users.labels.list`); `list_messages`, one page of message
67
+ and thread ids for a query in Gmail's own search syntax, sent verbatim, or for labels,
68
+ with upstream's `resultSizeEstimate` as data and no total (`users.messages.list`);
69
+ `search_messages`, at most 50 messages with their From, Subject, Date and snippet, a
70
+ list and one `format=metadata` call per message (5 + 20 quota units each);
71
+ `get_message`, one message's decoded view (`users.messages.get`, `format=full`): its
72
+ From, To, Cc, Bcc, Date, Subject, Message-ID, In-Reply-To and References headers, the
73
+ first plain-text part decoded in its charset, the first HTML part on request
74
+ (`include_html`), and its attachments' metadata, never their content, a message over
75
+ the MCP result cap coming back as its first 64 KB with a note saying so; and
76
+ `get_thread`, the views of a thread's messages as text (`users.threads.get`,
77
+ `format=full`), from `start` and at most `limit`, a cut answer ending with where to
78
+ resume.
79
+ - Endpoint wrappers for `users.labels.list`, `users.messages.list`, `users.messages.get`,
80
+ `users.threads.get` and `users.messages.attachments.get`, the last without a task, and
81
+ faithful models of their answers, the whole MIME tree of a message among them.
82
+ - The read server's entry point is `xippios-google-mail-mcp-read`, as the family names
83
+ the servers of a source with a write server; the write server has an entry point of
84
+ its own. It is served over `--http` on a loopback `--host` only, unless
85
+ `--allow-remote` is passed: it reaches every declared mailbox and carries no
86
+ authentication.
87
+ - `--account <name>` binds either server, the read or the write one, to one account:
88
+ every tool acts on it and takes no `account`.
89
+ - The write tools, on a server of their own, `xippios-google-mail-mcp-write`, which
90
+ takes `--account` too and is served over `--http` on a loopback `--host` only unless
91
+ `--allow-remote` is passed: `create_draft` and `send_message` build a plain-text
92
+ message in UTF-8 (To, Cc, Bcc and Subject; From is Gmail's) and store it as a draft
93
+ (`users.drafts.create`) or send it (`users.messages.send`), a reply joining the
94
+ original's conversation with its thread, In-Reply-To and References; `delete_draft`
95
+ deletes a draft permanently (`users.drafts.delete`); `modify_message` adds and removes
96
+ a message's labels (`users.messages.modify`); `trash_message` moves a message to the
97
+ trash (`users.messages.trash`). Every one previews and changes nothing unless called
98
+ with `confirm=True`: a message's headers and first lines, or the draft or message and
99
+ the labels; confirmed, it returns Gmail's answer, and `delete_draft`, which Gmail
100
+ answers without a body, an acknowledgement of its own, `{"performed": true, "id"}`.
101
+ They need an account consented with `--scopes write`, are re-exported from
102
+ `xippios.google.mail` and are no HTTP routes; a result's request echo never carries
103
+ the message's text.
104
+ - The fixture recorder records through a read task and scrubs a message or thread answer
105
+ as JSON before it writes: headers cut to an allowlist on every part, Message-ID,
106
+ In-Reply-To and References numbered `<n@example.com>`, display names in the address
107
+ headers replaced by `User`, every body decoded, its addresses replaced and encoded
108
+ again, attachment ids numbered, a profile-picture URL redacted and the raw message
109
+ never kept; its final check reads the decoded bodies too.
110
+ - The fixture recorder records the write tools under a safety rule: the demo account
111
+ writes to its own address only, read from its profile when it records, every message
112
+ it writes carries `xippios-live` in its subject, and the raw message a write sends is
113
+ dropped from the recorded request; the live tests follow the same rule and clean up
114
+ what they write.
@@ -0,0 +1,201 @@
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 [yyyy] [name of copyright owner]
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.
@@ -0,0 +1,208 @@
1
+ Metadata-Version: 2.5
2
+ Name: xippios-google-mail
3
+ Version: 0.1.0
4
+ Summary: Typed client, MCP tools and HTTP routes for Gmail
5
+ Project-URL: Homepage, https://github.com/xippios/sdk-google-mail
6
+ Project-URL: Upstream, https://developers.google.com/workspace/gmail/api
7
+ Project-URL: Changelog, https://github.com/xippios/sdk-google-mail/blob/main/CHANGELOG.md
8
+ Project-URL: Issues, https://github.com/xippios/sdk-google-mail/issues
9
+ Author: XIPPIOS GmbH
10
+ License-Expression: Apache-2.0
11
+ License-File: LICENSE
12
+ Keywords: google-mail,httpx,mcp,pydantic,sdk
13
+ Classifier: Development Status :: 3 - Alpha
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Programming Language :: Python :: 3.14
19
+ Classifier: Typing :: Typed
20
+ Requires-Python: >=3.12
21
+ Requires-Dist: xippios-core~=0.3.0
22
+ Provides-Extra: http
23
+ Requires-Dist: xippios-core[http]~=0.3.0; extra == 'http'
24
+ Provides-Extra: mcp
25
+ Requires-Dist: xippios-core[mcp]~=0.3.0; extra == 'mcp'
26
+ Provides-Extra: testing
27
+ Requires-Dist: xippios-core[testing]~=0.3.0; extra == 'testing'
28
+ Description-Content-Type: text/markdown
29
+
30
+ # xippios-google-mail
31
+
32
+ Typed Python client, MCP server and FastAPI routes for
33
+ [Gmail](https://developers.google.com/workspace/gmail/api), part of the
34
+ [xippios SDK family](https://github.com/xippios). Names and semantics follow the
35
+ upstream documentation; every response carries release metadata (source, endpoint,
36
+ retrieved_at, published_at, vintage).
37
+
38
+ ## Install
39
+
40
+ ```bash
41
+ uv add xippios-google-mail # client only
42
+ uv add "xippios-google-mail[mcp]" # + MCP server
43
+ uv add "xippios-google-mail[http]" # + FastAPI router
44
+ ```
45
+
46
+ The API takes an OAuth 2.0 bearer token, which the package renews in memory from a
47
+ refresh token per Gmail account and never writes to disk. The environment names the
48
+ operator's Desktop-app OAuth client, `GOOGLE_CLIENT_ID` and `GOOGLE_CLIENT_SECRET`, the
49
+ accounts, `GOOGLE_ACCOUNTS` (`work,private`), and one `GOOGLE_<NAME>_REFRESH_TOKEN` per
50
+ account (the test account `demo` is declared by `GOOGLE_DEMO_REFRESH_TOKEN` alone and
51
+ never listed). Every task takes the account's name first; `list_accounts` names the
52
+ declared ones.
53
+
54
+ A refresh token comes from the consent tool, which listens on `http://127.0.0.1:<port>/`,
55
+ prints the authorization URL to open in a browser signed in to the account, and prints the
56
+ refresh token once, to stdout; it stores nothing:
57
+
58
+ ```bash
59
+ uvx --from xippios-google-mail xippios-google-mail-auth --account work # --scopes read: gmail.readonly
60
+ uvx --from xippios-google-mail xippios-google-mail-auth --account work --scopes write # gmail.modify, every read too
61
+ xippios-google-mail-auth --account work # the same, where xippios-google-mail is installed
62
+ ```
63
+
64
+ ## 30-second example
65
+
66
+ ```python
67
+ from xippios.google.mail import tasks
68
+
69
+ tasks.list_accounts().data # ["work", "private"]
70
+ result = tasks.get_profile("work")
71
+ result.data.messages_total, result.meta.tenant, result.meta.retrieved_at
72
+
73
+ found = tasks.search_messages("work", "from:alice@example.com newer_than:7d", max_results=5)
74
+ [(row.from_, row.subject, row.date) for row in found.data]
75
+ message = tasks.get_message("work", found.data[0].id).data
76
+ message.headers, message.text, message.attachments # the decoded view; html on request
77
+ ```
78
+
79
+ `q` is Gmail's own search syntax, sent as given. `get_message` returns a decoded view of
80
+ the message: its From, To, Cc, Bcc, Date, Subject, Message-ID, In-Reply-To and References
81
+ headers, the first plain-text part decoded, the first HTML part with `include_html=True`,
82
+ and its attachments' names, types and sizes, never their content. `get_thread` returns
83
+ the same view of each message in a thread, as text.
84
+
85
+ The write tasks, in `xippios.google.mail.tasks_write` (re-exported from
86
+ `xippios.google.mail`), need an account consented with `--scopes write`, and each
87
+ previews unless called with `confirm=True`:
88
+
89
+ ```python
90
+ from xippios.google.mail import tasks_write
91
+
92
+ preview = tasks_write.send_message("work", ["alice@example.com"], "Lunch on Friday", "See you!")
93
+ preview.data.headers, preview.data.body_lines # nothing was sent
94
+ sent = tasks_write.send_message(
95
+ "work", ["alice@example.com"], "Lunch on Friday", "See you!", confirm=True
96
+ )
97
+ sent.data.id, sent.data.label_ids # upstream's answer: ["SENT"], ...
98
+ ```
99
+
100
+ The read and write tasks are listed in the status table below.
101
+
102
+ ## MCP
103
+
104
+ ```json
105
+ {
106
+ "mcpServers": {
107
+ "google-mail": {
108
+ "command": "uvx",
109
+ "args": ["--from", "xippios-google-mail[mcp]", "xippios-google-mail-mcp-read"],
110
+ "env": {
111
+ "GOOGLE_CLIENT_ID": "<client id>.apps.googleusercontent.com",
112
+ "GOOGLE_CLIENT_SECRET": "<client secret>",
113
+ "GOOGLE_ACCOUNTS": "work,private",
114
+ "GOOGLE_WORK_REFRESH_TOKEN": "<refresh token>",
115
+ "GOOGLE_PRIVATE_REFRESH_TOKEN": "<refresh token>"
116
+ }
117
+ }
118
+ }
119
+ }
120
+ ```
121
+
122
+ The refresh tokens come from the consent tool above, one per account; a deployment that
123
+ serves one account can pass `--account work` in `args` and declare that account alone
124
+ (`"GOOGLE_ACCOUNTS": "work"` and its token) instead of listing several.
125
+
126
+ The read server's tools are read-only and named `google_mail_<verb>_<noun>`. Results are capped, at
127
+ 200 rows or 64 KB unless a tool has a cap of its own, with a note on how to see the rest.
128
+ `google_mail_search_messages` reads at most 50 messages a call (a list and one call per
129
+ message, 5 + 20 quota units each), and `google_mail_get_thread` reads a long thread in
130
+ parts with `start` and `limit`: a cut answer ends with where to resume.
131
+ `google_mail_get_message` returns a message over the cap as its first 64 KB with a note:
132
+ `include_html=False` leaves the HTML out, and the rest is read in a mail client.
133
+ `--account <name>` binds the server to one account: every tool acts on it and takes no
134
+ `account`. `--http` serves streamable HTTP instead of stdio, on a loopback `--host` only
135
+ (`127.0.0.1`, `localhost`, `::1`): the server reaches every declared mailbox and carries no
136
+ authentication, so serving it beyond loopback takes `--allow-remote` and a gateway in front.
137
+
138
+ The write tools run in a server of their own, `xippios-google-mail-mcp-write`, so a
139
+ client of the read server never sees one; it takes `--account` too, and core holds it to
140
+ a loopback `--host` over `--http` unless `--allow-remote` is passed:
141
+
142
+ ```json
143
+ {
144
+ "mcpServers": {
145
+ "google-mail-write": {
146
+ "command": "uvx",
147
+ "args": ["--from", "xippios-google-mail[mcp]", "xippios-google-mail-mcp-write"],
148
+ "env": {
149
+ "GOOGLE_CLIENT_ID": "<client id>.apps.googleusercontent.com",
150
+ "GOOGLE_CLIENT_SECRET": "<client secret>",
151
+ "GOOGLE_ACCOUNTS": "work,private",
152
+ "GOOGLE_WORK_REFRESH_TOKEN": "<refresh token>",
153
+ "GOOGLE_PRIVATE_REFRESH_TOKEN": "<refresh token>"
154
+ }
155
+ }
156
+ }
157
+ }
158
+ ```
159
+
160
+ Its refresh tokens come from `xippios-google-mail-auth --scopes write`; a deployment that
161
+ only reads keeps the default `read` grant, which cannot change a mailbox.
162
+
163
+ Five write tools store a draft (`google_mail_create_draft`), delete one
164
+ (`google_mail_delete_draft`), send a message (`google_mail_send_message`), change a
165
+ message's labels (`google_mail_modify_message`) and move a message to the trash
166
+ (`google_mail_trash_message`). Every one returns a preview and changes nothing unless it
167
+ is called with `confirm=true`: a message's preview shows its To, Cc, Bcc, Subject,
168
+ In-Reply-To and References and the body's first 10 lines, the others name the draft or
169
+ the message and the labels. Confirmed, a tool returns Gmail's answer: the draft, or the
170
+ message with its labels; `google_mail_delete_draft`, which Gmail answers without a body,
171
+ returns the package's acknowledgement, `{"performed": true, "id": "<the draft's id>"}`.
172
+ A message is plain text in UTF-8, and Gmail sets From to the
173
+ account's address; a reply (`in_reply_to_message_id`) joins the original's conversation
174
+ and reads the original's headers first, its preview too. The write tools are no HTTP
175
+ routes.
176
+
177
+ ## Status
178
+
179
+ <!-- Core's family check (tests/test_family.py) reads this table: keep the "## Status"
180
+ heading and the "Task function" column. Each row's Task function cell starts with the
181
+ task's name in backticks, alone or as its call (`get_data(code, year)`); several tasks in
182
+ one row are backticked names separated by commas; prose may follow. The tables list
183
+ exactly tasks.__all__ and tasks_write.__all__. -->
184
+
185
+ | Upstream operation | Task function | MCP tool | Status |
186
+ | --- | --- | --- | --- |
187
+ | none: the declared accounts | `list_accounts` | `google_mail_list_accounts` | available; names only, no request |
188
+ | `GET gmail/v1/users/{userId}/profile` (`users.getProfile`) | `get_profile(account)` | `google_mail_get_profile` | available; `userId` `me`, the account's own |
189
+ | `GET gmail/v1/users/{userId}/labels` (`users.labels.list`) | `list_labels(account)` | `google_mail_list_labels` | available; the label ids `label_ids` takes |
190
+ | `GET gmail/v1/users/{userId}/messages` (`users.messages.list`) | `list_messages(account, q=None, label_ids=None, max_results=None, page_token=None, include_spam_trash=False)` | `google_mail_list_messages` | available; ids only, one page; `q` in Gmail's search syntax, verbatim; `result_size_estimate` upstream's estimate, `meta.total` `None` |
191
+ | `users.messages.list`, then `GET gmail/v1/users/{userId}/messages/{id}` (`users.messages.get`, `format=metadata`) per id | `search_messages(account, q, label_ids=None, max_results=20)` | `google_mail_search_messages` | available; From, Subject, Date and snippet per message; `max_results` at most 50 (5 + 20 quota units a message) |
192
+ | `GET gmail/v1/users/{userId}/messages/{id}` (`users.messages.get`, `format=full`) | `get_message(account, message_id, include_html=False)` | `google_mail_get_message` | available; the decoded view: nine headers, the plain text, the HTML on request, the attachments' metadata (no content) |
193
+ | `GET gmail/v1/users/{userId}/threads/{id}` (`users.threads.get`, `format=full`) | `get_thread(account, thread_id, start=0, limit=None)` | `google_mail_get_thread` | available; each message's decoded view, text only; `start` and `limit` read a long thread in parts |
194
+ | `POST gmail/v1/users/{userId}/drafts` (`users.drafts.create`) | `create_draft(account, to, subject, body, cc=None, bcc=None, in_reply_to_message_id=None, confirm=False)` | `google_mail_create_draft` (write server) | available; a preview unless `confirm=True`; a reply reads the original's headers (`users.messages.get`, `format=metadata`) |
195
+ | `DELETE gmail/v1/users/{userId}/drafts/{id}` (`users.drafts.delete`) | `delete_draft(account, draft_id, confirm=False)` | `google_mail_delete_draft` (write server) | available; a preview unless `confirm=True`; deleted permanently, not trashed |
196
+ | `POST gmail/v1/users/{userId}/messages/send` (`users.messages.send`) | `send_message(account, to, subject, body, cc=None, bcc=None, in_reply_to_message_id=None, confirm=False)` | `google_mail_send_message` (write server) | available; a preview unless `confirm=True`; plain text in UTF-8, From set by Gmail |
197
+ | `POST gmail/v1/users/{userId}/messages/{id}/modify` (`users.messages.modify`) | `modify_message(account, message_id, add_label_ids=None, remove_label_ids=None, confirm=False)` | `google_mail_modify_message` (write server) | available; a preview unless `confirm=True`; label ids only, 100 each at most |
198
+ | `POST gmail/v1/users/{userId}/messages/{id}/trash` (`users.messages.trash`) | `trash_message(account, message_id, confirm=False)` | `google_mail_trash_message` (write server) | available; a preview unless `confirm=True` |
199
+
200
+ ## Upstream terms and attribution
201
+
202
+ Data comes from Gmail (https://developers.google.com/workspace/gmail/api), on whatever terms upstream
203
+ states for it, if any; this package adds no rights to it. Documentation snapshot and its
204
+ attribution: `docs/upstream/FETCHED.md`.
205
+
206
+ ## Licence
207
+
208
+ Apache-2.0. See [LICENSE](LICENSE).