mailsocket — Python SDK
The official Python client for the mailsocket v1 REST API. Ephemeral email inboxes, message retrieval, and — the whole point — wait for the OTP in one line.
from mailsocket import Client
client = Client("ms_live_...") # your API key from the dashboard
inbox = client.create_inbox(label="signup") # -> {"id": "inbox_...", "address": "..."}
# hand inbox["address"] to whatever form sends the code, then:
result = client.wait_for_otp(inbox["id"]) # blocks up to 60s
print(result.otp) # "123456"
print(result.confidence) # 0.95
No polling loop. No regex over the email body. wait_for_otp long-polls the
server (which already knows how to extract the code) and hands back a
deterministic result with a confidence score.
Install
pip install mailsocket
Zero runtime dependencies — pure standard library (urllib). Python 3.9+.
API
client = Client(api_key, base_url="https://dash.mailsocket.app/api/v1")
| Method | Returns |
|---|---|
create_inbox(label=None) |
dict — the inbox (id, address, ...) |
list_inboxes(limit=None, cursor=None) |
Page — .data list + .next_cursor / .has_more |
get_inbox(inbox_id) |
dict — inbox plus message_count_month, webhook_configured |
delete_inbox(inbox_id) |
None |
list_messages(inbox_id, has_otp=None, subject_contains=None, sender=None, ...) |
Page — sender maps to the API's from filter |
get_latest(inbox_id) |
dict — newest message |
get_message(message_id) |
dict — full message |
The moat
result = client.wait_for_otp("inbox_abc123", timeout=60, min_confidence=0.0, since=None)
result = client.wait_for_link("inbox_abc123", timeout=60, since=None)
result = client.wait("inbox_abc123", timeout=60, min_confidence=0.0, since=None) # otp OR link
All three return a WaitResult and take keyword-only arguments after
inbox_id. timeout/min_confidence/since shown above are the defaults —
call with no extra arguments for the common case.
| Method | Keyword args (all optional, keyword-only) | Returns |
|---|---|---|
wait_for_otp(inbox_id, ...) |
timeout=60, min_confidence=0.0, since=None |
WaitResult |
wait_for_link(inbox_id, ...) |
timeout=60, since=None |
WaitResult |
wait(inbox_id, ...) |
timeout=60, min_confidence=0.0, since=None |
WaitResult (otp OR link) |
since=None (the default) omits the param, so the server uses its own
default: the request start time — a code that arrives during this call is
caught, and a stale code already in a reused inbox is not. Pass since=0 to
restore the old "any message already in the inbox" behaviour (useful right
after create_inbox, where there's nothing stale to match), or a message id
/ timestamp to continue after a specific point.
WaitResult exposes .otp, .confidence, .magic_link (and .link as an
alias), plus the full .message dict. str(result) is the OTP (or the link).
Semantics:
- Each HTTP call blocks server-side for up to 25s (
timeoutis clamped to[1, 25]); the SDK re-calls until the overalltimeout(seconds, default 60) elapses. 200→ the matching message.204→ nothing yet, re-call immediately.429→ honoursRetry-Afterand retries within the deadline.404→ raises.- On overall deadline →
WaitTimeout.
Errors
MailsocketError (base) with subclasses:
AuthError— HTTP 401 (bad/missing key).NotFound— HTTP 404.RateLimited— HTTP 429, carries.subcode(rate_limited,too_many_wait_requests,wait_capacity) and.retry_after.WaitTimeout— no matching message within the overall deadline.
Develop
cd python
python -m pytest -q
Tests make no external or live-API requests. Most monkeypatch
urllib.request.urlopen with a scripted responder, and a few start a real local
http.server on 127.0.0.1 to check actual request behaviour, e.g. that an
invalid id never reaches the network.
Changelog
- 0.2.0 — BEHAVIOUR CHANGE:
wait_for_otp/wait_for_link/waitnow defaultsince=None, which omits the param so the server uses the request start time, instead of the oldsince=0("any message already in the inbox"). The old default silently returned a STALE OTP/link from a reused inbox. Passsince=0explicitly to keep the old behaviour. - 0.1.3 —
_segnow rejects an empty id or a bare./..id with aMailsocketError(code="invalid_id") before any request is made, matching the TypeScript SDK's contract.
Metadata
Release files for mailsocket 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| mailsocket-0.2.0.tar.gz | 16.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mailsocket-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 26.4 kB
Release files / mailsocket-0.2.0.tar.gz
| Download URL | mailsocket-0.2.0.tar.gz |
|---|---|
| Size | 16.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d9e86198e591b0f31645cb3fd487a934b549abb14db3720404b7bb2080752fbf
|
|
BLAKE2b-256 checksum How to use checksums |
662c73673c40bd98d65aeaae8e8e2d3c7467093c5b4212a69d73381d8b2b94c2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.6
|
Release files / mailsocket-0.2.0-py3-none-any.whl
| Download URL | mailsocket-0.2.0-py3-none-any.whl |
|---|---|
| Size | 10.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b7441f7d7a84867f8d176828e6458277b498c380a529a8be65f0de784abc58dd
|
|
BLAKE2b-256 checksum How to use checksums |
5c3a0310ede831bd70bd2630d693c697bee96c09e94a1ebb57b83d3ec970fbc2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.6
|