Skip to content

altissimo-hq/sendgrid-python

Repository files navigation

altissimo-sendgrid

CI Python License Code style: ruff

Reusable SendGrid email client for Altissimo Python projects.

Features

  • 📧 Plain text emails via send_text()
  • 🎨 HTML emails via send_html()
  • 📋 Dynamic templates via send_template()
  • 🏗️ Factory methodSendGridClient.from_env() reads SENDGRID_API_KEY from the environment
  • 🔌 Optional dependencysendgrid SDK is lazily imported with a helpful error message
  • 📐 Typed — full type annotations with py.typed PEP 561 marker
  • Consistent return type — all methods return a SendResult dataclass

Requirements

  • Python 3.11+

Installation

pip install altissimo-sendgrid[sendgrid]   # core + SendGrid SDK

Quick Start

from altissimo.sendgrid import SendGridClient

client = SendGridClient.from_env()

# Plain text
result = client.send_text(
    to="user@example.com",
    subject="Hello",
    body="Welcome aboard!",
)

# HTML
result = client.send_html(
    to="user@example.com",
    subject="Hello",
    html="<h1>Welcome!</h1>",
    reply_to="support@example.com",
)

# Template
result = client.send_template(
    to="user@example.com",
    template_id="d-abc123",
    dynamic_data={"first_name": "Alice", "year": 2026},
)

assert result.ok
assert result.status_code == 202

API Reference

SendGridClient

Method Description
SendGridClient(api_key, default_from?) Create a client with an explicit API key
SendGridClient.from_env(env_var?, default_from?) Create a client from an environment variable
send_text(to, subject, body, from_email?, reply_to?) Send a plain-text email
send_html(to, subject, html, from_email?, reply_to?) Send an HTML email
send_template(to, template_id, dynamic_data?, from_email?, reply_to?) Send a dynamic template email

SendResult

Field Type Description
ok bool Whether the request succeeded (2xx status)
status_code int HTTP status code from SendGrid
body str Response body
headers dict[str, str] Response headers
error str | None Error message on failure

Architecture

altissimo.sendgrid
├── __init__.py       # Public API surface
├── client.py         # SendGridClient with lazy SDK initialization
├── exceptions.py     # SendGridError, SendGridImportError
├── models.py         # SendResult dataclass
└── py.typed          # PEP 561 marker

Development

# Install all dependencies
poetry sync

# Run tests
poetry run pytest

# Run tests with coverage
poetry run pytest --cov=altissimo --cov-report=term-missing

# Run linters
poetry run ruff check .
poetry run ruff format --check .

See CONTRIBUTING.md for detailed development guidelines.

Changelog

See CHANGELOG.md for version history.

Security

For reporting security vulnerabilities, see SECURITY.md.

License

GNU General Public License v3.0 or later — see LICENSE for details.

About

Reusable SendGrid email client for sending text, HTML, and template emails

Topics

Resources

License

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages