Skip to main content

Python SDK

The jetemail package is the official Python SDK for JetEmail transactional email (MIT license, Python 3.8+, requests 2.28+). Create a transactional API key in the dashboard: Outbound → Keys → Add API key. Use that key with the SDK.

Installation

Package on PyPI: jetemail. Source on GitHub: jetemail/jetemail-python.

Quick start

Use a from_ address on a verified domain (see Getting started).
The sender field is named from_ (with a trailing underscore) because from is a reserved word in Python. It is sent to the API as from.

Creating a client

The client is synchronous (built on requests). Passing an empty API key raises jetemail.ApiKeyIsMissing. JetEmail(...) exposes two services:

client.emails.send(options)

Send a single email. options is a SendEmailOptions dataclass (import it from jetemail).
Missing required fields (or neither html nor text) raise a ValueError before any request is made.

Responses

Every call returns the API response as a plain dict. Response shape for a single send: {"id": str, "response": str}.

client.batch.send(emails)

Send up to 100 emails in one request. emails is a list of SendEmailOptions, each using the same fields as a single send. Returns a dict with summary (total, successful, failed) and results per message.
An empty list, more than 100 emails, or an invalid email in the list raises a ValueError (the message includes the index of the offending email).

Attachments

Attachment holds a filename and base64-encoded data. Build one from a file path, from raw content, or directly:

Error handling

API and network errors raise JetEmailError, which exposes message, status_code (0 for network failures) and response (the parsed error body, or None). Client-side validation raises a standard ValueError.
Common status codes: 400 invalid request, 401 bad/missing API key, 500 server error.

Webhook signature verification

The SDK includes a standalone helper for verifying webhook signatures that does not need a client instance. It checks the HMAC-SHA256 signature and rejects events whose timestamp is older than the tolerance (default 300 seconds).
verify_webhook() returns True on success and raises WebhookSignatureVerificationFailed otherwise. Pass the raw request body as bytes; re-serialised JSON will not match the signature.
For additional examples, see the README on GitHub. REST details: API reference.