You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+55-50Lines changed: 55 additions & 50 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -190,26 +190,23 @@ with Client(auth=(api_key, api_secret), version="v3.1") as mailjet:
190
190
print(result.status_code)
191
191
```
192
192
193
-
(Note:
194
-
195
-
> **Note**
196
-
> If you choose not to use the context manager, you should manually call mailjet.close() when your application shuts down.
193
+
> [!WARNING]
194
+
> **Resource Management:** If you choose not to use the context manager, you **must** manually call `mailjet.close()` when your application shuts down to release the underlying sockets.
197
195
198
196
### Advanced Configuration
199
197
200
198
You can pass configuration overrides directly when initializing the `Client` or during individual API calls:
201
199
202
200
```python
203
201
# Set custom base URL, timeout, and API version
204
-
mailjet = Client(
202
+
with Client(
205
203
auth=(api_key, api_secret),
206
204
version="v3.1",
207
205
api_url="https://api.us.mailjet.com/",
208
206
timeout=30,
209
-
)
210
-
211
-
# Override timeout for a single, heavy request
212
-
result = mailjet.contact.get(timeout=60)
207
+
) as mailjet:
208
+
# Override timeout for a single, heavy request
209
+
result = mailjet.contact.get(timeout=60)
213
210
```
214
211
215
212
#### API Versioning
@@ -224,7 +221,11 @@ Since most Email API endpoints are located under `v3`, it is set as the default
224
221
For the others you need to specify the version using `version`. For example, if using Send API `v3.1`:
If your account has been moved to Mailjet's **US architecture**, the URL value you need to set is `https://api.us.mailjet.com`.
@@ -301,19 +306,19 @@ For example, to reach `statistics/link-click` path you should call `statistics_l
301
306
302
307
```python
303
308
# GET `statistics/link-click`
304
-
mailjet =Client(auth=(api_key, api_secret))
305
-
filters = {"CampaignId": "xxxxxxx"}
306
-
result = mailjet.statistics_linkClick.get(filters=filters)
307
-
print(result.status_code)
308
-
print(result.json())
309
+
withClient(auth=(api_key, api_secret))as mailjet:
310
+
filters = {"CampaignId": "xxxxxxx"}
311
+
result = mailjet.statistics_linkClick.get(filters=filters)
312
+
print(result.status_code)
313
+
print(result.json())
309
314
```
310
315
311
316
For the **Content API (v1)**, sub-actions will be correctly routed using slashes (e.g. contents/lock). Additionally, the SDK maps the `data_images` resource specifically to `/v1/data/images` to support media uploads.
### Standard REST Actions (GET, POST, PUT, DELETE)
474
480
481
+
> [!NOTE]\
482
+
> All examples in this section assume that you have already opened a session using the context manager, for example: with Client(auth=(api_key, api_secret)) as mailjet:.
483
+
475
484
#### POST (Create)
476
485
477
486
##### Simple POST request
@@ -505,10 +514,9 @@ Enable `dry_run=True` to safely intercept all network mutations (`POST`, `PUT`,
505
514
506
515
```python
507
516
# Intercepts state-changing requests and injects SandboxMode where applicable
0 commit comments