Skip to main content

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 (timeout is clamped to [1, 25]); the SDK re-calls until the overall timeout (seconds, default 60) elapses.
  • 200 → the matching message. 204 → nothing yet, re-call immediately.
  • 429 → honours Retry-After and 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 are fully offline — they monkeypatch urllib.request.urlopen with a scripted responder, so nothing touches the live API.

Release files for mailsocket 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mailsocket 0.1.2
File Size Uploaded
mailsocket-0.1.2.tar.gz 12.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mailsocket 0.1.2
File Interpreter ABI Platform
mailsocket-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 21.0 kB

Release files / mailsocket-0.1.2.tar.gz

Download URL mailsocket-0.1.2.tar.gz
Size 12.2 kB
Tags Source
SHA-256 checksum
How to use checksums
2bd7b46561c536575b38f3b4bdad3b3be9eea7140975e1a22297006984cf0fef
BLAKE2b-256 checksum
How to use checksums
1c539dcd10b37875bbf4b485988d7a631f59cf5b957086b996b708bcc79dc9cd
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.2-py3-none-any.whl

Download URL mailsocket-0.1.2-py3-none-any.whl
Size 8.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ded1ff14a5e72585340f004cd2723e9c612eb112a2a6df1da7a82174e4c59c34
BLAKE2b-256 checksum
How to use checksums
e2153afb23a2ea83b7b67d665e9df3f597d7da3daff069d54bf2efa7fa06e8da
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.12

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page