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: CHANGELOG.md
+5Lines changed: 5 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,6 +4,11 @@ We [keep a changelog.](http://keepachangelog.com/)
4
4
5
5
## [Unreleased]
6
6
7
+
### Fixed
8
+
9
+
-**Config**: Fixed a URL routing regression where explicitly passing a version suffix (like `/v3`) in the `api_url` caused duplicate version paths (`/v3/v3`) resulting in 404s (#40).
10
+
- Fixed the usage's example in `README.md` of the `api_url` parameter that must strictly be the **base host only**.
Copy file name to clipboardExpand all lines: README.md
+22-23Lines changed: 22 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -210,11 +210,9 @@ The Mailgun API is part of the Sinch family and enables you to send, track, and
210
210
### Base URL
211
211
212
212
All API calls referenced in our documentation start with a base URL. Mailgun allows the ability to send and receive
213
-
email in both US and EU regions. Be sure to use the appropriate base URL based on which region you have created for your
214
-
domain.
213
+
email in both US and EU regions.
215
214
216
-
It is also important to note that Mailgun uses URI versioning for our API endpoints, and some endpoints may have
217
-
different versions than others. Please reference the version stated in the URL for each endpoint.
215
+
If you are using a proxy or a regional endpoint (such as the EU infrastructure), you can configure a custom `api_url` during initialization.
218
216
219
217
For domains created in our US region the base URL is:
220
218
@@ -228,11 +226,16 @@ For domains created in our EU region the base URL is:
228
226
https://api.eu.mailgun.net/
229
227
```
230
228
231
-
Your Mailgun account may contain multiple sending domains. To avoid passing the domain name as a query parameter, most
232
-
API URLs must include the name of the domain you are interested in:
229
+
**⚠️ Important:** The `api_url` parameter must strictly be the **base host only** (e.g., `https://api.eu.mailgun.net`). Do **not** append API version paths (like `/v3` or `/v4`) to this string. The SDK's data-driven routing engine automatically appends the correct, endpoint-specific API version under the hood.
233
230
234
-
```sh
235
-
https://api.mailgun.net/v3/mydomain.com
231
+
```python
232
+
import os
233
+
from mailgun.client import Client
234
+
235
+
# Pass ONLY the base domain
236
+
with Client(auth=("api", os.environ["APIKEY"]), api_url="https://api.eu.mailgun.net") as client:
237
+
# do someshings
238
+
pass
236
239
```
237
240
238
241
### Authentication
@@ -266,26 +269,21 @@ Synchronous vs Asynchronous Client.
266
269
267
270
### Client
268
271
269
-
Initialize your [Mailgun](http://www.mailgun.com/) client:
270
-
271
-
```python
272
-
from mailgun.client import Client
273
-
import os
274
-
275
-
auth = ("api", os.environ["APIKEY"])
276
-
client = Client(auth=auth)
277
-
```
278
-
279
272
#### Client Lifecycle & Resource Management
280
273
274
+
Initialize your [Mailgun](http://www.mailgun.com/) client.
275
+
281
276
> [!TIP]
282
277
> **New in v1.7.0:** The SDK now utilizes connection pooling (`requests.Session`) under the hood to dramatically improve performance by reusing TLS connections.
283
278
284
279
**The Simple Variant (Backward Compatible)**
285
280
For simple scripts, lambdas, or single-request apps, you can initialize and use the client directly. Python's garbage collector will eventually clean up the connection.
@@ -298,8 +296,11 @@ If you are running long-lived applications (like Celery workers, web servers, or
298
296
For production applications, \**always use the client as a Context Manager* (`with`) or explicitly call `client.close()`. This ensures deterministic release of TCP connection pools.
299
297
300
298
```python
299
+
import os
300
+
from mailgun.client import Client
301
+
301
302
# Sockets are safely managed and closed automatically
302
-
with Client(auth=("api", "KEY")) as client:
303
+
with Client(auth=("api", os.environ["APIKEY"])) as client:
@@ -308,7 +309,7 @@ with Client(auth=("api", "KEY")) as client:
308
309
By default, the SDK routes traffic to the US servers (`https://api.mailgun.net`). If you are operating in the EU, you can override the base URL during initialization:
The SDK also implements Timeouts by default `read=60.0s` (but can take a tuple with connect/read `(10.0, 60.0)` to ensure your application fails-fast during network partitions but remains patient while Mailgun processes heavy analytical queries).
@@ -322,8 +323,6 @@ import asyncio
322
323
import os
323
324
from mailgun.client import AsyncClient
324
325
325
-
auth = ("api", os.environ["APIKEY"])
326
-
327
326
328
327
asyncdefmain():
329
328
# BEST PRACTICE: Use the async context manager for safe connection pooling
0 commit comments