cherami 0.1.0__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.
cherami/__init__.py ADDED
@@ -0,0 +1,16 @@
1
+ """Official synchronous and asynchronous Cherami HTTP clients."""
2
+ from . import models as models
3
+ from ._operations import AsyncCherami as AsyncCherami, Cherami as Cherami
4
+ from ._transport import (
5
+ ApiResponse as ApiResponse,
6
+ CheramiApiError as CheramiApiError,
7
+ CheramiTransportError as CheramiTransportError,
8
+ )
9
+ from .attachments import attachment as attachment, attachment_bytes as attachment_bytes
10
+ from .recovery import (
11
+ PreparedSend as PreparedSend,
12
+ SendOperation as SendOperation,
13
+ SendRecoveryExpiredError as SendRecoveryExpiredError,
14
+ prepare_send as prepare_send,
15
+ restore_send as restore_send,
16
+ )
cherami/_client.py ADDED
@@ -0,0 +1,187 @@
1
+ """Connection lifetime and lazy pagination over shared wire/recovery policies."""
2
+ from __future__ import annotations
3
+
4
+ from collections.abc import AsyncIterator, Iterator
5
+ from copy import deepcopy
6
+ from typing import Any, Self
7
+
8
+ import httpx
9
+
10
+ from . import models
11
+ from ._routes import PAGE_FIELDS, ROUTES
12
+ from ._transport import (
13
+ ApiResponse, DEFAULT_TIMEOUT, Route, Timeout, WirePolicy,
14
+ decode_response, envelope, is_download, transport_error,
15
+ )
16
+ from .recovery import PreparedSend, check_send_window, restore_send
17
+
18
+
19
+ def _pagination(operation: str, params: Any, max_pages: int | None) -> tuple[dict[str, Any], str | None, set[str]]:
20
+ if operation not in PAGE_FIELDS:
21
+ raise ValueError("Operation is not paginated.")
22
+ if max_pages is not None and (type(max_pages) is not int or max_pages < 1):
23
+ raise ValueError("max_pages must be a positive integer or None.")
24
+ if not isinstance(params, dict):
25
+ raise TypeError("Supply a parameter dictionary.")
26
+ # This runs when the iterator is obtained, not on its first advancement.
27
+ # Caller mutations during a pause cannot change the query's meaning.
28
+ snapshot = deepcopy(params)
29
+ cursor = snapshot.get("cursor")
30
+ if cursor is not None and (not isinstance(cursor, str) or not cursor):
31
+ raise ValueError("Invalid pagination cursor.")
32
+ return snapshot, cursor, {cursor} if cursor else set()
33
+
34
+
35
+ def _next_page(result: ApiResponse[Any], seen: set[str]) -> str | None:
36
+ if "next_cursor" not in result.data:
37
+ raise ValueError("Missing pagination cursor; inspect the response before restarting.")
38
+ cursor = result.data["next_cursor"]
39
+ if cursor is not None:
40
+ if not isinstance(cursor, str) or not cursor or cursor in seen:
41
+ raise ValueError("Invalid or repeated pagination cursor; inspect the response before restarting.")
42
+ seen.add(cursor)
43
+ return cursor
44
+
45
+
46
+ def _items(result: ApiResponse[Any], operation: str) -> list[Any]:
47
+ items = result.data.get(PAGE_FIELDS[operation])
48
+ if not isinstance(items, list):
49
+ raise ValueError("Invalid paginated collection in Cherami response.")
50
+ return items
51
+
52
+
53
+ def _intent(prepared: PreparedSend) -> PreparedSend:
54
+ # Even direct construction of PreparedSend cannot bypass record validation.
55
+ record = restore_send(prepared.to_json())
56
+ check_send_window(record)
57
+ return record
58
+
59
+
60
+ class SyncClient:
61
+ def __init__(self, api_key: str, *, base_url: str = "https://cherami.to", timeout: float | None = 60.0, transport: httpx.BaseTransport | None = None):
62
+ """Use an existing approved key. Custom transports must not retry writes.
63
+
64
+ timeout is HTTPX's per-operation inactivity timeout, in seconds; None
65
+ disables it. Environment proxies and implicit redirects are disabled.
66
+ """
67
+ self._wire = WirePolicy(api_key, base_url, timeout)
68
+ self._http = httpx.Client(follow_redirects=False, trust_env=False, transport=transport)
69
+
70
+ def __enter__(self) -> Self:
71
+ self._http.__enter__()
72
+ return self
73
+
74
+ def __exit__(self, *args: Any) -> None:
75
+ self.close()
76
+
77
+ def close(self) -> None:
78
+ self._http.close()
79
+
80
+ def _request(self, route: Route, params: Any, *, timeout: Timeout = DEFAULT_TIMEOUT) -> ApiResponse[Any]:
81
+ request = self._http.build_request(**self._wire.request_parts(route, params, timeout))
82
+ response = None
83
+ download = False
84
+ try:
85
+ # One request only. Always stream initially so binary bodies belong to
86
+ # the caller; JSON/error bodies are consumed and closed here instead.
87
+ response = self._http.send(request, stream=True, follow_redirects=False)
88
+ download = is_download(route, response)
89
+ if download:
90
+ return envelope(response, response)
91
+ response.read()
92
+ return decode_response(route, response)
93
+ except httpx.HTTPError as cause:
94
+ raise transport_error(response) from cause
95
+ finally:
96
+ if response is not None and not download:
97
+ response.close()
98
+
99
+ def submit(self, prepared: PreparedSend, *, timeout: Timeout = DEFAULT_TIMEOUT) -> ApiResponse[models.SendReceipt]:
100
+ """Submit/recover a persisted intent once, without extending its window."""
101
+ record = _intent(prepared)
102
+ return self._request(ROUTES[record.operation], record.params, timeout=timeout)
103
+
104
+ def _pages(self, operation: str, params: Any, *, max_pages: int | None, timeout: Timeout) -> Iterator[ApiResponse[Any]]:
105
+ snapshot, cursor, seen = _pagination(operation, params, max_pages)
106
+
107
+ def generate() -> Iterator[ApiResponse[Any]]:
108
+ nonlocal cursor
109
+ count = 0
110
+ while max_pages is None or count < max_pages:
111
+ query = {**snapshot, **({"cursor": cursor} if cursor is not None else {})}
112
+ result = self._request(ROUTES[operation], query, timeout=timeout)
113
+ cursor = _next_page(result, seen)
114
+ yield result
115
+ count += 1
116
+ if cursor is None:
117
+ return
118
+ return generate()
119
+
120
+ def _iterate(self, operation: str, params: Any, *, max_pages: int | None, timeout: Timeout) -> Iterator[Any]:
121
+ pages = self._pages(operation, params, max_pages=max_pages, timeout=timeout)
122
+ return (item for result in pages for item in _items(result, operation))
123
+
124
+
125
+ class AsyncClient:
126
+ def __init__(self, api_key: str, *, base_url: str = "https://cherami.to", timeout: float | None = 60.0, transport: httpx.AsyncBaseTransport | None = None):
127
+ """Async I/O using the same policies and models as Cherami. No retries."""
128
+ self._wire = WirePolicy(api_key, base_url, timeout)
129
+ self._http = httpx.AsyncClient(follow_redirects=False, trust_env=False, transport=transport)
130
+
131
+ async def __aenter__(self) -> Self:
132
+ await self._http.__aenter__()
133
+ return self
134
+
135
+ async def __aexit__(self, *args: Any) -> None:
136
+ await self.aclose()
137
+
138
+ async def aclose(self) -> None:
139
+ await self._http.aclose()
140
+
141
+ async def _request(self, route: Route, params: Any, *, timeout: Timeout = DEFAULT_TIMEOUT) -> ApiResponse[Any]:
142
+ request = self._http.build_request(**self._wire.request_parts(route, params, timeout))
143
+ response = None
144
+ download = False
145
+ try:
146
+ response = await self._http.send(request, stream=True, follow_redirects=False)
147
+ download = is_download(route, response)
148
+ if download:
149
+ return envelope(response, response)
150
+ await response.aread()
151
+ return decode_response(route, response)
152
+ except httpx.HTTPError as cause:
153
+ raise transport_error(response) from cause
154
+ finally:
155
+ if response is not None and not download:
156
+ await response.aclose()
157
+ # Cancellation (including asyncio.CancelledError) deliberately propagates
158
+ # rather than being swallowed or retried. It cannot undo a submitted write.
159
+
160
+ async def submit(self, prepared: PreparedSend, *, timeout: Timeout = DEFAULT_TIMEOUT) -> ApiResponse[models.SendReceipt]:
161
+ record = _intent(prepared)
162
+ return await self._request(ROUTES[record.operation], record.params, timeout=timeout)
163
+
164
+ def _pages(self, operation: str, params: Any, *, max_pages: int | None, timeout: Timeout) -> AsyncIterator[ApiResponse[Any]]:
165
+ snapshot, cursor, seen = _pagination(operation, params, max_pages)
166
+
167
+ async def generate() -> AsyncIterator[ApiResponse[Any]]:
168
+ nonlocal cursor
169
+ count = 0
170
+ while max_pages is None or count < max_pages:
171
+ query = {**snapshot, **({"cursor": cursor} if cursor is not None else {})}
172
+ result = await self._request(ROUTES[operation], query, timeout=timeout)
173
+ cursor = _next_page(result, seen)
174
+ yield result
175
+ count += 1
176
+ if cursor is None:
177
+ return
178
+ return generate()
179
+
180
+ def _iterate(self, operation: str, params: Any, *, max_pages: int | None, timeout: Timeout) -> AsyncIterator[Any]:
181
+ pages = self._pages(operation, params, max_pages=max_pages, timeout=timeout)
182
+
183
+ async def generate() -> AsyncIterator[Any]:
184
+ async for result in pages:
185
+ for item in _items(result, operation):
186
+ yield item
187
+ return generate()
cherami/_operations.py ADDED
@@ -0,0 +1,383 @@
1
+ # Generated from openapi.json by bun scripts/generate.mts. Do not edit.
2
+ from collections.abc import AsyncIterator, Iterator
3
+ from typing import Any, Literal, overload
4
+ import httpx
5
+ from . import models
6
+ from ._transport import ApiResponse, DEFAULT_TIMEOUT, Timeout
7
+ from ._client import SyncClient, AsyncClient
8
+ from ._routes import ROUTES
9
+
10
+ class Cherami(SyncClient):
11
+ def list_inboxes(self, *, timeout: Timeout = DEFAULT_TIMEOUT) -> ApiResponse[models.ListInboxesResult]:
12
+ """List inboxes. See the HTTP reference for state/recovery semantics."""
13
+ return self._request(ROUTES["list_inboxes"], {}, timeout=timeout)
14
+
15
+ def create_inbox(self, params: models.CreateInboxParams, *, timeout: Timeout = DEFAULT_TIMEOUT) -> ApiResponse[models.CreateInboxResult]:
16
+ """Create an inbox. See the HTTP reference for state/recovery semantics."""
17
+ return self._request(ROUTES["create_inbox"], params, timeout=timeout)
18
+
19
+ def get_inbox(self, params: models.GetInboxParams, *, timeout: Timeout = DEFAULT_TIMEOUT) -> ApiResponse[models.GetInboxResult]:
20
+ """Read an inbox. See the HTTP reference for state/recovery semantics."""
21
+ return self._request(ROUTES["get_inbox"], params, timeout=timeout)
22
+
23
+ def update_inbox(self, params: models.UpdateInboxParams, *, timeout: Timeout = DEFAULT_TIMEOUT) -> ApiResponse[models.UpdateInboxResult]:
24
+ """Edit inbox names. See the HTTP reference for state/recovery semantics."""
25
+ return self._request(ROUTES["update_inbox"], params, timeout=timeout)
26
+
27
+ def delete_inbox(self, params: models.DeleteInboxParams, *, timeout: Timeout = DEFAULT_TIMEOUT) -> ApiResponse[models.DeleteInboxResult]:
28
+ """Delete an inbox. See the HTTP reference for state/recovery semantics."""
29
+ return self._request(ROUTES["delete_inbox"], params, timeout=timeout)
30
+
31
+ def get_sending_policy(self, params: models.GetSendingPolicyParams, *, timeout: Timeout = DEFAULT_TIMEOUT) -> ApiResponse[models.GetSendingPolicyResult]:
32
+ """Inspect sending rules. See the HTTP reference for state/recovery semantics."""
33
+ return self._request(ROUTES["get_sending_policy"], params, timeout=timeout)
34
+
35
+ def get_receiving_policy(self, params: models.GetReceivingPolicyParams, *, timeout: Timeout = DEFAULT_TIMEOUT) -> ApiResponse[models.GetReceivingPolicyResult]:
36
+ """Inspect receiving rules. See the HTTP reference for state/recovery semantics."""
37
+ return self._request(ROUTES["get_receiving_policy"], params, timeout=timeout)
38
+
39
+ def list_messages(self, params: models.ListMessagesParams, *, timeout: Timeout = DEFAULT_TIMEOUT) -> ApiResponse[models.ListMessagesResult]:
40
+ """List received messages. See the HTTP reference for state/recovery semantics."""
41
+ return self._request(ROUTES["list_messages"], params, timeout=timeout)
42
+
43
+ def count_messages(self, params: models.CountMessagesParams, *, timeout: Timeout = DEFAULT_TIMEOUT) -> ApiResponse[models.CountMessagesResult]:
44
+ """Count received messages. See the HTTP reference for state/recovery semantics."""
45
+ return self._request(ROUTES["count_messages"], params, timeout=timeout)
46
+
47
+ def get_message(self, params: models.GetMessageParams, *, timeout: Timeout = DEFAULT_TIMEOUT) -> ApiResponse[models.GetMessageResult]:
48
+ """Read a received message. See the HTTP reference for state/recovery semantics."""
49
+ return self._request(ROUTES["get_message"], params, timeout=timeout)
50
+
51
+ def delete_message(self, params: models.DeleteMessageParams, *, timeout: Timeout = DEFAULT_TIMEOUT) -> ApiResponse[models.DeleteMessageResult]:
52
+ """Delete a received message. See the HTTP reference for state/recovery semantics."""
53
+ return self._request(ROUTES["delete_message"], params, timeout=timeout)
54
+
55
+ def update_message_labels(self, params: models.UpdateMessageLabelsParams, *, timeout: Timeout = DEFAULT_TIMEOUT) -> ApiResponse[models.UpdateMessageLabelsResult]:
56
+ """Label a received message. See the HTTP reference for state/recovery semantics."""
57
+ return self._request(ROUTES["update_message_labels"], params, timeout=timeout)
58
+
59
+ def download_raw_message(self, params: models.DownloadRawMessageParams, *, timeout: Timeout = DEFAULT_TIMEOUT) -> ApiResponse[httpx.Response]:
60
+ """Download raw MIME. See the HTTP reference for state/recovery semantics."""
61
+ return self._request(ROUTES["download_raw_message"], params, timeout=timeout)
62
+
63
+ def download_attachment(self, params: models.DownloadAttachmentParams, *, timeout: Timeout = DEFAULT_TIMEOUT) -> ApiResponse[httpx.Response]:
64
+ """Download a received attachment. See the HTTP reference for state/recovery semantics."""
65
+ return self._request(ROUTES["download_attachment"], params, timeout=timeout)
66
+
67
+ def delete_sent_message(self, params: models.DeleteSentMessageParams, *, timeout: Timeout = DEFAULT_TIMEOUT) -> ApiResponse[models.DeleteSentMessageResult]:
68
+ """Delete a sent copy. See the HTTP reference for state/recovery semantics."""
69
+ return self._request(ROUTES["delete_sent_message"], params, timeout=timeout)
70
+
71
+ def update_sent_message_labels(self, params: models.UpdateSentMessageLabelsParams, *, timeout: Timeout = DEFAULT_TIMEOUT) -> ApiResponse[models.UpdateSentMessageLabelsResult]:
72
+ """Label a sent copy. See the HTTP reference for state/recovery semantics."""
73
+ return self._request(ROUTES["update_sent_message_labels"], params, timeout=timeout)
74
+
75
+ def get_sent_message(self, params: models.GetSentMessageParams, *, timeout: Timeout = DEFAULT_TIMEOUT) -> ApiResponse[models.GetSentMessageResult]:
76
+ """Read a sent message. See the HTTP reference for state/recovery semantics."""
77
+ return self._request(ROUTES["get_sent_message"], params, timeout=timeout)
78
+
79
+ def bulk_update_message_labels(self, params: models.BulkUpdateMessageLabelsParams, *, timeout: Timeout = DEFAULT_TIMEOUT) -> ApiResponse[models.BulkUpdateMessageLabelsResult]:
80
+ """Label several received messages. See the HTTP reference for state/recovery semantics."""
81
+ return self._request(ROUTES["bulk_update_message_labels"], params, timeout=timeout)
82
+
83
+ def bulk_update_sent_labels(self, params: models.BulkUpdateSentLabelsParams, *, timeout: Timeout = DEFAULT_TIMEOUT) -> ApiResponse[models.BulkUpdateSentLabelsResult]:
84
+ """Label several sent copies. See the HTTP reference for state/recovery semantics."""
85
+ return self._request(ROUTES["bulk_update_sent_labels"], params, timeout=timeout)
86
+
87
+ def list_labels(self, params: models.ListLabelsParams, *, timeout: Timeout = DEFAULT_TIMEOUT) -> ApiResponse[models.ListLabelsResult]:
88
+ """Discover labels. See the HTTP reference for state/recovery semantics."""
89
+ return self._request(ROUTES["list_labels"], params, timeout=timeout)
90
+
91
+ def send_message(self, params: models.SendMessageParams, *, timeout: Timeout = DEFAULT_TIMEOUT) -> ApiResponse[models.SendMessageResult]:
92
+ """Send a message. See the HTTP reference for state/recovery semantics."""
93
+ return self._request(ROUTES["send_message"], params, timeout=timeout)
94
+
95
+ def list_sent_messages(self, params: models.ListSentMessagesParams, *, timeout: Timeout = DEFAULT_TIMEOUT) -> ApiResponse[models.ListSentMessagesResult]:
96
+ """List sent messages. See the HTTP reference for state/recovery semantics."""
97
+ return self._request(ROUTES["list_sent_messages"], params, timeout=timeout)
98
+
99
+ def reply_message(self, params: models.ReplyMessageParams, *, timeout: Timeout = DEFAULT_TIMEOUT) -> ApiResponse[models.ReplyMessageResult]:
100
+ """Reply to a message. See the HTTP reference for state/recovery semantics."""
101
+ return self._request(ROUTES["reply_message"], params, timeout=timeout)
102
+
103
+ def reply_all_message(self, params: models.ReplyAllMessageParams, *, timeout: Timeout = DEFAULT_TIMEOUT) -> ApiResponse[models.ReplyAllMessageResult]:
104
+ """Reply to visible participants. See the HTTP reference for state/recovery semantics."""
105
+ return self._request(ROUTES["reply_all_message"], params, timeout=timeout)
106
+
107
+ def forward_message(self, params: models.ForwardMessageParams, *, timeout: Timeout = DEFAULT_TIMEOUT) -> ApiResponse[models.ForwardMessageResult]:
108
+ """Forward a message. See the HTTP reference for state/recovery semantics."""
109
+ return self._request(ROUTES["forward_message"], params, timeout=timeout)
110
+
111
+ def get_outbound_quota(self, *, timeout: Timeout = DEFAULT_TIMEOUT) -> ApiResponse[models.GetOutboundQuotaResult]:
112
+ """Read sending allowance. See the HTTP reference for state/recovery semantics."""
113
+ return self._request(ROUTES["get_outbound_quota"], {}, timeout=timeout)
114
+
115
+ def create_draft(self, params: models.CreateDraftParams, *, timeout: Timeout = DEFAULT_TIMEOUT) -> ApiResponse[models.CreateDraftResult]:
116
+ """Create a draft. See the HTTP reference for state/recovery semantics."""
117
+ return self._request(ROUTES["create_draft"], params, timeout=timeout)
118
+
119
+ def list_drafts(self, params: models.ListDraftsParams, *, timeout: Timeout = DEFAULT_TIMEOUT) -> ApiResponse[models.ListDraftsResult]:
120
+ """List drafts. See the HTTP reference for state/recovery semantics."""
121
+ return self._request(ROUTES["list_drafts"], params, timeout=timeout)
122
+
123
+ def get_draft(self, params: models.GetDraftParams, *, timeout: Timeout = DEFAULT_TIMEOUT) -> ApiResponse[models.GetDraftResult]:
124
+ """Retrieve a draft. See the HTTP reference for state/recovery semantics."""
125
+ return self._request(ROUTES["get_draft"], params, timeout=timeout)
126
+
127
+ def update_draft(self, params: models.UpdateDraftParams, *, timeout: Timeout = DEFAULT_TIMEOUT) -> ApiResponse[models.UpdateDraftResult]:
128
+ """Edit a draft. See the HTTP reference for state/recovery semantics."""
129
+ return self._request(ROUTES["update_draft"], params, timeout=timeout)
130
+
131
+ def delete_draft(self, params: models.DeleteDraftParams, *, timeout: Timeout = DEFAULT_TIMEOUT) -> ApiResponse[models.DeleteDraftResult]:
132
+ """Delete a draft. See the HTTP reference for state/recovery semantics."""
133
+ return self._request(ROUTES["delete_draft"], params, timeout=timeout)
134
+
135
+ def send_draft(self, params: models.SendDraftParams, *, timeout: Timeout = DEFAULT_TIMEOUT) -> ApiResponse[models.SendDraftResult]:
136
+ """Send a draft. See the HTTP reference for state/recovery semantics."""
137
+ return self._request(ROUTES["send_draft"], params, timeout=timeout)
138
+
139
+ def list_threads(self, params: models.ListThreadsParams, *, timeout: Timeout = DEFAULT_TIMEOUT) -> ApiResponse[models.ListThreadsResult]:
140
+ """List conversations. See the HTTP reference for state/recovery semantics."""
141
+ return self._request(ROUTES["list_threads"], params, timeout=timeout)
142
+
143
+ def get_thread(self, params: models.GetThreadParams, *, timeout: Timeout = DEFAULT_TIMEOUT) -> ApiResponse[models.GetThreadResult]:
144
+ """Read a conversation. See the HTTP reference for state/recovery semantics."""
145
+ return self._request(ROUTES["get_thread"], params, timeout=timeout)
146
+
147
+ def update_thread_labels(self, params: models.UpdateThreadLabelsParams, *, timeout: Timeout = DEFAULT_TIMEOUT) -> ApiResponse[models.UpdateThreadLabelsResult]:
148
+ """Label a conversation. See the HTTP reference for state/recovery semantics."""
149
+ return self._request(ROUTES["update_thread_labels"], params, timeout=timeout)
150
+
151
+ def delete_thread(self, params: models.DeleteThreadParams, *, timeout: Timeout = DEFAULT_TIMEOUT) -> ApiResponse[models.DeleteThreadResult]:
152
+ """Delete a conversation. See the HTTP reference for state/recovery semantics."""
153
+ return self._request(ROUTES["delete_thread"], params, timeout=timeout)
154
+
155
+ @overload
156
+ def pages(self, operation: Literal["list_messages"], params: models.ListMessagesParams, *, max_pages: int | None = None, timeout: Timeout = DEFAULT_TIMEOUT) -> Iterator[ApiResponse[models.ListMessagesResult]]: ...
157
+
158
+ @overload
159
+ def pages(self, operation: Literal["list_labels"], params: models.ListLabelsParams, *, max_pages: int | None = None, timeout: Timeout = DEFAULT_TIMEOUT) -> Iterator[ApiResponse[models.ListLabelsResult]]: ...
160
+
161
+ @overload
162
+ def pages(self, operation: Literal["list_sent_messages"], params: models.ListSentMessagesParams, *, max_pages: int | None = None, timeout: Timeout = DEFAULT_TIMEOUT) -> Iterator[ApiResponse[models.ListSentMessagesResult]]: ...
163
+
164
+ @overload
165
+ def pages(self, operation: Literal["list_drafts"], params: models.ListDraftsParams, *, max_pages: int | None = None, timeout: Timeout = DEFAULT_TIMEOUT) -> Iterator[ApiResponse[models.ListDraftsResult]]: ...
166
+
167
+ @overload
168
+ def pages(self, operation: Literal["list_threads"], params: models.ListThreadsParams, *, max_pages: int | None = None, timeout: Timeout = DEFAULT_TIMEOUT) -> Iterator[ApiResponse[models.ListThreadsResult]]: ...
169
+
170
+ @overload
171
+ def pages(self, operation: Literal["get_thread"], params: models.GetThreadParams, *, max_pages: int | None = None, timeout: Timeout = DEFAULT_TIMEOUT) -> Iterator[ApiResponse[models.GetThreadResult]]: ...
172
+
173
+ def pages(self, operation: str, params: Any, *, max_pages: int | None = None, timeout: Timeout = DEFAULT_TIMEOUT) -> Iterator[ApiResponse[Any]]:
174
+ return self._pages(operation, params, max_pages=max_pages, timeout=timeout)
175
+
176
+ @overload
177
+ def iterate(self, operation: Literal["list_messages"], params: models.ListMessagesParams, *, max_pages: int | None = None, timeout: Timeout = DEFAULT_TIMEOUT) -> Iterator[models.ListMessagesItem]: ...
178
+
179
+ @overload
180
+ def iterate(self, operation: Literal["list_labels"], params: models.ListLabelsParams, *, max_pages: int | None = None, timeout: Timeout = DEFAULT_TIMEOUT) -> Iterator[models.ListLabelsItem]: ...
181
+
182
+ @overload
183
+ def iterate(self, operation: Literal["list_sent_messages"], params: models.ListSentMessagesParams, *, max_pages: int | None = None, timeout: Timeout = DEFAULT_TIMEOUT) -> Iterator[models.ListSentMessagesItem]: ...
184
+
185
+ @overload
186
+ def iterate(self, operation: Literal["list_drafts"], params: models.ListDraftsParams, *, max_pages: int | None = None, timeout: Timeout = DEFAULT_TIMEOUT) -> Iterator[models.ListDraftsItem]: ...
187
+
188
+ @overload
189
+ def iterate(self, operation: Literal["list_threads"], params: models.ListThreadsParams, *, max_pages: int | None = None, timeout: Timeout = DEFAULT_TIMEOUT) -> Iterator[models.ListThreadsItem]: ...
190
+
191
+ @overload
192
+ def iterate(self, operation: Literal["get_thread"], params: models.GetThreadParams, *, max_pages: int | None = None, timeout: Timeout = DEFAULT_TIMEOUT) -> Iterator[models.GetThreadItem]: ...
193
+
194
+ def iterate(self, operation: str, params: Any, *, max_pages: int | None = None, timeout: Timeout = DEFAULT_TIMEOUT) -> Iterator[Any]:
195
+ return self._iterate(operation, params, max_pages=max_pages, timeout=timeout)
196
+
197
+
198
+ class AsyncCherami(AsyncClient):
199
+ async def list_inboxes(self, *, timeout: Timeout = DEFAULT_TIMEOUT) -> ApiResponse[models.ListInboxesResult]:
200
+ """List inboxes. See the HTTP reference for state/recovery semantics."""
201
+ return await self._request(ROUTES["list_inboxes"], {}, timeout=timeout)
202
+
203
+ async def create_inbox(self, params: models.CreateInboxParams, *, timeout: Timeout = DEFAULT_TIMEOUT) -> ApiResponse[models.CreateInboxResult]:
204
+ """Create an inbox. See the HTTP reference for state/recovery semantics."""
205
+ return await self._request(ROUTES["create_inbox"], params, timeout=timeout)
206
+
207
+ async def get_inbox(self, params: models.GetInboxParams, *, timeout: Timeout = DEFAULT_TIMEOUT) -> ApiResponse[models.GetInboxResult]:
208
+ """Read an inbox. See the HTTP reference for state/recovery semantics."""
209
+ return await self._request(ROUTES["get_inbox"], params, timeout=timeout)
210
+
211
+ async def update_inbox(self, params: models.UpdateInboxParams, *, timeout: Timeout = DEFAULT_TIMEOUT) -> ApiResponse[models.UpdateInboxResult]:
212
+ """Edit inbox names. See the HTTP reference for state/recovery semantics."""
213
+ return await self._request(ROUTES["update_inbox"], params, timeout=timeout)
214
+
215
+ async def delete_inbox(self, params: models.DeleteInboxParams, *, timeout: Timeout = DEFAULT_TIMEOUT) -> ApiResponse[models.DeleteInboxResult]:
216
+ """Delete an inbox. See the HTTP reference for state/recovery semantics."""
217
+ return await self._request(ROUTES["delete_inbox"], params, timeout=timeout)
218
+
219
+ async def get_sending_policy(self, params: models.GetSendingPolicyParams, *, timeout: Timeout = DEFAULT_TIMEOUT) -> ApiResponse[models.GetSendingPolicyResult]:
220
+ """Inspect sending rules. See the HTTP reference for state/recovery semantics."""
221
+ return await self._request(ROUTES["get_sending_policy"], params, timeout=timeout)
222
+
223
+ async def get_receiving_policy(self, params: models.GetReceivingPolicyParams, *, timeout: Timeout = DEFAULT_TIMEOUT) -> ApiResponse[models.GetReceivingPolicyResult]:
224
+ """Inspect receiving rules. See the HTTP reference for state/recovery semantics."""
225
+ return await self._request(ROUTES["get_receiving_policy"], params, timeout=timeout)
226
+
227
+ async def list_messages(self, params: models.ListMessagesParams, *, timeout: Timeout = DEFAULT_TIMEOUT) -> ApiResponse[models.ListMessagesResult]:
228
+ """List received messages. See the HTTP reference for state/recovery semantics."""
229
+ return await self._request(ROUTES["list_messages"], params, timeout=timeout)
230
+
231
+ async def count_messages(self, params: models.CountMessagesParams, *, timeout: Timeout = DEFAULT_TIMEOUT) -> ApiResponse[models.CountMessagesResult]:
232
+ """Count received messages. See the HTTP reference for state/recovery semantics."""
233
+ return await self._request(ROUTES["count_messages"], params, timeout=timeout)
234
+
235
+ async def get_message(self, params: models.GetMessageParams, *, timeout: Timeout = DEFAULT_TIMEOUT) -> ApiResponse[models.GetMessageResult]:
236
+ """Read a received message. See the HTTP reference for state/recovery semantics."""
237
+ return await self._request(ROUTES["get_message"], params, timeout=timeout)
238
+
239
+ async def delete_message(self, params: models.DeleteMessageParams, *, timeout: Timeout = DEFAULT_TIMEOUT) -> ApiResponse[models.DeleteMessageResult]:
240
+ """Delete a received message. See the HTTP reference for state/recovery semantics."""
241
+ return await self._request(ROUTES["delete_message"], params, timeout=timeout)
242
+
243
+ async def update_message_labels(self, params: models.UpdateMessageLabelsParams, *, timeout: Timeout = DEFAULT_TIMEOUT) -> ApiResponse[models.UpdateMessageLabelsResult]:
244
+ """Label a received message. See the HTTP reference for state/recovery semantics."""
245
+ return await self._request(ROUTES["update_message_labels"], params, timeout=timeout)
246
+
247
+ async def download_raw_message(self, params: models.DownloadRawMessageParams, *, timeout: Timeout = DEFAULT_TIMEOUT) -> ApiResponse[httpx.Response]:
248
+ """Download raw MIME. See the HTTP reference for state/recovery semantics."""
249
+ return await self._request(ROUTES["download_raw_message"], params, timeout=timeout)
250
+
251
+ async def download_attachment(self, params: models.DownloadAttachmentParams, *, timeout: Timeout = DEFAULT_TIMEOUT) -> ApiResponse[httpx.Response]:
252
+ """Download a received attachment. See the HTTP reference for state/recovery semantics."""
253
+ return await self._request(ROUTES["download_attachment"], params, timeout=timeout)
254
+
255
+ async def delete_sent_message(self, params: models.DeleteSentMessageParams, *, timeout: Timeout = DEFAULT_TIMEOUT) -> ApiResponse[models.DeleteSentMessageResult]:
256
+ """Delete a sent copy. See the HTTP reference for state/recovery semantics."""
257
+ return await self._request(ROUTES["delete_sent_message"], params, timeout=timeout)
258
+
259
+ async def update_sent_message_labels(self, params: models.UpdateSentMessageLabelsParams, *, timeout: Timeout = DEFAULT_TIMEOUT) -> ApiResponse[models.UpdateSentMessageLabelsResult]:
260
+ """Label a sent copy. See the HTTP reference for state/recovery semantics."""
261
+ return await self._request(ROUTES["update_sent_message_labels"], params, timeout=timeout)
262
+
263
+ async def get_sent_message(self, params: models.GetSentMessageParams, *, timeout: Timeout = DEFAULT_TIMEOUT) -> ApiResponse[models.GetSentMessageResult]:
264
+ """Read a sent message. See the HTTP reference for state/recovery semantics."""
265
+ return await self._request(ROUTES["get_sent_message"], params, timeout=timeout)
266
+
267
+ async def bulk_update_message_labels(self, params: models.BulkUpdateMessageLabelsParams, *, timeout: Timeout = DEFAULT_TIMEOUT) -> ApiResponse[models.BulkUpdateMessageLabelsResult]:
268
+ """Label several received messages. See the HTTP reference for state/recovery semantics."""
269
+ return await self._request(ROUTES["bulk_update_message_labels"], params, timeout=timeout)
270
+
271
+ async def bulk_update_sent_labels(self, params: models.BulkUpdateSentLabelsParams, *, timeout: Timeout = DEFAULT_TIMEOUT) -> ApiResponse[models.BulkUpdateSentLabelsResult]:
272
+ """Label several sent copies. See the HTTP reference for state/recovery semantics."""
273
+ return await self._request(ROUTES["bulk_update_sent_labels"], params, timeout=timeout)
274
+
275
+ async def list_labels(self, params: models.ListLabelsParams, *, timeout: Timeout = DEFAULT_TIMEOUT) -> ApiResponse[models.ListLabelsResult]:
276
+ """Discover labels. See the HTTP reference for state/recovery semantics."""
277
+ return await self._request(ROUTES["list_labels"], params, timeout=timeout)
278
+
279
+ async def send_message(self, params: models.SendMessageParams, *, timeout: Timeout = DEFAULT_TIMEOUT) -> ApiResponse[models.SendMessageResult]:
280
+ """Send a message. See the HTTP reference for state/recovery semantics."""
281
+ return await self._request(ROUTES["send_message"], params, timeout=timeout)
282
+
283
+ async def list_sent_messages(self, params: models.ListSentMessagesParams, *, timeout: Timeout = DEFAULT_TIMEOUT) -> ApiResponse[models.ListSentMessagesResult]:
284
+ """List sent messages. See the HTTP reference for state/recovery semantics."""
285
+ return await self._request(ROUTES["list_sent_messages"], params, timeout=timeout)
286
+
287
+ async def reply_message(self, params: models.ReplyMessageParams, *, timeout: Timeout = DEFAULT_TIMEOUT) -> ApiResponse[models.ReplyMessageResult]:
288
+ """Reply to a message. See the HTTP reference for state/recovery semantics."""
289
+ return await self._request(ROUTES["reply_message"], params, timeout=timeout)
290
+
291
+ async def reply_all_message(self, params: models.ReplyAllMessageParams, *, timeout: Timeout = DEFAULT_TIMEOUT) -> ApiResponse[models.ReplyAllMessageResult]:
292
+ """Reply to visible participants. See the HTTP reference for state/recovery semantics."""
293
+ return await self._request(ROUTES["reply_all_message"], params, timeout=timeout)
294
+
295
+ async def forward_message(self, params: models.ForwardMessageParams, *, timeout: Timeout = DEFAULT_TIMEOUT) -> ApiResponse[models.ForwardMessageResult]:
296
+ """Forward a message. See the HTTP reference for state/recovery semantics."""
297
+ return await self._request(ROUTES["forward_message"], params, timeout=timeout)
298
+
299
+ async def get_outbound_quota(self, *, timeout: Timeout = DEFAULT_TIMEOUT) -> ApiResponse[models.GetOutboundQuotaResult]:
300
+ """Read sending allowance. See the HTTP reference for state/recovery semantics."""
301
+ return await self._request(ROUTES["get_outbound_quota"], {}, timeout=timeout)
302
+
303
+ async def create_draft(self, params: models.CreateDraftParams, *, timeout: Timeout = DEFAULT_TIMEOUT) -> ApiResponse[models.CreateDraftResult]:
304
+ """Create a draft. See the HTTP reference for state/recovery semantics."""
305
+ return await self._request(ROUTES["create_draft"], params, timeout=timeout)
306
+
307
+ async def list_drafts(self, params: models.ListDraftsParams, *, timeout: Timeout = DEFAULT_TIMEOUT) -> ApiResponse[models.ListDraftsResult]:
308
+ """List drafts. See the HTTP reference for state/recovery semantics."""
309
+ return await self._request(ROUTES["list_drafts"], params, timeout=timeout)
310
+
311
+ async def get_draft(self, params: models.GetDraftParams, *, timeout: Timeout = DEFAULT_TIMEOUT) -> ApiResponse[models.GetDraftResult]:
312
+ """Retrieve a draft. See the HTTP reference for state/recovery semantics."""
313
+ return await self._request(ROUTES["get_draft"], params, timeout=timeout)
314
+
315
+ async def update_draft(self, params: models.UpdateDraftParams, *, timeout: Timeout = DEFAULT_TIMEOUT) -> ApiResponse[models.UpdateDraftResult]:
316
+ """Edit a draft. See the HTTP reference for state/recovery semantics."""
317
+ return await self._request(ROUTES["update_draft"], params, timeout=timeout)
318
+
319
+ async def delete_draft(self, params: models.DeleteDraftParams, *, timeout: Timeout = DEFAULT_TIMEOUT) -> ApiResponse[models.DeleteDraftResult]:
320
+ """Delete a draft. See the HTTP reference for state/recovery semantics."""
321
+ return await self._request(ROUTES["delete_draft"], params, timeout=timeout)
322
+
323
+ async def send_draft(self, params: models.SendDraftParams, *, timeout: Timeout = DEFAULT_TIMEOUT) -> ApiResponse[models.SendDraftResult]:
324
+ """Send a draft. See the HTTP reference for state/recovery semantics."""
325
+ return await self._request(ROUTES["send_draft"], params, timeout=timeout)
326
+
327
+ async def list_threads(self, params: models.ListThreadsParams, *, timeout: Timeout = DEFAULT_TIMEOUT) -> ApiResponse[models.ListThreadsResult]:
328
+ """List conversations. See the HTTP reference for state/recovery semantics."""
329
+ return await self._request(ROUTES["list_threads"], params, timeout=timeout)
330
+
331
+ async def get_thread(self, params: models.GetThreadParams, *, timeout: Timeout = DEFAULT_TIMEOUT) -> ApiResponse[models.GetThreadResult]:
332
+ """Read a conversation. See the HTTP reference for state/recovery semantics."""
333
+ return await self._request(ROUTES["get_thread"], params, timeout=timeout)
334
+
335
+ async def update_thread_labels(self, params: models.UpdateThreadLabelsParams, *, timeout: Timeout = DEFAULT_TIMEOUT) -> ApiResponse[models.UpdateThreadLabelsResult]:
336
+ """Label a conversation. See the HTTP reference for state/recovery semantics."""
337
+ return await self._request(ROUTES["update_thread_labels"], params, timeout=timeout)
338
+
339
+ async def delete_thread(self, params: models.DeleteThreadParams, *, timeout: Timeout = DEFAULT_TIMEOUT) -> ApiResponse[models.DeleteThreadResult]:
340
+ """Delete a conversation. See the HTTP reference for state/recovery semantics."""
341
+ return await self._request(ROUTES["delete_thread"], params, timeout=timeout)
342
+
343
+ @overload
344
+ def pages(self, operation: Literal["list_messages"], params: models.ListMessagesParams, *, max_pages: int | None = None, timeout: Timeout = DEFAULT_TIMEOUT) -> AsyncIterator[ApiResponse[models.ListMessagesResult]]: ...
345
+
346
+ @overload
347
+ def pages(self, operation: Literal["list_labels"], params: models.ListLabelsParams, *, max_pages: int | None = None, timeout: Timeout = DEFAULT_TIMEOUT) -> AsyncIterator[ApiResponse[models.ListLabelsResult]]: ...
348
+
349
+ @overload
350
+ def pages(self, operation: Literal["list_sent_messages"], params: models.ListSentMessagesParams, *, max_pages: int | None = None, timeout: Timeout = DEFAULT_TIMEOUT) -> AsyncIterator[ApiResponse[models.ListSentMessagesResult]]: ...
351
+
352
+ @overload
353
+ def pages(self, operation: Literal["list_drafts"], params: models.ListDraftsParams, *, max_pages: int | None = None, timeout: Timeout = DEFAULT_TIMEOUT) -> AsyncIterator[ApiResponse[models.ListDraftsResult]]: ...
354
+
355
+ @overload
356
+ def pages(self, operation: Literal["list_threads"], params: models.ListThreadsParams, *, max_pages: int | None = None, timeout: Timeout = DEFAULT_TIMEOUT) -> AsyncIterator[ApiResponse[models.ListThreadsResult]]: ...
357
+
358
+ @overload
359
+ def pages(self, operation: Literal["get_thread"], params: models.GetThreadParams, *, max_pages: int | None = None, timeout: Timeout = DEFAULT_TIMEOUT) -> AsyncIterator[ApiResponse[models.GetThreadResult]]: ...
360
+
361
+ def pages(self, operation: str, params: Any, *, max_pages: int | None = None, timeout: Timeout = DEFAULT_TIMEOUT) -> AsyncIterator[ApiResponse[Any]]:
362
+ return self._pages(operation, params, max_pages=max_pages, timeout=timeout)
363
+
364
+ @overload
365
+ def iterate(self, operation: Literal["list_messages"], params: models.ListMessagesParams, *, max_pages: int | None = None, timeout: Timeout = DEFAULT_TIMEOUT) -> AsyncIterator[models.ListMessagesItem]: ...
366
+
367
+ @overload
368
+ def iterate(self, operation: Literal["list_labels"], params: models.ListLabelsParams, *, max_pages: int | None = None, timeout: Timeout = DEFAULT_TIMEOUT) -> AsyncIterator[models.ListLabelsItem]: ...
369
+
370
+ @overload
371
+ def iterate(self, operation: Literal["list_sent_messages"], params: models.ListSentMessagesParams, *, max_pages: int | None = None, timeout: Timeout = DEFAULT_TIMEOUT) -> AsyncIterator[models.ListSentMessagesItem]: ...
372
+
373
+ @overload
374
+ def iterate(self, operation: Literal["list_drafts"], params: models.ListDraftsParams, *, max_pages: int | None = None, timeout: Timeout = DEFAULT_TIMEOUT) -> AsyncIterator[models.ListDraftsItem]: ...
375
+
376
+ @overload
377
+ def iterate(self, operation: Literal["list_threads"], params: models.ListThreadsParams, *, max_pages: int | None = None, timeout: Timeout = DEFAULT_TIMEOUT) -> AsyncIterator[models.ListThreadsItem]: ...
378
+
379
+ @overload
380
+ def iterate(self, operation: Literal["get_thread"], params: models.GetThreadParams, *, max_pages: int | None = None, timeout: Timeout = DEFAULT_TIMEOUT) -> AsyncIterator[models.GetThreadItem]: ...
381
+
382
+ def iterate(self, operation: str, params: Any, *, max_pages: int | None = None, timeout: Timeout = DEFAULT_TIMEOUT) -> AsyncIterator[Any]:
383
+ return self._iterate(operation, params, max_pages=max_pages, timeout=timeout)