bavimail 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 (53) hide show
  1. bavimail-0.1.0/.gitignore +15 -0
  2. bavimail-0.1.0/.python-version +1 -0
  3. bavimail-0.1.0/LICENSE +21 -0
  4. bavimail-0.1.0/PKG-INFO +310 -0
  5. bavimail-0.1.0/README.md +281 -0
  6. bavimail-0.1.0/examples/async_usage.py +40 -0
  7. bavimail-0.1.0/examples/basic_usage.py +62 -0
  8. bavimail-0.1.0/examples/webhook_handler.py +51 -0
  9. bavimail-0.1.0/pyproject.toml +59 -0
  10. bavimail-0.1.0/src/bavimail/__init__.py +91 -0
  11. bavimail-0.1.0/src/bavimail/_client.py +95 -0
  12. bavimail-0.1.0/src/bavimail/_http.py +171 -0
  13. bavimail-0.1.0/src/bavimail/_types.py +36 -0
  14. bavimail-0.1.0/src/bavimail/_version.py +1 -0
  15. bavimail-0.1.0/src/bavimail/exceptions.py +144 -0
  16. bavimail-0.1.0/src/bavimail/models/__init__.py +52 -0
  17. bavimail-0.1.0/src/bavimail/models/_base.py +32 -0
  18. bavimail-0.1.0/src/bavimail/models/alias.py +36 -0
  19. bavimail-0.1.0/src/bavimail/models/conversation.py +106 -0
  20. bavimail-0.1.0/src/bavimail/models/domain.py +215 -0
  21. bavimail-0.1.0/src/bavimail/models/email.py +134 -0
  22. bavimail-0.1.0/src/bavimail/models/inbound_email.py +298 -0
  23. bavimail-0.1.0/src/bavimail/models/tag.py +105 -0
  24. bavimail-0.1.0/src/bavimail/models/webhook.py +111 -0
  25. bavimail-0.1.0/src/bavimail/pagination.py +73 -0
  26. bavimail-0.1.0/src/bavimail/py.typed +0 -0
  27. bavimail-0.1.0/src/bavimail/resources/__init__.py +1 -0
  28. bavimail-0.1.0/src/bavimail/resources/_base.py +15 -0
  29. bavimail-0.1.0/src/bavimail/resources/aliases.py +76 -0
  30. bavimail-0.1.0/src/bavimail/resources/conversations.py +72 -0
  31. bavimail-0.1.0/src/bavimail/resources/domains.py +163 -0
  32. bavimail-0.1.0/src/bavimail/resources/emails.py +120 -0
  33. bavimail-0.1.0/src/bavimail/resources/inbound_emails.py +193 -0
  34. bavimail-0.1.0/src/bavimail/resources/tags.py +179 -0
  35. bavimail-0.1.0/src/bavimail/resources/webhooks.py +179 -0
  36. bavimail-0.1.0/src/bavimail/webhook_verification.py +68 -0
  37. bavimail-0.1.0/tests/__init__.py +0 -0
  38. bavimail-0.1.0/tests/conftest.py +222 -0
  39. bavimail-0.1.0/tests/resources/__init__.py +0 -0
  40. bavimail-0.1.0/tests/resources/test_aliases.py +79 -0
  41. bavimail-0.1.0/tests/resources/test_conversations.py +57 -0
  42. bavimail-0.1.0/tests/resources/test_domains.py +269 -0
  43. bavimail-0.1.0/tests/resources/test_emails.py +60 -0
  44. bavimail-0.1.0/tests/resources/test_inbound_emails.py +123 -0
  45. bavimail-0.1.0/tests/resources/test_tags.py +84 -0
  46. bavimail-0.1.0/tests/resources/test_webhooks.py +122 -0
  47. bavimail-0.1.0/tests/test_client.py +32 -0
  48. bavimail-0.1.0/tests/test_exceptions.py +110 -0
  49. bavimail-0.1.0/tests/test_http.py +116 -0
  50. bavimail-0.1.0/tests/test_models.py +354 -0
  51. bavimail-0.1.0/tests/test_pagination.py +87 -0
  52. bavimail-0.1.0/tests/test_webhook_verification.py +105 -0
  53. bavimail-0.1.0/uv.lock +536 -0
