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=0)
result = client.wait_for_link("inbox_abc123", timeout=60, since=0)
result = client.wait("inbox_abc123", timeout=60, min_confidence=0.0, since=0) # 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=0 |
WaitResult |
wait_for_link(inbox_id, ...) |
timeout=60, since=0 |
WaitResult |
wait(inbox_id, ...) |
timeout=60, min_confidence=0.0, since=0 |
WaitResult (otp OR link) |
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.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.1.3
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.1.3.tar.gz | 13.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mailsocket-0.1.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 22.2 kB
Release files / mailsocket-0.1.3.tar.gz
| Download URL | mailsocket-0.1.3.tar.gz |
|---|---|
| Size | 13.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d13466c63788e5d4b21a3587df8f0074293858a48d861d57bffbb2a85b0b06ca
|
|
BLAKE2b-256 checksum How to use checksums |
0bbe7fad24d404f40f8c46b14cb8cbdecd7233d57f707fdee1ef44fb4b14b644
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.12
|
Release files / mailsocket-0.1.3-py3-none-any.whl
| Download URL | mailsocket-0.1.3-py3-none-any.whl |
|---|---|
| Size | 9.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
730165bf3c6ad3d064d61d52b3a3732aefb749de09c361baad16a3bc1d3151eb
|
|
BLAKE2b-256 checksum How to use checksums |
2cc627a8316c802c03601417059e9f8f57b56545b3d75d43da32addc3660b264
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.12
|