
Product
Introducing Scala and Kotlin Support in Socket
Socket now supports Scala and Kotlin, bringing AI-powered threat detection to JVM projects with easy manifest generation and fast, accurate scans.
A modern, asynchronous SendGrid client built on top of httpx
. This library provides a simple and efficient way to send emails using SendGrid's API with Python's async/await syntax.
Install the package using pip:
pip install sendgrid-async
from async_sendgrid import SendgridAPI
from sendgrid.helpers.mail import Mail
# Initialize the client
sendgrid = SendgridAPI(api_key="YOUR_API_KEY")
# Create and send an email
email = Mail(
from_email="from@example.com",
to_emails="to@example.com",
subject="Hello World",
plain_text_content="Hello World!",
)
response = await sendgrid.send(email)
Optimize performance with connection pooling:
from async_sendgrid import SendgridAPI
from async_sendgrid.pool import ConnectionPool
pool = ConnectionPool(
max_connections=20,
max_keepalive_connections=10,
keepalive_expiry=10.0,
)
sendgrid = SendgridAPI(
api_key="YOUR_API_KEY",
pool=pool,
)
Send emails on behalf of subusers:
sendgrid = SendgridAPI(
api_key="YOUR_API_KEY",
on_behalf_of="John Smith",
)
Use custom API endpoints:
sendgrid = SendgridAPI(
api_key="YOUR_API_KEY",
endpoint="https://custom.endpoint.com/v3/mail/send",
)
Monitor and trace your SendGrid operations with OpenTelemetry:
from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter
# Configure OpenTelemetry
tracer_provider = TracerProvider()
trace.set_tracer_provider(tracer_provider)
# Add your exporter
otlp_exporter = OTLPSpanExporter()
span_processor = BatchSpanProcessor(otlp_exporter)
tracer_provider.add_span_processor(span_processor)
The library automatically tracks:
Control telemetry behavior with environment variables:
# Disable telemetry
SENDGRID_TELEMETRY_IS_ENABLED=false
# Custom span name
SENDGRID_TELEMETRY_SPAN_NAME=custom.span.name
Robust error handling for API operations:
try:
response = await sendgrid.send(email)
except Exception as e:
# Handle the error
print(f"Error sending email: {e}")
# Clone the repository
git clone https://github.com/yourusername/async-sendgrid.git
cd async-sendgrid
# Install development dependencies
pip install -e ".[test]"
# Run all tests
pytest
# Run with coverage
pytest --cov=async_sendgrid
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
FAQs
SendGrid using an httpx client
We found that sendgrid-async demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports Scala and Kotlin, bringing AI-powered threat detection to JVM projects with easy manifest generation and fast, accurate scans.
Application Security
/Security News
Socket CEO Feross Aboukhadijeh and a16z partner Joel de la Garza discuss vibe coding, AI-driven software development, and how the rise of LLMs, despite their risks, still points toward a more secure and innovative future.
Research
/Security News
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.