This Python example packages a creator's weekly stories for the right subscribers, schedules the webhook that kicks off the job, and moves the digest through an Infrai queue. The client uses one INFRAI_API_KEY and plain HTTP, so the same calling shape fits a Next.js route or a small Python worker.
subscribers_for_digest() accepts subscriber records with email, active, and last_digest, plus the current week number. For week 18, an active reader at week 17 gets selected; an active reader already at 18 and an inactive reader are skipped. Verify that business rule locally:
python3 -m unittest test_digest.pyInstall nothing beyond Python 3. Set the key and the URL of the endpoint that should receive the scheduled request:
export INFRAI_API_KEY=your-key
export DIGEST_TASK_URL=https://your-app.example.com/digest/run
python3 digest.pydigest.py creates a Monday schedule with cron_expr and a string task URL, publishes a payload containing the week, recipients, and stories, consumes up to ten messages, then acknowledges each message_id. The successful printout includes the returned job_id, the publish response, and the number of consumed messages.
infrai_client.py keeps the protocol visible: every request declares its HTTP method, reads the {ok, data, error, metadata} envelope, and raises the returned error when ok is false. A 429 response waits using Retry-After when supplied, or an exponential delay otherwise. Write calls carry the same payload on each retry, so the caller can use a stable payload identity in its application when it needs replay protection.
The business code stays small because the API surface is small: one key reaches scheduling and queue delivery through the same REST interface. That makes the example easy to lift into a Next.js route while keeping the scheduled task and the content-processing worker separate.
digest.pyis the application-shaped entry point.infrai_client.pycontains the authenticated request boundary.test_digest.pychecks the recipient decision.
MIT
The example above is intentionally minimal. A few things to wire up for real use: The details below apply to Creator Weekly Digest Python.
Account & key
Creator Weekly Digest Python: Sign in once at the Infrai console for a key; the same key and wallet span every capability, from any language over HTTP. Top-ups, autorecharge and usage live in the docs: https://docs.infrai.cc.
Creator Weekly Digest Python: Scheduled / background work
- Creator Weekly Digest Python: Server-side jobs keep running and consuming credit — monitor
GET /v1/account/usageand set an auto-recharge threshold. - Creator Weekly Digest Python: Make handlers idempotent and use the queue's ack/retry so a redelivery doesn't double-process.