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

Uploaded Python 3

File details

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

File metadata

  • Download URL: ai_newsletter-1.0.0.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.0.tar.gz
Algorithm Hash digest
SHA256 90396322a427b561928f8cacbbeb67729653f1c7d200b362bc29068e9043b602
MD5 e697dbe9c7efbe838a2c529c34dadc4d
BLAKE2b-256 4d80c556bdbc3b48bc77367c2f6c3884a2b8af3a20cf5715f727c4218bc04d2b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ai_newsletter-1.0.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7b7eeb4a3acd2fef6576c507d636b7c1a0d4f028c862df0ba3a6d471ad25fce2
MD5 3b0272fabec33f143be0c9bfbe411cd3
BLAKE2b-256 05ee3536009e0ff747f85d2a755a7dd74b7e742fa1d068d5afe78fd8ad614201

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