@@ -0,0 +1,15 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ *$py.class
4
+ *.egg-info/
5
+ dist/
6
+ build/
7
+ .eggs/
8
+ *.egg
9
+ .mypy_cache/
10
+ .ruff_cache/
11
+ .pytest_cache/
12
+ .tox/
13
+ .venv/
14
+ venv/
15
+ .idea
@@ -0,0 +1 @@
1
+ 3.12
bavimail-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Bavlio
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,310 @@
1
+ Metadata-Version: 2.4
2
+ Name: bavimail
3
+ Version: 0.1.0
4
+ Summary: Python SDK for the Bavimail email service API
5
+ Project-URL: Homepage, https://github.com/Bavlio/bavimail-python
6
+ Project-URL: Documentation, https://github.com/Bavlio/bavimail-python#readme
7
+ Author: Bavlio, samcannas
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.9
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Typing :: Typed
20
+ Requires-Python: >=3.9
21
+ Requires-Dist: httpx<1.0.0,>=0.24.0
22
+ Provides-Extra: dev
23
+ Requires-Dist: mypy>=1.0; extra == 'dev'
24
+ Requires-Dist: pytest-asyncio>=0.21; extra == 'dev'
25
+ Requires-Dist: pytest-httpx>=0.21; extra == 'dev'
26
+ Requires-Dist: pytest>=7.0; extra == 'dev'
27
+ Requires-Dist: ruff>=0.1; extra == 'dev'
28
+ Description-Content-Type: text/markdown
29
+
30
+ # bavimail-python
31
+
32
+ Python SDK for the [Bavimail](https://github.com/Bavlio/bavimail-python) email service API.
33
+
34
+ ## Installation
35
+
36
+ ```bash
37
+ pip install bavimail
38
+ ```
39
+
40
+ ## Quick Start
41
+
42
+ ### Synchronous
43
+
44
+ ```python
45
+ from bavimail import Bavimail
46
+
47
+ client = Bavimail(
48
+ api_key="bvm_your_api_key",
49
+ base_url="https://mail.yourdomain.com",
50
+ )
51
+
52
+ # List domains
53
+ domains = client.domains.list()
54
+ for d in domains:
55
+ print(f"{d.domain} ({d.status})")
56
+
57
+ # Send an email
58
+ email = client.emails.send(
59
+ alias_id="your-alias-id",
60
+ to_email="recipient@example.com",
61
+ subject="Hello!",
62
+ body="<p>Welcome!</p>",
63
+ )
64
+ print(f"Sent: {email.id} (status: {email.status})")
65
+
66
+ client.close()
67
+ ```
68
+
69
+ ### Asynchronous
70
+
71
+ Every method has an `_async` variant. Use `async with` for automatic cleanup:
72
+
73
+ ```python
74
+ import asyncio
75
+ from bavimail import Bavimail
76
+
77
+ async def main():
78
+ async with Bavimail(
79
+ api_key="bvm_your_api_key",
80
+ base_url="https://mail.yourdomain.com",
81
+ ) as client:
82
+ domains = await client.domains.list_async()
83
+ email = await client.emails.send_async(
84
+ alias_id="your-alias-id",
85
+ to_email="recipient@example.com",
86
+ subject="Hello!",
87
+ body="<p>Welcome!</p>",
88
+ )
89
+
90
+ asyncio.run(main())
91
+ ```
92
+
93
+ ## Resources
94
+
95
+ ### Domains
96
+
97
+ ```python
98
+ # Create a domain
99
+ domain = client.domains.create("example.com", "AWS")
100
+
101
+ # Get setup instructions (DNS records)
102
+ setup = client.domains.get_setup(domain.id)
103
+ for record in setup.dns_records:
104
+ print(f"{record.type} {record.name} -> {record.value}")
105
+
106
+ # Check DNS verification status
107
+ dns = client.domains.get_dns_status(domain.id)
108
+ print(f"Verified: {dns.overall_progress.verified}/{dns.overall_progress.total_records}")
109
+
110
+ # Trigger verification
111
+ domain = client.domains.verify(domain.id)
112
+
113
+ # Update domain settings
114
+ domain = client.domains.update(domain.id, is_active=False)
115
+
116
+ # Delete
117
+ client.domains.delete(domain.id)
118
+ ```
119
+
120
+ ### Aliases
121
+
122
+ ```python
123
+ alias = client.aliases.create(domain.id, "support")
124
+ aliases = client.aliases.list(domain_id=domain.id)
125
+ client.aliases.update(alias.id, "info")
126
+ client.aliases.delete(alias.id)
127
+ ```
128
+
129
+ ### Emails (Outbound)
130
+
131
+ ```python
132
+ email = client.emails.send(
133
+ alias_id=alias.id,
134
+ to_email="user@example.com",
135
+ subject="Welcome",
136
+ body="<h1>Hello!</h1>",
137
+ track_opens=True,
138
+ attachments=[{
139
+ "filename": "doc.pdf",
140
+ "content": "<base64-encoded-content>",
141
+ "mime_type": "application/pdf",
142
+ }],
143
+ )
144
+
145
+ emails = client.emails.list(alias_id=alias.id, limit=50)
146
+ email = client.emails.get(email.id)
147
+ ```
148
+
149
+ ### Inbound Emails
150
+
151
+ ```python
152
+ # List with filters
153
+ emails = client.inbound_emails.list(alias_id=alias.id, limit=25)
154
+
155
+ # Get full detail
156
+ detail = client.inbound_emails.get(email_id)
157
+
158
+ # Download raw RFC822 email
159
+ raw = client.inbound_emails.download_raw(email_id)
160
+
161
+ # Download attachment by index
162
+ attachment = client.inbound_emails.download_attachment(email_id, 0)
163
+
164
+ # Tag management
165
+ client.inbound_emails.add_tags(email_id, ["tag-id-1", "tag-id-2"])
166
+ tags = client.inbound_emails.get_tags(email_id)
167
+ client.inbound_emails.replace_tags(email_id, ["tag-id-3"])
168
+ client.inbound_emails.remove_tag(email_id, "tag-id-3")
169
+
170
+ # Delete
171
+ client.inbound_emails.delete(email_id)
172
+ ```
173
+
174
+ ### Conversations
175
+
176
+ ```python
177
+ conversations = client.conversations.list(limit=20)
178
+ detail = client.conversations.get(conversation_id)
179
+ for msg in detail.messages:
180
+ print(f"[{msg.direction}] {msg.from_email}: {msg.subject}")
181
+ ```
182
+
183
+ ### Tags
184
+
185
+ ```python
186
+ tag = client.tags.create("important", color="#ff0000", is_pinned=True)
187
+ tags = client.tags.list()
188
+ tag = client.tags.update(tag.id, name="critical")
189
+ client.tags.delete(tag.id)
190
+ ```
191
+
192
+ ### Webhooks
193
+
194
+ ```python
195
+ # Create (returns secret, shown once!)
196
+ wh = client.webhooks.create(
197
+ url="https://hooks.example.com/bavimail",
198
+ event_types=["email.inbound.received", "domain.verified"],
199
+ )
200
+ print(f"Secret: {wh.secret}") # Store this!
201
+
202
+ # Verify
203
+ wh = client.webhooks.verify(wh.id, "verification-code-from-endpoint")
204
+
205
+ # Manage
206
+ webhooks = client.webhooks.list()
207
+ client.webhooks.update(wh.id, is_active=True)
208
+ client.webhooks.test(wh.id)
209
+ secret = client.webhooks.rotate_secret(wh.id)
210
+ client.webhooks.delete(wh.id)
211
+ ```
212
+
213
+ ## Pagination
214
+
215
+ Use `iter_pages` / `iter_pages_async` to iterate through all results:
216
+
217
+ ```python
218
+ from bavimail import iter_pages, iter_pages_async
219
+
220
+ # Sync
221
+ for email in iter_pages(client.inbound_emails.list, alias_id="...", page_size=25):
222
+ print(email.subject)
223
+
224
+ # Async
225
+ async for email in iter_pages_async(client.inbound_emails.list_async, page_size=25):
226
+ print(email.subject)
227
+ ```
228
+
229
+ ## Webhook Signature Verification
230
+
231
+ Verify incoming webhook signatures in your handler:
232
+
233
+ ```python
234
+ from bavimail import verify_webhook_signature, WebhookVerificationError
235
+
236
+ try:
237
+ verify_webhook_signature(
238
+ payload=request.body,
239
+ signature=request.headers["x-webhook-signature"],
240
+ timestamp=request.headers["x-webhook-timestamp"],
241
+ secret="your-hex-secret",
242
+ )
243
+ except WebhookVerificationError as e:
244
+ print(f"Invalid webhook: {e}")
245
+ ```
246
+
247
+ ## Error Handling
248
+
249
+ All API errors raise typed exceptions:
250
+
251
+ ```python
252
+ from bavimail import (
253
+ NotFoundError,
254
+ ValidationError,
255
+ ConflictError,
256
+ AuthenticationError,
257
+ RateLimitError,
258
+ APIError,
259
+ )
260
+
261
+ try:
262
+ client.domains.get("nonexistent")
263
+ except NotFoundError as e:
264
+ print(f"Not found: {e.message}")
265
+ print(f"Error code: {e.code}") # e.g. "DOMAIN_NOT_FOUND"
266
+ print(f"Category: {e.category}") # e.g. "not_found"
267
+ print(f"Request ID: {e.request_id}") # For debugging
268
+ print(f"Context: {e.context}") # e.g. {"field": "domain_id", "value": "nonexistent"}
269
+ except APIError as e:
270
+ print(f"API error ({e.status_code}): {e.message}")
271
+ ```
272
+
273
+ ## Custom HTTP Client
274
+
275
+ Pass a custom `httpx.Client` for advanced configuration (proxies, custom TLS, retries):
276
+
277
+ ```python
278
+ import httpx
279
+
280
+ custom = httpx.Client(
281
+ transport=httpx.HTTPTransport(retries=3),
282
+ timeout=60.0,
283
+ )
284
+
285
+ client = Bavimail(
286
+ api_key="bvm_...",
287
+ base_url="https://mail.yourdomain.com",
288
+ http_client=custom,
289
+ )
290
+ ```
291
+
292
+ ## Development
293
+
294
+ ```bash
295
+ # Install dev dependencies
296
+ pip install -e ".[dev]"
297
+
298
+ # Run tests
299
+ pytest tests/ -v
300
+
301
+ # Type check
302
+ mypy src/bavimail --strict
303
+
304
+ # Lint
305
+ ruff check src/ tests/
306
+ ```
307
+
308
+ ## License
309
+
310
+ MIT
@@ -0,0 +1,281 @@
1
+ # bavimail-python
2
+
3
+ Python SDK for the [Bavimail](https://github.com/Bavlio/bavimail-python) email service API.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pip install bavimail
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ### Synchronous
14
+
15
+ ```python
16
+ from bavimail import Bavimail
17
+
18
+ client = Bavimail(
19
+ api_key="bvm_your_api_key",
20
+ base_url="https://mail.yourdomain.com",
21
+ )
22
+
23
+ # List domains
24
+ domains = client.domains.list()
25
+ for d in domains:
26
+ print(f"{d.domain} ({d.status})")
27
+
28
+ # Send an email
29
+ email = client.emails.send(
30
+ alias_id="your-alias-id",
31
+ to_email="recipient@example.com",
32
+ subject="Hello!",
33
+ body="<p>Welcome!</p>",
34
+ )
35
+ print(f"Sent: {email.id} (status: {email.status})")
36
+
37
+ client.close()
38
+ ```
39
+
40
+ ### Asynchronous
41
+
42
+ Every method has an `_async` variant. Use `async with` for automatic cleanup:
43
+
44
+ ```python
45
+ import asyncio
46
+ from bavimail import Bavimail
47
+
48
+ async def main():
49
+ async with Bavimail(
50
+ api_key="bvm_your_api_key",
51
+ base_url="https://mail.yourdomain.com",
52
+ ) as client:
53
+ domains = await client.domains.list_async()
54
+ email = await client.emails.send_async(
55
+ alias_id="your-alias-id",
56
+ to_email="recipient@example.com",
57
+ subject="Hello!",
58
+ body="<p>Welcome!</p>",
59
+ )
60
+
61
+ asyncio.run(main())
62
+ ```
63
+
64
+ ## Resources
65
+
66
+ ### Domains
67
+
68
+ ```python
69
+ # Create a domain
70
+ domain = client.domains.create("example.com", "AWS")
71
+
72
+ # Get setup instructions (DNS records)
73
+ setup = client.domains.get_setup(domain.id)
74
+ for record in setup.dns_records:
75
+ print(f"{record.type} {record.name} -> {record.value}")
76
+
77
+ # Check DNS verification status
78
+ dns = client.domains.get_dns_status(domain.id)
79
+ print(f"Verified: {dns.overall_progress.verified}/{dns.overall_progress.total_records}")
80
+
81
+ # Trigger verification
82
+ domain = client.domains.verify(domain.id)
83
+
84
+ # Update domain settings
85
+ domain = client.domains.update(domain.id, is_active=False)
86
+
87
+ # Delete
88
+ client.domains.delete(domain.id)
89
+ ```
90
+
91
+ ### Aliases
92
+
93
+ ```python
94
+ alias = client.aliases.create(domain.id, "support")
95
+ aliases = client.aliases.list(domain_id=domain.id)
96
+ client.aliases.update(alias.id, "info")
97
+ client.aliases.delete(alias.id)
98
+ ```
99
+
100
+ ### Emails (Outbound)
101
+
102
+ ```python
103
+ email = client.emails.send(
104
+ alias_id=alias.id,
105
+ to_email="user@example.com",
106
+ subject="Welcome",
107
+ body="<h1>Hello!</h1>",
108
+ track_opens=True,
109
+ attachments=[{
110
+ "filename": "doc.pdf",
111
+ "content": "<base64-encoded-content>",
112
+ "mime_type": "application/pdf",
113
+ }],
114
+ )
115
+
116
+ emails = client.emails.list(alias_id=alias.id, limit=50)
117
+ email = client.emails.get(email.id)
118
+ ```
119
+
120
+ ### Inbound Emails
121
+
122
+ ```python
123
+ # List with filters
124
+ emails = client.inbound_emails.list(alias_id=alias.id, limit=25)
125
+
126
+ # Get full detail
127
+ detail = client.inbound_emails.get(email_id)
128
+
129
+ # Download raw RFC822 email
130
+ raw = client.inbound_emails.download_raw(email_id)
131
+
132
+ # Download attachment by index
133
+ attachment = client.inbound_emails.download_attachment(email_id, 0)
134
+
135
+ # Tag management
136
+ client.inbound_emails.add_tags(email_id, ["tag-id-1", "tag-id-2"])
137
+ tags = client.inbound_emails.get_tags(email_id)
138
+ client.inbound_emails.replace_tags(email_id, ["tag-id-3"])
139
+ client.inbound_emails.remove_tag(email_id, "tag-id-3")
140
+
141
+ # Delete
142
+ client.inbound_emails.delete(email_id)
143
+ ```
144
+
145
+ ### Conversations
146
+
147
+ ```python
148
+ conversations = client.conversations.list(limit=20)
149
+ detail = client.conversations.get(conversation_id)
150
+ for msg in detail.messages:
151
+ print(f"[{msg.direction}] {msg.from_email}: {msg.subject}")
152
+ ```
153
+
154
+ ### Tags
155
+
156
+ ```python
157
+ tag = client.tags.create("important", color="#ff0000", is_pinned=True)
158
+ tags = client.tags.list()
159
+ tag = client.tags.update(tag.id, name="critical")
160
+ client.tags.delete(tag.id)
161
+ ```
162
+
163
+ ### Webhooks
164
+
165
+ ```python
166
+ # Create (returns secret, shown once!)
167
+ wh = client.webhooks.create(
168
+ url="https://hooks.example.com/bavimail",
169
+ event_types=["email.inbound.received", "domain.verified"],
170
+ )
171
+ print(f"Secret: {wh.secret}") # Store this!
172
+
173
+ # Verify
174
+ wh = client.webhooks.verify(wh.id, "verification-code-from-endpoint")
175
+
176
+ # Manage
177
+ webhooks = client.webhooks.list()
178
+ client.webhooks.update(wh.id, is_active=True)
179
+ client.webhooks.test(wh.id)
180
+ secret = client.webhooks.rotate_secret(wh.id)
181
+ client.webhooks.delete(wh.id)
182
+ ```
183
+
184
+ ## Pagination
185
+
186
+ Use `iter_pages` / `iter_pages_async` to iterate through all results:
187
+
188
+ ```python
189
+ from bavimail import iter_pages, iter_pages_async
190
+
191
+ # Sync
192
+ for email in iter_pages(client.inbound_emails.list, alias_id="...", page_size=25):
193
+ print(email.subject)
194
+
195
+ # Async
196
+ async for email in iter_pages_async(client.inbound_emails.list_async, page_size=25):
197
+ print(email.subject)
198
+ ```
199
+
200
+ ## Webhook Signature Verification
201
+
202
+ Verify incoming webhook signatures in your handler:
203
+
204
+ ```python
205
+ from bavimail import verify_webhook_signature, WebhookVerificationError
206
+
207
+ try:
208
+ verify_webhook_signature(
209
+ payload=request.body,
210
+ signature=request.headers["x-webhook-signature"],
211
+ timestamp=request.headers["x-webhook-timestamp"],
212
+ secret="your-hex-secret",
213
+ )
214
+ except WebhookVerificationError as e:
215
+ print(f"Invalid webhook: {e}")
216
+ ```
217
+
218
+ ## Error Handling
219
+
220
+ All API errors raise typed exceptions:
221
+
222
+ ```python
223
+ from bavimail import (
224
+ NotFoundError,
225
+ ValidationError,
226
+ ConflictError,
227
+ AuthenticationError,
228
+ RateLimitError,
229
+ APIError,
230
+ )
231
+
232
+ try:
233
+ client.domains.get("nonexistent")
234
+ except NotFoundError as e:
235
+ print(f"Not found: {e.message}")
236
+ print(f"Error code: {e.code}") # e.g. "DOMAIN_NOT_FOUND"
237
+ print(f"Category: {e.category}") # e.g. "not_found"
238
+ print(f"Request ID: {e.request_id}") # For debugging
239
+ print(f"Context: {e.context}") # e.g. {"field": "domain_id", "value": "nonexistent"}
240
+ except APIError as e:
241
+ print(f"API error ({e.status_code}): {e.message}")
242
+ ```
243
+
244
+ ## Custom HTTP Client
245
+
246
+ Pass a custom `httpx.Client` for advanced configuration (proxies, custom TLS, retries):
247
+
248
+ ```python
249
+ import httpx
250
+
251
+ custom = httpx.Client(
252
+ transport=httpx.HTTPTransport(retries=3),
253
+ timeout=60.0,
254
+ )
255
+
256
+ client = Bavimail(
257
+ api_key="bvm_...",
258
+ base_url="https://mail.yourdomain.com",
259
+ http_client=custom,
260
+ )
261
+ ```
262
+
263
+ ## Development
264
+
265
+ ```bash
266
+ # Install dev dependencies
267
+ pip install -e ".[dev]"
268
+
269
+ # Run tests
270
+ pytest tests/ -v
271
+
272
+ # Type check
273
+ mypy src/bavimail --strict
274
+
275
+ # Lint
276
+ ruff check src/ tests/
277
+ ```
278
+
279
+ ## License
280
+
281
+ MIT
@@ -0,0 +1,40 @@
1
+ """Async usage of the Bavimail SDK."""
2
+
3
+ import asyncio
4
+
5
+ from bavimail import Bavimail, iter_pages_async
6
+
7
+
8
+ async def main() -> None:
9
+ async with Bavimail(
10
+ api_key="bvm_your_api_key_here",
11
+ base_url="https://mail.yourdomain.com",
12
+ ) as client:
13
+ # List domains
14
+ domains = await client.domains.list_async()
15
+ for d in domains:
16
+ print(f"{d.domain} ({d.status})")
17
+
18
+ # Send an email
19
+ email = await client.emails.send_async(
20
+ alias_id="your-alias-id",
21
+ to_email="recipient@example.com",
22
+ subject="Hello from async!",
23
+ body="<p>Sent asynchronously.</p>",
24
+ )
25
+ print(f"Sent: {email.id}")
26
+
27
+ # Paginate through inbound emails
28
+ async for inbound in iter_pages_async(
29
+ client.inbound_emails.list_async, page_size=25
30
+ ):
31
+ print(f" {inbound.from_email}: {inbound.subject}")
32
+
33
+ # Conversations
34
+ conversations = await client.conversations.list_async(limit=10)
35
+ for conv in conversations:
36
+ print(f"Thread: {conv.subject} ({conv.message_count} messages)")
37
+
38
+
39
+ if __name__ == "__main__":
40
+ asyncio.run(main())