Skip to main content

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)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ai_newsletter-1.0.1-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file ai_newsletter-1.0.1.tar.gz.

File metadata

  • Download URL: ai_newsletter-1.0.1.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for ai_newsletter-1.0.1.tar.gz
Algorithm Hash digest
SHA256 b24925b13584e3009ba47871f2f2f740aaf4b1ee40a0c45549a0a280e6e9e81c
MD5 cecd1e3fee899eb669871225370646a2
BLAKE2b-256 29721fd9419172c5a57569e2a16bcc533836ce18c69db73e6df1e6e7b0c328e5

See more details on using hashes here.

File details

Details for the file ai_newsletter-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: ai_newsletter-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for ai_newsletter-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 71cbbd0001558a75fafb6b548d04130dec3c012e255a069a0d2dfc94ce27f97a
MD5 c2074f7b39c3c9fa4f26c293d25b8085
BLAKE2b-256 29d7f81b54cf29bc0c929f05c33af5966e1458296e8797bc20a73a89aced8602

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page