Skip to main content
The Python SDK is the sendflit package. It has no runtime dependencies. It uses the standard library for HTTP, so it works anywhere Python 3.9 or later runs.
Looking for another language? See the SDK overview.

Install

Create a client

The constructor accepts these arguments: The client is synchronous. Each call blocks until the API responds.

Send an email

send takes keyword arguments. Use from_ for the sender, because from is a reserved word in Python.
send returns the stored email as a dictionary. Its id is what you use to look up or cancel the email later. Arguments you can pass:

Send with a template

Attachments

Each attachment is a dictionary with a filename, a content, and an optional content_type. Pass content as str or bytes. The SDK base64-encodes it for you.
Limits:
  • Up to 10 attachments per message.
  • Up to 10 MB per attachment. Larger files are rejected with 422.

Safe retries with idempotency keys

If a request times out, you can’t tell whether the server sent the email. Pass an idempotency_key so a retry can’t send it twice.
Sending the same key with the same request returns the original result and sends nothing new. Reusing a key with a different request body is rejected with 409. That means your code has a bug, so generate a new key for a new email. For the full rules, see Idempotency.

Send a batch

batch sends up to 100 emails in one request. It takes a list of dictionaries, each with the same keys as send, except that the sender key is from.
The response has a results list, in the same order as your input, and a count. An empty list raises TypeError, and more than 100 emails raises ValueError, before any request is made. See Batch sending.

Manage emails

cancel_email removes an email that hasn’t been sent yet. If the email was already sent, the API returns an error, which the SDK raises as SendFlitError.

Domains

You can send only from a verified domain. For the DNS records and dashboard steps, see Domains.

Suppressions

Suppressed addresses never receive email from your account. Add an address when a recipient unsubscribes or complains.
reason is optional and defaults to "unsubscribe". See Emails.

Usage and health

Use health in a readiness probe or a startup check.

Verify webhooks

SendFlit signs each webhook. The X-Sendflit-Signature header carries sha256=<hex>, an HMAC-SHA256 of the raw request body. Use the module-level function to check it.
Read the raw body with request.get_data() before anything parses it. A parsed or re-serialized body won’t match the signature. See Webhooks for the event list.

Errors and retries

Every failed request raises SendFlitError:
Requests that fail with 429 or 5xx are retried up to max_retries times. The SDK honors the Retry-After header when present, and otherwise backs off exponentially. Other 4xx responses are not retried. See Errors, retries and limits.

Method reference

Next steps