Reusable SendGrid email client for Altissimo Python projects.
- π§ Plain text emails via
send_text() - π¨ HTML emails via
send_html() - π Dynamic templates via
send_template() - ποΈ Factory method β
SendGridClient.from_env()readsSENDGRID_API_KEYfrom the environment - π Optional dependency β
sendgridSDK is lazily imported with a helpful error message - π Typed β full type annotations with
py.typedPEP 561 marker - β
Consistent return type β all methods return a
SendResultdataclass
- Python 3.11+
pip install altissimo-sendgrid[sendgrid] # core + SendGrid SDKfrom 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| 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 |
| 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 |
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
# 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.
See CHANGELOG.md for version history.
For reporting security vulnerabilities, see SECURITY.md.
GNU General Public License v3.0 or later β see LICENSE for details.