> ## Documentation Index
> Fetch the complete documentation index at: https://jetemail.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Python

> Official JetEmail Python SDK for transactional email

# Python SDK

The **[jetemail](https://pypi.org/project/jetemail/)** package is the official Python SDK for JetEmail transactional email (MIT license, **Python 3.8+**).

Create a **transactional** API key in the dashboard: **Outbound** → **Keys** → Add API key. Use that key with the SDK.

## Installation

```bash theme={null}
pip install jetemail
```

Package on PyPI: [jetemail](https://pypi.org/project/jetemail/).

## Quick start

```python theme={null}
from jetemail import JetEmail

client = JetEmail("your-transactional-api-key")

result = client.email.send(
    from_address="Your App <hello@yourdomain.com>",
    to="user@example.com",
    subject="Welcome!",
    html="<h1>Welcome!</h1>"
)
```

Use a `from_address` on a **verified domain** (see [Getting started](/transactional-email/getting-started)).

## Constructor

```python theme={null}
# API key string
client = JetEmail("your-transactional-api-key")

# Or with options
client = JetEmail(
    api_key="your-transactional-api-key",
    base_url="https://api.jetemail.com"  # optional
)
```

## `client.email.send(**options)`

Send a single email.

| Field                   | Required | Description                              |
| ----------------------- | -------- | ---------------------------------------- |
| `from_address`          | ✓        | Sender, e.g. `"Name <email@domain.com>"` |
| `to`                    | ✓        | Recipient(s), string or list (max 50)    |
| `subject`               | ✓        | Subject line                             |
| `html`                  | \*       | HTML body (need `html` and/or `text`)    |
| `text`                  | \*       | Plain text (need `html` and/or `text`)   |
| `cc`, `bcc`, `reply_to` |          | Recipients (max 50 each)                 |
| `headers`               |          | Custom headers dict                      |
| `attachments`           |          | Attachments (max 40MB total)             |

Response shape: `{ "id": str, "response": str }`.

## `client.batch.send(emails)`

Send up to **100** emails in one request. Returns `summary` (`total`, `successful`, `failed`) and `results` per message.

```python theme={null}
result = client.batch.send([
    {
        "from_address": "you@example.com",
        "to": "alice@example.com",
        "subject": "Hello Alice",
        "html": "<p>Hi Alice!</p>",
    },
    {
        "from_address": "you@example.com",
        "to": "bob@example.com",
        "subject": "Hello Bob",
        "html": "<p>Hi Bob!</p>",
    },
])
```

## Attachments

```python theme={null}
from jetemail import Attachment

result = client.email.send(
    from_address="you@example.com",
    to="recipient@example.com",
    subject="Invoice",
    html="<p>Please find your invoice attached.</p>",
    attachments=[
        Attachment.from_path("/path/to/invoice.pdf"),
        Attachment.from_content("Hello World", "hello.txt"),
    ],
)
```

## Error handling

```python theme={null}
from jetemail import JetEmail, JetEmailError

try:
    client.email.send(...)
except JetEmailError as e:
    print(e.status_code, e.message, e.response)
```

Common status codes: **400** invalid request, **401** bad/missing API key, **500** server error.

***

For additional examples and the full option list, see the **[PyPI package page](https://pypi.org/project/jetemail/)**. REST details: [API reference](/api-reference/introduction).
