SendGrid
Official Python SDK for the Twilio SendGrid Email API v3. Owned by Twilio. Two send patterns exist: Mail helper class and raw dict. v6.x is a breaking change from v5.x. Free plan retired May 2025. SDK last meaningfully updated Sep 2025 — in maintenance mode.
Warnings
- breaking v6.x is a breaking change from v5.x. The SendGridAPIClient constructor signature changed, and the send pattern via sg.client.mail.send.post() requires a raw dict, not the old Mail object's .get() call in some patterns.
- gotcha 202 Accepted does not mean delivered. SendGrid queues emails and delivers asynchronously. Checking response.status_code == 200 will always fail — the success code is 202.
- gotcha The from_email must be a verified sender (Single Sender Verification) or from a domain with Domain Authentication set up. Sending from unverified addresses returns 403 Forbidden.
- gotcha SendGrid Free plan was retired May 27, 2025. New accounts can no longer use the free tier after this date. Existing free accounts had 60 days before billing required.
- gotcha SDK GitHub repository last updated September 2025. The library is in maintenance mode — new SendGrid features may not be reflected in the SDK. Use sg.client._('endpoint').post(request_body=data) for endpoints not in the helper.
Install
-
pip install sendgrid
Imports
- SendGridAPIClient (Mail helper)
from sendgrid import SendGridAPIClient from sendgrid.helpers.mail import Mail message = Mail( from_email='from@example.com', to_emails='to@example.com', subject='Subject', html_content='<strong>Hello</strong>' ) sg = SendGridAPIClient(os.environ.get('SENDGRID_API_KEY')) response = sg.send(message)
Quickstart
import os
from sendgrid import SendGridAPIClient
from sendgrid.helpers.mail import Mail
message = Mail(
from_email='sender@example.com',
to_emails='recipient@example.com',
subject='Sending with SendGrid',
html_content='<strong>Hello from Python!</strong>'
)
try:
sg = SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
response = sg.send(message)
print(response.status_code) # 202 = accepted
except Exception as e:
print(str(e))