receiverdotemail
Official Python SDK for Receiver.email: programmable email inboxes for end-to-end tests, AI agents and scripts. Create a unique address per test, trigger your sign-up, login or password-reset email, and get the OTP code or magic link back with one call. Built for pytest, Playwright for Python and CI.
Guides: pytest · Playwright · OTP / 2FA · Magic links · Password resets
Features
- Unique inboxes on demand: mint an address per test or agent run with
inboxes.create() - Waits of any length:
wait_forandwait_for_otploop the API's 60 s long-poll for you - OTP extraction: the code, plus every candidate code found, newest first
- Live stream:
async forover new emails (Server-Sent Events, reconnects automatically) - Link extraction, filtering, pagination, webhooks
- Type-safe: Pydantic models with snake_case attributes
- Async/await API built on
httpx
Installation
pip install receiverdotemail
Quick Start
import asyncio
from receiverdotemail import ReceiverClient
async def main():
# Reads RECEIVER_API_KEY (and RECEIVER_API_URL, if set) from the environment
async with ReceiverClient() as receiver:
inbox = await receiver.inboxes.create(prefix="signup")
await my_app.sign_up(inbox.address)
otp = await receiver.emails.wait_for_otp(
recipient=inbox.address,
since=inbox.created_at,
timeout=60,
)
print(otp.code)
asyncio.run(main())
With an API key, project_id is optional on every email and inbox method: the SDK
calls whoami() once and caches the key's project. Pass project_id=... to skip that
call, or when authenticating with a dashboard session token.
Configuration
client = ReceiverClient(
api_key="recv_live_...", # default: RECEIVER_API_KEY
base_url="https://api.receiver.email/api/v1", # default: RECEIVER_API_URL, else production
timeout=30, # HTTP timeout for ordinary requests (seconds)
user_agent="my-tool/1.0", # default: receiver-sdk-py/<version>
project_id="proj_abc123", # default: RECEIVER_PROJECT_ID, else looked up once via whoami()
)
A missing API key raises ReceiverError with code == "MISSING_API_KEY".
Usage
Who am I
me = await client.whoami()
print(me.auth_type) # "apikey" or "jwt"
print(me.project.email_suffix) # -a3kx9p2m@receiver.email
Create an inbox
inbox = await client.inboxes.create(prefix="reset") # prefix is optional
print(inbox.address) # reset-k2m9qa-a3kx9p2m@receiver.email
print(inbox.created_at) # pass as `since` when waiting
Nothing is stored until mail arrives. Always build addresses this way (or from
project.email_suffix), never by hand.
since
since (a datetime or ISO string) matches mail received strictly after it.
Use inbox.created_at for the first email, and the previous email's received_at
for the next one. Naive datetimes are treated as local time. When omitted, waits
look back 60 seconds and stream() starts from now.
Wait for an email
from receiverdotemail import ReceiverTimeoutError
try:
email = await client.emails.wait_for(
recipient=inbox.address,
subject="Reset", # substring, case-insensitive
since=inbox.created_at,
timeout=120, # any length; the SDK repeats 60 s server waits
)
reset_link = next(link for link in email.links if "reset" in link)
except ReceiverTimeoutError as e:
print(f"Nothing after {e.waited_seconds}s (since {e.since})")
wait_for returns an Email (with text_body and links) or raises
ReceiverTimeoutError. It never returns None.
One-time codes
otp = await client.emails.wait_for_otp(recipient=inbox.address, since=inbox.created_at, timeout=60)
print(otp.code, otp.code_length, otp.source) # "123456", 6, "subject"
print([c.code for c in otp.candidates]) # every code found, newest first
# No waiting: returns None when nothing matches
otp = await client.emails.get_otp(recipient=inbox.address, code_length=6)
Stream new emails
async for event in client.emails.stream(recipient=inbox.address):
print(event.email.subject, event.email.links)
if event.otp:
print(event.otp.code)
break # stop whenever you like
The server closes each connection after about 55 seconds; the SDK reconnects with
the since it reports, so no email is missed or repeated.
Send a test email
await client.emails.send_test(to=inbox.address) # "Your Receiver.email test code: 123456"
List, get and delete emails
response = await client.emails.list(recipient=inbox.address, limit=50)
for email in response.emails:
print(email.subject)
async for email in client.emails.list_all(sender="noreply@example.com"):
...
email = await client.emails.get("email_xyz789") # or get("proj_abc123", "email_xyz789")
print(email.text_body, email.html_body, email.attachments)
await client.emails.delete("email_xyz789")
emails = await client.emails.find_by_subject("Password Reset")
Webhooks (dashboard session only)
Webhook management needs a dashboard session token; API keys get 403.
hook = await client.webhooks.create("proj_abc123", "https://ci.example.com/hooks/receiver")
print(hook.secret) # whsec_..., shown once
hooks = await client.webhooks.list("proj_abc123") # List[Webhook]
delivery = await client.webhooks.test("proj_abc123", hook.id)
deliveries = await client.webhooks.deliveries("proj_abc123", hook.id) # last 50
await client.webhooks.delete("proj_abc123", hook.id)
Verify each delivery in your receiver with the raw request body:
from receiverdotemail import verify_webhook_signature
if not verify_webhook_signature(secret, request.headers["Receiver-Signature"], raw_body):
return 400
Projects, organizations and API keys
projects = await client.projects.list("org_abc123")
project = await client.projects.get("proj_abc123")
await client.projects.create(organization_id="org_abc123", name="CI Tests")
orgs = await client.organizations.list()
response = await client.api_keys.create(project_id="proj_abc123", name="CI Pipeline")
print(response.key) # Full key, only shown once!
await client.api_keys.revoke("proj_abc123", "key_xyz789")
Error Handling
from receiverdotemail import (
ReceiverError,
ReceiverTimeoutError,
RateLimitError,
AuthenticationError,
NotFoundError,
)
try:
email = await client.emails.wait_for(recipient=inbox.address, timeout=30)
except ReceiverTimeoutError as e:
print(e.since, e.waited_seconds)
except RateLimitError as e:
print(f"Rate limited. Retry at: {e.reset_at}")
except AuthenticationError:
print("Invalid API key")
except NotFoundError:
print("Not found")
except ReceiverError as e:
print(e.message, e.status_code, e.code)
All errors derive from ReceiverError. ReceiverTimeoutError has status_code == 408
and code == "WAIT_TIMEOUT".
Pytest Integration
import pytest
from receiverdotemail import ReceiverClient
@pytest.fixture
async def receiver():
async with ReceiverClient() as client: # RECEIVER_API_KEY from the environment
yield client
async def test_signup_email(receiver):
inbox = await receiver.inboxes.create(prefix="signup")
await my_app.signup(inbox.address)
email = await receiver.emails.wait_for(
recipient=inbox.address,
subject="Confirm your email",
since=inbox.created_at,
timeout=60,
)
assert any("confirm" in link for link in email.links)
Upgrading from 1.x
See CHANGELOG.md. In short: wait_for raises ReceiverTimeoutError
instead of returning None, wait_for_otp raises instead of returning None, and
received_after on waits is now since (the old name still works).
Development
pip install -e ".[dev]"
pytest
mypy receiverdotemail
Or from the repo root: ./scripts/test.sh python-sdk.
License
MIT
Support
- Documentation: https://docs.receiver.email
- Email: support@receiver.email
- Issues: https://github.com/receiverdotemail/sdk-python/issues
Metadata
Release files for receiverdotemail 2.0.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 | Provenance | Actions |
|---|---|---|---|---|
| receiverdotemail-2.0.0.tar.gz | 29.7 kB | Without provenance | Details for receiverdotemail-2.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| receiverdotemail-2.0.0-py3-none-any.whl | Python 3 | none | any | Details for receiverdotemail-2.0.0-py3-none-any.whl |
Total release size: 57.5 kB
Release files / receiverdotemail-2.0.0.tar.gz
| Download URL | receiverdotemail-2.0.0.tar.gz |
|---|---|
| Size | 29.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6eb7b09b93b30fdc1ff8c4c854f3fa1234fd88dcb43d5640554fcc857d5e550d
|
|
BLAKE2b-256 checksum How to use checksums |
85ada0121a769008d6486ff6d8d9672f364f366d0a2420d4d5c3603b861cbf07
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.2
|
Release files / receiverdotemail-2.0.0-py3-none-any.whl
| Download URL | receiverdotemail-2.0.0-py3-none-any.whl |
|---|---|
| Size | 27.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
751d6df82e91f5806dd0201fe045fd4586b4d55f6a5069bd74901e67b9956995
|
|
BLAKE2b-256 checksum How to use checksums |
7425de405db7d60a859e1834cda770240cbd7a5dd9849945c0da100c6f513e43
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.2
|
Security for receiverdotemail 2.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.