Official Python SDK for the Signal AI / AI Newsletter public REST API.
Project description
ai-newsletter (Python)
Official Python SDK for the Signal AI public REST API.
Install
pip install ai-newsletter
Quick start
from ai_newsletter import AiNewsletter
with AiNewsletter(api_key="sk_live_…") as client: # or sk_test_…
client.subscribers.create(newsletter_id="d5…", email="jane@example.com")
job = client.sends.create(
newsletter_id="d5…",
type="transactional",
to="jane@example.com",
subject="Welcome!",
html="<p>Hi Jane</p>",
)
stats = client.analytics.for_newsletter("d5…")
print(stats["open_rate"])
Pagination
for sub in client.subscribers.iterate(newsletter_id="d5…"):
print(sub["email"])
Retries & timeouts
Retries (with exponential backoff and jitter) are automatic for
408 / 425 / 429 / 5xx and network errors. Retry-After is honoured.
client = AiNewsletter(api_key="…", max_retries=5, timeout=60.0)
Errors
from ai_newsletter import AiNewsletterError
try:
client.subscribers.create(...)
except AiNewsletterError as e:
print(e.status, e.code, str(e), e.retry_after)
Verify webhooks
from ai_newsletter import verify_webhook_signature
if not verify_webhook_signature(raw_body, request.headers["X-Webhook-Signature"], SECRET):
abort(401)
Test mode
Pass an sk_test_ key — all traffic targets the sandbox tables.
client.is_test reports the mode.
License
MIT
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
ai_newsletter-1.0.1.tar.gz
(5.4 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters