Installation
pip install mailpass
Quick Start — OTP Send & Verify
from mailpass import MailPass
client = MailPass("mp_live_your_api_key_here")
# Send OTP
response = client.otp.send(email="user@example.com", purpose="login")
print(response["request_id"])
# Verify OTP
result = client.otp.verify(
request_id=response["request_id"],
otp="123456"
)
if result["success"]:
print("Verified!", result["email"])
Subscribers — List & Create
# List subscribers
subscribers = client.subscribers.list(list_id=1, page=1, per_page=20)
for sub in subscribers["data"]:
print(sub["email"], sub["status"])
# Create subscriber
new_sub = client.subscribers.create(
email="new@example.com",
name="Jane Doe",
list_id=1,
tags=["newsletter"],
double_optin=True
)
print(new_sub["data"]["uuid"])
Error Handling
from mailpass.exceptions import (
ApiException,
ValidationException,
RateLimitException,
)
try:
response = client.otp.send(email="user@example.com")
except ValidationException as e:
print(f"Validation error: {e.message}")
print(f"Details: {e.details}")
except RateLimitException as e:
print(f"Rate limited. Retry after {e.retry_after}s")
except ApiException as e:
print(f"API error [{e.code}]: {e.message}")
For the full API reference, see the API Documentation or the interactive Swagger UI.