Docs / Using SDK

Sending email with the SDK

The official Python SDK wraps the REST API so you can send email in a couple of lines, without building requests by hand. It is published on PyPI as the postwing package.

Installation

bash
pip install postwing

Authentication

You can get them on the token management page. For security reasons, a token is shown only once — at the moment it is created.

Create the client once with your domain token — the same credentials you use for the SMTP relay and the REST API — and reuse it for every send.

python
from postwing import PostwingSdk

sdk = PostwingSdk(
    username="[email protected]",
    password="your-token",
)

Send a raw email

Use send_simple to send a ready-made message. Pass the recipient, sender, subject and the HTML (or plain-text) body.

python
sdk.send_simple(
    recipient="[email protected]",
    sender="[email protected]",
    subject="Hello",
    body="<h1>Welcome aboard!</h1>",
)

Send a templated email

Use send_tpl to render one of your saved templates by its slug. Provide the language and any placeholder params the template expects.

python
sdk.send_tpl(
    recipient="[email protected]",
    sender="[email protected]",
    tpl="welcome",
    lang="en",
    params={"name": "Alex"},
)
Both methods accept an idempotency_key so retries never send a duplicate. For the full request and response shape, see the API reference.