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.2.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.2-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ai_newsletter-1.0.2.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.2.tar.gz
Algorithm Hash digest
SHA256 2a9d45e900a96a0d3c410b29a3e707c925933ecd6c68d7f05e1baa6ee8d13879
MD5 e25db6610a686e96211351b1a0904b26
BLAKE2b-256 246ac50a4713f10427ad18803f313b1be6dade325d5c6a2b1dfa1c58ab9a3a14

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ai_newsletter-1.0.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8da40b1f499fef202f7b603e560fcbcc0b326ed2dbc403822d3d1934114f8a1b
MD5 31011cfe85dd3dda27b1fd30bda1a7b2
BLAKE2b-256 43fd63512ee63e0901fe97d92797b4596e69859328b149694b90efff085ecf8e

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