or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

configuration.mdemail-backend.mdindex.mdsignals.mdtemplates-personalization.mdwebhooks.md
tile.json

tessl/pypi-django-sendgrid-v5

Django email backend implementation compatible with SendGrid API v5+ for seamless email delivery integration

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/django-sendgrid-v5@1.3.x

To install, run

npx @tessl/cli install tessl/pypi-django-sendgrid-v5@1.3.0

index.mddocs/

Django SendGrid v5

A Django email backend implementation that integrates with SendGrid's REST API v5+ for reliable email delivery. This package provides seamless email sending functionality through Django's standard email API while offering advanced SendGrid-specific features like dynamic templates, personalization, webhook signature verification, tracking, and scheduling.

Package Information

  • Package Name: django-sendgrid-v5
  • Language: Python
  • Installation: pip install django-sendgrid-v5

Core Imports

from sendgrid_backend import SendgridBackend, __version__

For Django settings integration:

# In settings.py
EMAIL_BACKEND = "sendgrid_backend.SendgridBackend"
SENDGRID_API_KEY = "your-sendgrid-api-key"

Basic Usage

from django.core.mail import send_mail, EmailMessage

# Simple email sending using Django's standard API
send_mail(
    'Subject here',
    'Here is the message.',
    'from@example.com',
    ['to@example.com'],
    fail_silently=False,
)

# Enhanced email with SendGrid-specific features
msg = EmailMessage(
    subject='Advanced Email',
    body='Email content',
    from_email='sender@example.com',
    to=['recipient@example.com'],
)

# Add SendGrid-specific attributes
msg.template_id = "d-abc123def456"
msg.dynamic_template_data = {"name": "John", "product": "Widget"}
msg.categories = ["marketing", "newsletter"]
msg.send()

Architecture

The package extends Django's BaseEmailBackend with SendGrid API integration:

  • SendgridBackend: Main email backend class that translates Django EmailMessage objects to SendGrid API calls
  • Django Settings Integration: Seamless configuration through Django settings for API keys, tracking, and sandbox mode
  • Version Compatibility: Automatic detection and support for both SendGrid API v5 and v6 with internal compatibility handling
  • Signal System: Django signal emission for email delivery events with success/failure tracking
  • Webhook Security: Cryptographic signature verification for SendGrid webhook endpoints

Capabilities

Email Backend

The core SendGrid email backend implementation that replaces Django's default email backend with SendGrid API integration.

class SendgridBackend(BaseEmailBackend):
    def __init__(self, *args, **kwargs): ...
    def send_messages(self, email_messages) -> int: ...
    def echo_to_output_stream(self, email_messages): ...

Email Backend

Template and Personalization

Dynamic template support with variable substitution and personalized content for individual recipients.

# EmailMessage extensions for templates
msg.template_id = "template-id" 
msg.dynamic_template_data = dict  # v6+
msg.substitutions = dict  # v5
msg.personalizations = list  # Advanced personalization

Templates and Personalization

Configuration and Settings

Django settings integration for API keys, tracking options, sandbox mode, and other SendGrid-specific configurations.

# Django settings
SENDGRID_API_KEY = str
SENDGRID_SANDBOX_MODE_IN_DEBUG = bool
SENDGRID_TRACK_EMAIL_OPENS = bool
SENDGRID_TRACK_CLICKS_HTML = bool
SENDGRID_TRACK_CLICKS_PLAIN = bool

Configuration

Webhook Integration

Secure webhook handling with signature verification for processing SendGrid delivery events and email tracking data.

@verify_sendgrid_webhook_signature
def webhook_handler(request): ...

def check_sendgrid_signature(request) -> bool: ...

Webhooks

Signals and Events

Django signal system for handling email delivery events, enabling custom logging, analytics, and error handling.

sendgrid_email_sent = django.dispatch.Signal()
# Signal arguments: sender, message, fail_flag

Signals

Types

# Package version
__version__: str  # Package version string (e.g., "1.3.0")

# Email message extensions
class EmailMessage:
    # Template support
    template_id: str
    dynamic_template_data: dict  # v6+
    substitutions: dict  # v5
    
    # Personalization
    personalizations: list
    make_private: bool
    custom_args: dict
    
    # Scheduling and delivery
    send_at: int  # Unix timestamp
    ip_pool_name: str
    
    # Organization and tracking
    categories: list[str]
    asm: dict  # Unsubscribe groups
    reply_to_list: list[str]  # v6+
    
    # Advanced settings
    mail_settings: MailSettings
    tracking_settings: TrackingSettings