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_id, *, timeout=60, min_confidence=0.0, since=0) -> WaitResult
result = client.wait_for_link(inbox_id, *, timeout=60, since=0) -> WaitResult
result = client.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.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.1.0.tar.gz | 9.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mailsocket-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 17.6 kB
Release files / mailsocket-0.1.0.tar.gz
| Download URL | mailsocket-0.1.0.tar.gz |
|---|---|
| Size | 9.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
70d266b5c44daf2ae1513b17dc0161982456722adb465bd727c3fb9832a574d6
|
|
BLAKE2b-256 checksum How to use checksums |
a41df81fc8add931153e051062c3635cd6e6798a6ea2852b4b927175503cb6c3
|
| 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.0-py3-none-any.whl
| Download URL | mailsocket-0.1.0-py3-none-any.whl |
|---|---|
| Size | 8.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
18ef0f21f80f2ab957603730f786ffb48ebad3265625b41fd77b22150f222a65
|
|
BLAKE2b-256 checksum How to use checksums |
11c09fcb4563cd3dfe00637923cf2dd5f633573f20374654a69eec1c07f0bcd2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.12
|