# Send with Python

> Send email from Python with the requests library.

## Prerequisites

- A Sendtern [API key](https://sendtern.com/docs/authentication) stored as `SENDTERN_API_KEY`
- Python 3.8 or newer

1. **Install requests**: Any HTTP client works. This guide uses `requests`.

```
pip install requests
```

2. **Send an email**: Create `send.py`.

```
# send.py
import os
import uuid
import requests

res = requests.post(
    "https://sendtern.com/emails",
    headers={
        "Authorization": f"Bearer {os.environ['SENDTERN_API_KEY']}",
        "Idempotency-Key": str(uuid.uuid4()),
    },
    json={
        "from": "Acme <hello@mail.example.com>",
        "to": ["you@example.com"],
        "subject": "Hello from Python",
        "html": "<p>It works!</p>",
    },
    timeout=10,
)

res.raise_for_status()
print(res.json())
```

3. **Check the response**: A successful request returns `200 OK` with the email id. Use it to look the email up later.

```
{
  "id": "47be30ca-24b7-48fb-b35d-ff287b89e66d"
}
```

> **tip:** Replace the example sender with an address on your [verified domain](https://sendtern.com/docs/domains).
