Skip to main content

receiverdotemail

Official Python SDK for Receiver.email, the programmable inbox API for tests, AI agents and scripts: create an address under your project, wait for the email, and get the OTP code and links already extracted.

pip install receiverdotemail
import asyncio
from receiverdotemail import ReceiverClient

async def main():
    async with ReceiverClient() as receiver:  # reads RECEIVER_API_KEY
        inbox = await receiver.inboxes.create(prefix="signup")  # a fresh address per run
        await my_app.sign_up(inbox.address)  # your app sends the email

        # Long-polls until the email arrives; raises ReceiverTimeoutError after 60 s
        otp = await receiver.emails.wait_for_otp(
            recipient=inbox.address, since=inbox.created_at, timeout=60
        )
        print(otp.code)  # "847291"

asyncio.run(main())

Works the same from pytest (see Pytest Integration), Playwright for Python or Selenium tests, scripts and AI agents. Python 3.9+, async, typed (Pydantic models).

Docs: SDK reference · Quick start: create a project and an API key · REST API

Guides: pytest · Playwright · Selenium · OTP / 2FA · Magic links · Password resets

Also available: the TypeScript SDK, an MCP server for AI agents and a CLI.

Features

  • Unique inboxes on demand: mint an address per test or agent run with inboxes.create()
  • Waits of any length: wait_for and wait_for_otp loop the API's 60 s long-poll for you
  • OTP extraction: the code, plus every candidate code found, newest first
  • Live stream: async for over 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

Authentication

Create an API key (recv_live_...) in the dashboard: open your project, then Settings → API Keys. ReceiverClient() reads it from RECEIVER_API_KEY (and the API URL from RECEIVER_API_URL, if set).

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)

code_length is optional (4 to 8): without it the API auto-detects the code, and 5- and 7-digit codes are only found when you ask for them.

Stream new emails

async for event in client.emails.stream(recipient=inbox.address, subject="code"):
    print(event.email.subject, event.email.links)
    if event.otp:
        print(event.otp.code)
    break  # stop whenever you like

Filters: recipient, sender, subject (case-insensitive substring), since (default: now). Each event.email has the same fields as a list() item. 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)

# get() holds a preview of bodies over 100,000 characters; get_content reads the whole body
html = await client.emails.get_content("email_xyz789", "html")   # "text" (default), "html" or "raw"

await client.emails.delete("email_xyz789")

emails = await client.emails.find_by_sender("noreply@example.com")
resets = await client.emails.find_by_subject("Password Reset")  # case-insensitive substring
recent = await client.emails.find_by_recipient(inbox.address, since=inbox.created_at)

List filters: recipient, sender, subject (case-insensitive substring), has_attachments, since (strictly after; received_after is a deprecated alias), received_before, limit (max 100), cursor. With subject or has_attachments a page can hold fewer than limit emails while has_more is still true, so page on with the cursor (list_all() does).

Attachments

from pathlib import Path

email = await client.emails.get("email_xyz789")
for index, attachment in enumerate(email.attachments):
    if attachment.omitted:  # over the plan's size limit, not stored
        continue
    data = await client.emails.get_attachment(email.id, index)  # bytes
    Path(attachment.filename).write_bytes(data)

Each attachment has filename, content_type, size, and either url (stored) or omitted == "too_large". url, text_body_uri and html_body_uri are API URLs that need the same Authorization header as every other request, so they don't open in a browser; get_attachment() and get_content() fetch them for you.

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]
hook = await client.webhooks.get("proj_abc123", hook.id)
hook = await client.webhooks.update("proj_abc123", hook.id, url="https://ci.example.com/hooks/v2")  # url and/or events
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)

rotated = await client.webhooks.rotate_secret("proj_abc123", hook.id)
print(rotated.secret)  # the new whsec_..., shown once

rotate_secret() takes effect at once: new deliveries are signed with the new secret (retries already under way keep the old one). Deliveries your receiver rejects before it has the new secret are not resent, so deploy it promptly.

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

Everything here except projects.get and projects.list needs a dashboard session token; an API key gets 403. With an API key, projects.list returns only the key's own project.

from datetime import datetime, timedelta, timezone

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",
    expires_at=datetime.now(timezone.utc) + timedelta(days=90),  # optional, at most 365 days
)
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".

With a dashboard session, a project or organization you aren't a member of raises NotFoundError (404), the same as one that doesn't exist. An API key used on any project other than its own, existing or not, gets 403. Plan limits (projects, webhooks per project, members, free organizations) answer 403 with code == "LIMIT_REACHED".

Pytest Integration

Async tests and fixtures need pytest-asyncio with asyncio_mode = "auto" (in pyproject.toml under [tool.pytest.ini_options]).

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

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

Metadata

Release files for receiverdotemail 2.1.0

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

Source distribution (sdist)

Source distribution for receiverdotemail 2.1.0
File Size Uploaded Provenance Actions
receiverdotemail-2.1.0.tar.gz 38.0 kB With provenance Details for receiverdotemail-2.1.0.tar.gz

Built distribution (wheel)

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

Total release size: 70.9 kB

Release files / receiverdotemail-2.1.0.tar.gz

Download URL receiverdotemail-2.1.0.tar.gz
Size 38.0 kB
Tags Source
SHA-256 checksum
How to use checksums
ae25c832ae5d393c1caa3cb817a68a6b93aaedf54bbfae3d7dfd87e4fff43c68
BLAKE2b-256 checksum
How to use checksums
7da05b9f5d3c715efd96a88fcbe3e52e8ccda37c72bd9e4ac401b17e0b01bdf1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 26, 2026.

Transparency log

Release files / receiverdotemail-2.1.0-py3-none-any.whl

Download URL receiverdotemail-2.1.0-py3-none-any.whl
Size 32.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
be28e1d960cb1ac5330c778face9838f3f0263e54b8f541a0e757687bafb6b57
BLAKE2b-256 checksum
How to use checksums
84c69d07b6690171cb5be9d8a0577bbc5c9f638172034df05c61cb6d4048a1a2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 26, 2026.

Transparency log

Security for receiverdotemail 2.1.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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for receiverdotemail-2.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 26, 2026.

Transparency log

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.

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