Send email with Python
The official SDK, or one requests call if you would rather not add a dependency.
You need a verified sending domain and an API key from Settings › API Keys. If neither exists yet, the quickstart covers both in a couple of minutes.
Install
pip install sending-sdkSend
import os
from sending import Sending
client = Sending(api_key=os.environ["SENDING_API_KEY"])
res = client.emails.send({
"from": "Acme <[email protected]>",
"to": "[email protected]",
"subject": "Welcome",
"html": "<p>You're in.</p>",
"idempotencyKey": "welcome-sara-001",
})
print(res["id"])A successful call answers 202 with the message id: accepted and queued, not yet delivered. Delivery, opens, bounces and complaints arrive later, on webhooks or in the dashboard.
What changes in Python
The package on PyPI is sending-sdk and the import is sending. The body keys are camelCase, because they are the JSON field names rather than Python parameters.
The thing that catches people
from is a reserved word in Python, so it can only be a dict key and never a keyword argument. That is why the SDK takes the payload as a dict.
Next
- All the fields: cc and bcc, reply-to, attachments, templates, scheduling.
- Webhooks: delivery, bounce and complaint events, signed with HMAC.
- Domains: SPF, DKIM and MAIL FROM, and why sending is refused until they are in place.
- MCP: the same operations as tools, when the one writing the code is an agent.