Install the SDK
pip install groundmailFor the Django email backend:
pip install 'groundmail[django]'Configure your API key
export GROUNDMAIL_API_KEY=gm_your_key_hereSend an email (API client)
import os
from groundmail import Groundmail
tx = Groundmail(os.environ["GROUNDMAIL_API_KEY"])
result = tx.emails.send(
from_="ops@yourdomain.com",
to="user@example.com",
subject="Your receipt",
html="<p>Thanks for your purchase.</p>",
)
print(result["id"], result["status"])Django email backend (recommended)
# settings.py
EMAIL_BACKEND = "groundmail.django.EmailBackend"
# Uses GROUNDMAIL_API_KEY from the environment.
# Optional: EMAIL_HOST-style settings are not used; configure the API key via env.Then send as usual:
from django.core.mail import EmailMultiAlternatives
msg = EmailMultiAlternatives(
subject="Your receipt",
body="Thanks for your purchase.",
from_email="ops@yourdomain.com",
to=["user@example.com"],
)
msg.attach_alternative("<p>Thanks for your purchase.</p>", "text/html")
msg.extra_headers["X-Groundmail-Tag"] = "campaign=welcome"
msg.extra_headers["X-Groundmail-Idempotency-Key"] = "receipt-123"
msg.send()X-Groundmail-Tag uses name=value. Pass a list of tag strings for multiple tags. Custom non-reserved headers are forwarded to the API headers field. Optional: X-Groundmail-Scheduled-At (ISO 8601).
Resources
The client includes thin wrappers for common API resources:
tx.emails— send, batch, list, cancel, resend, test webhooks, deliverability insightstx.domains— create, verify, apply DNS, update, deletetx.webhooks— CRUD for webhook endpointstx.templates— CRUD plus publishtx.suppressions— list, create, removetx.validate(email)andtx.validate_batch(emails)— check addresses before you accept them (validation);mailbox_check=Truealso confirms the mailbox exists
See the API reference for request fields. The Python SDK accepts the same JSON shapes as the REST API.
Source
Package source lives in python/ in the public groundmail-sdks repository.