Skip to main content

Async SendGrid client based on httpx

Project description

aiosendgrid

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("test@example.com")
to_email = To("test@example.com")
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": "test@example.com"}],
            "subject": "Sending with SendGrid is Fun",
        }
    ],
    "from": {"email": "test@example.com"},
    "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)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aiosendgrid-0.1.0.tar.gz (2.9 kB view hashes)

Uploaded Source

Built Distribution

aiosendgrid-0.1.0-py3-none-any.whl (3.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page