v2 API Python Code Example


(warning)

This documentation is for the SendGrid Web API v2

To access all the latest features and upcoming developments, please see our v3 API. For assistance with transitioning, refer to our migration guide.

(information)

Info

We recommend using SendGrid Python, our client library, available on GitHub(link takes you to an external page), with full documentation.

(information)

Info

The library does not officially support the V2 API, but you can use V2 with an older version of the library. For more information, see Continue Using V2 in Python(link takes you to an external page).


Using SendGrid's Python Library

using-sendgrids-python-library page anchor
1
# using SendGrid's Python Library
2
# https://github.com/sendgrid/sendgrid-python
3
import sendgrid
4
5
client = sendgrid.SendGridClient("SENDGRID_APIKEY")
6
message = sendgrid.Mail()
7
8
message.add_to("test@sendgrid.com")
9
message.set_from("you@example.com")
10
message.set_subject("Sending with SendGrid is Fun")
11
message.set_html("and easy to do anywhere, even with Python")
12
13
client.send(message)