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 sdks/python
python -m pytest -q
Tests are fully offline — they monkeypatch urllib.request.urlopen with a
scripted responder, so nothing touches the live API.
Release files for mailsocket 0.1.1
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.1.tar.gz | 10.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mailsocket-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 18.7 kB
Release files / mailsocket-0.1.1.tar.gz
| Download URL | mailsocket-0.1.1.tar.gz |
|---|---|
| Size | 10.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2c8b17524378e2417d6143cc7592189b9ba74d6b1b4a72dfdd3991fe2c01cdcc
|
|
BLAKE2b-256 checksum How to use checksums |
2708482ebbaf354068ca9162c6dbab619c67b7ab78e6b0e6a3b3f36ade8f678c
|
| 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.1-py3-none-any.whl
| Download URL | mailsocket-0.1.1-py3-none-any.whl |
|---|---|
| Size | 8.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
01b97c630768bfc1232eed726c4b11b8dcf8865cf7623841e265c1fe7bf5318e
|
|
BLAKE2b-256 checksum How to use checksums |
c85260876090ed4fc0ef02287f24c4091ad762c0165979bfa368d509111eedd1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.12
|