---
"@context": https://schema.org
"@type": TechArticle
"@id": https://www.twilio.com/docs/sendgrid/for-developers/sending-email/v3-python-code-example#article
headline: v3 API Python Code Example
description: Integrate Twilio SendGrid using the Python client library with complete documentation. Detailed example with API integration tips and resources.
url: https://www.twilio.com/docs/sendgrid/for-developers/sending-email/v3-python-code-example
inLanguage: en
dateModified: 2026-07-23T16:57:51.000Z
author:
  "@type": Organization
  name: Twilio Developer Education Team
publisher:
  "@type": Organization
  name: Twilio
---

# v3 API Python Code Example

> \[!NOTE]
>
> We recommend using SendGrid Python, our client library, [available on GitHub](https://github.com/sendgrid/sendgrid-python), with full documentation.

> \[!NOTE]
>
> Do you have an [API Key](https://app.sendgrid.com/settings/api_keys) yet? If not, go get one. You're going to need it to integrate!

## Using SendGrid's Python Library

The following example sends a single email with the Twilio SendGrid Python library. Set your API key in the `SENDGRID_API_KEY` environment variable, then build and send the message.

```python title="Send an email with the Twilio SendGrid Python library"
# using SendGrid's Python Library
# https://github.com/sendgrid/sendgrid-python
import os
from sendgrid import SendGridAPIClient
from sendgrid.helpers.mail import Mail

message = Mail(
    from_email='from_email@example.com',
    to_emails='to@example.com',
    subject='Sending with Twilio SendGrid is Fun',
    html_content='<strong>and easy to do anywhere, even with Python</strong>')
try:
    sg = SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
    response = sg.send(message)
    print(response.status_code)
    print(response.body)
    print(response.headers)
except Exception as e:
    print(e.message)
```
