Python
Send an email from Python with the notix-sdk package.
Send your first email from Python with notix-sdk, the official SDK. It needs Python 3.10 or newer. You install notix-sdk and import notix.
Prerequisites
- An API key.
- A verified domain to send from.
Install the SDK
pip install notix-sdkpoetry add notix-sdkSet your API key
The client reads
NOTIX_API_KEYwhen you do not pass a key.NOTIX_API_KEY=notix_12345Send an email
Pass a plain dict, so you can use the
fromkey.from notix import Notix notix = Notix() # reads NOTIX_API_KEY data, _ = notix.emails.send(payload={ "from": "Acme <receipts@acme.com>", "to": "maria@example.com", "subject": "Your receipt for order 4471", "html": "<p>Thanks for your order, Maria.</p>", "text": "Thanks for your order, Maria.", }) print("Sent", data["emailId"])Handle errors
By default the client raises
NotixHTTPErrorwhen the API answers with an error. The exception carries the status and the error body.from notix import Notix, NotixHTTPError notix = Notix() try: data, _ = notix.emails.send(payload={ "from": "receipts@acme.com", "to": "maria@example.com", "subject": "Your receipt", "html": "<p>Thanks for your order.</p>", }) except NotixHTTPError as err: print(err.status_code, err.error.get("code"), err.error.get("message"))Prefer not to raise? Create the client with
Notix(raise_on_error=False). Every method then returns(data, error), anderroris set when the call failed.
Next steps
- Send many emails at once with batch sending:
notix.emails.batch(payload=[...]). - Add files with attachments.
- Make retries safe with idempotency keys:
options={"idempotency_key": "order-4471-receipt"}. - Hear about deliveries and bounces with webhooks.