Python SDK
Install and use the official taifa-mail Python client to send email, manage domains, contacts, suppressions, templates, and webhooks.
The official Python client for Taifa Mail wraps the Emails API and every other Core resource in a small, typed surface. It is published as taifa-mail on PyPI, and the source lives in the taifa-mail-sdks repository.
Installation
The package has zero runtime dependencies (it uses only the Python standard library) and supports Python 3.8 and above.
Client setup
Create a client with your API key. Keys start with tfm_k_ and are passed as a bearer token on every request.
The constructor accepts the following options:
| Option | Type | Default | Description |
|---|---|---|---|
api_key | str | required | Your Taifa Mail API key. Must start with tfm_k_. |
base_url | str | https://govconnect.ke | Override the API host (for staging or self-hosted setups). |
max_retries | int | 3 | Maximum attempts per request. Retries apply to 429 and 5xx responses. |
timeout | float | 30.0 | Per-request timeout in seconds. |
Keep your API key on the server. Never embed it in client-side code or commit it to source control. Load it from an environment variable instead.
Send an email
Pass a message dictionary to taifamail.emails.send. The from, to, cc, and bcc fields accept a bare email string, a {"email", "name"} dict, or a list of either.
You expose a clean from key. The SDK maps it to the API's wire field from_ for you, so you never write from_ yourself.
A richer send can set names, multiple recipients, a reply-to, tags, and a schedule. The send_at field accepts a datetime or an ISO 8601 string.
The send returns a result dict shaped like this:
Emails
The taifamail.emails resource covers sending, lookups, search, scheduling, and inspection.
Domains
The taifamail.domains resource registers, verifies, inspects, and transfers sending domains.
Contacts
The taifamail.contacts resource manages subscriber lists, their contacts, CSV imports, and templated bulk sends.
Suppressions
The taifamail.suppressions resource manages the do-not-send list. The list returns a paginated envelope of {items, total, page, limit}.
Templates
The taifamail.templates resource manages reusable email templates. Available on the Starter plan and above.
The html and text arguments map to the wire fields html_body and text_body. Template variables are derived server-side from {{name}} placeholders, so you do not pass them.
Webhooks
The taifamail.webhooks resource manages event subscriptions and inspects deliveries.
Error handling
Any non-2xx response, or a transport failure that survives every retry, raises TaifaMailError. Inspect its attributes to branch on specific failures.
| Attribute | Type | Description |
|---|---|---|
status | int | HTTP status code. 0 indicates a transport or network failure. |
code | str or None | Machine-readable error code from the API body, when present. |
message | str | Human-readable message (the exception's string value). |
detail | any | The raw parsed response body, for debugging. |
Configuration
The client tunes its network behaviour through three constructor options.
- Retries. Requests that return
429(rate limited) or any5xxare retried automatically, up tomax_retriesattempts (default3). Backoff is exponential, and aRetry-Afterheader is honoured when present. Uploads are not retried, because they are not idempotent. - Timeout. Each request is bounded by
timeoutseconds (default30.0). A timeout that exhausts all retries raisesTaifaMailErrorwithstatusset to0. - Base URL. Point
base_urlat a staging or self-hosted host. It defaults tohttps://govconnect.keand trailing slashes are trimmed.
Next steps
- SDK overview - compare the Python client with the SDKs for other languages.
- Emails API reference - the underlying REST endpoints, request bodies, and response shapes.