Skip to main content

SendGrid using a client based on httpx.

Project description

Python Python
Package PyPI Latest Release PyPI Downloads
Meta License - MIT

Async-Sendgrid

Sendgrid-Async is a simple asynchronous client built upon the httpx library.

Installation

You can install Sendgrid-Async using pip with the following command:

pip install sendgrid-async

Usage

Here is a brief script demonstrating how to send an email using Async-Sendgrid:

First, import the SendgridAPI from the sendgrid-async package. Then, create a SendgridAPI object using your API key.

from async_sendgrid import SendgridAPI
import os

API_KEY = os.environ.get('SECRET_API_KEY')
sendgrid = SendgridAPI(API_KEY)

Next, we can create an email using the original sendgrid library as follows:

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

from_email = Email("test@example.com")
to_email = To("test@example.com")
subject = "Lorem ipsum dolor sit amet, consectetur adipiscing elit"
content = Content("text/plain", "Sed varius ligula ac urna vehicula ultrices. Nunc ut dolor sem.")

mail = Mail(
    from_email=from_email,
    to_email=to_email,
    subject=subject,
    content=content
    )

An email can be sent to sendgrid servers with the send API of the SendgridAPI instance:

async with sendgrid as client:
    response = await client.send(data)

For testing purposes, you can modify the API endpoint as follows:

sendgrid = SendgridAPI(api_key="SECRET_API_KEY", endpoint="https://localhost:3000/v3/mail/send")

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

sendgrid_async-2.0.1.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

sendgrid_async-2.0.1-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file sendgrid_async-2.0.1.tar.gz.

File metadata

  • Download URL: sendgrid_async-2.0.1.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for sendgrid_async-2.0.1.tar.gz
Algorithm Hash digest
SHA256 8a432eeb9883e41f63755473c87bcb0e3ae57bcbeeab1acfe058203bcf9d3796
MD5 070f340ac07bbc9828a7212dc32d3ca8
BLAKE2b-256 c9d31f15af35a72f815555732132a8749b05d2be42847a0f2185839da5c1b3ea

See more details on using hashes here.

File details

Details for the file sendgrid_async-2.0.1-py3-none-any.whl.

File metadata

  • Download URL: sendgrid_async-2.0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for sendgrid_async-2.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 58f11063b264b61f6a154db40e0d2468bb28b8f2f6653b45c5d422a51d0bca0b
MD5 e721f3f0f538dc3259c25c452477addc
BLAKE2b-256 5246e8fa6b84b088383ee0aa80a1078ae38d0d8376e78213d809d6260ae76e37

See more details on using hashes here.

Supported by

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