Skip to content

kozlek/aiosendgrid

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

aiosendgrid

pypi versions code style license

A simple SendGrid asynchronous client based on httpx.

Installation

pip install aiosendgrid

Or, to include the optional SendGrid helpers support, use:

pip install aiosendgrid[helpers]

Usage

With Mail Helper Class

import aiosendgrid
from sendgrid.helpers.mail import Content, Email, Mail, To

SENDGRID_API_KEY = "SG.XXX"

from_email = Email("[email protected]")
to_email = To("[email protected]")
subject = "Sending with SendGrid is Fun"
content = Content("text/plain", "and easy to do anywhere, even with Python")
mail = Mail(from_email, to_email, subject, content)

async with aiosendgrid.AsyncSendGridClient(api_key=SENDGRID_API_KEY) as client:
    response = await client.send_mail_v3(body=mail.get())

More info on sendgrid-python official repository.

Without Mail Helper Class

import aiosendgrid

SENDGRID_API_KEY = "SG.XXX"

data = {
    "personalizations": [
        {
            "to": [{"email": "[email protected]"}],
            "subject": "Sending with SendGrid is Fun",
        }
    ],
    "from": {"email": "[email protected]"},
    "content": [
        {"type": "text/plain", "value": "and easy to do anywhere, even with Python"}
    ],
}

async with aiosendgrid.AsyncSendGridClient(api_key=SENDGRID_API_KEY) as client:
    response = await client.send_mail_v3(body=data)

About

Async SendGrid client based on httpx

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published