[SEND][ACK]

sendack (Python)

Sendack's Python client: standard library only (http.client, so live streams stream), Python 3.9+. It speaks Sendack's Connect API with binary protobuf (crates/proto-server/proto/sendack/v1/api.proto), its few messages encoded by hand.

from sendack import Sendack, Preferences

# token: a string, or a callable(refresh) returning one (refresh is True after `unauthenticated`); omit it for an
# open server
sendack = Sendack("https://sendack.lunaor.com", token=lambda refresh: get_access_token(refresh))

sendack.publish("chat.42", "m1", b'{"text": "hi"}')     # Published(version=…, duplicate=False, pos="…")
history = sendack.read("chat.42")                       # [Event(pos, id, data, publisher)] from the beginning
recent = sendack.read("chat.42", latest=True, limit=50)  # the newest 50, oldest first

live = sendack.subscribe("chat.42", after=recent[-1].pos if recent else "")
for ev in live:                                          # resumes by itself: no gap, no repeat
    print(ev.pos, ev.json())

Every failure is a SendackError with Connect's code, the human-readable message, retry_after_s and the refusal's www_authenticate header (None unless sent). A live subscription keeps hello and position (the last position seen); on unavailable, a dropped connection or an expired token (unauthenticated, when the token is a callable) it reconnects from position with jittered backoff (min_delay, max_delay, on_error); other errors raise. A connection that goes silent for idle seconds (default 60: twice the server's 25 s keep-alive on a quiet topic; any frame counts, a keep-alive included) is given up on and resumed from position the same way, so a half-dead TCP connection cannot stall it. close() from any thread ends it, reconnect() resumes at once, ready is set once it's live.

Event paging and webhook history (plain HTTP calls):

page = sendack.events("chat.42", after="", limit=100)      # EventsPage(events, next_after): oldest first; next_after is None on a short page
for ev in sendack.iter_events("chat.42", limit=100): ...   # pages until the end, then stops: it never waits for new events (subscribe does)

page = sendack.webhook_deliveries("crm", limit=20)         # DeliveriesPage(webhook, deliveries, next_before), newest first; pass next_before as `before`
attempt = sendack.webhook_redeliver("crm", page.deliveries[0].pos)   # the DeliveryAttempt it made
sub = sendack.get_subscription("billing")                  # cursor, leased_upto, outstanding, and consumers: [Consumer(subject, client_id, leases, oldest_lease_us)] (None from list_subscriptions)
rules = sendack.notify_rules("chat.42")                    # NotifyRules(topic, enabled, recipients, push, email): push/email say what this server can carry
sendack.set_notify_rules("chat.42", True)                  # NodResult (a person is asked, as for rotate_webhook_secret); value: on or off, True if that changed anything. Off when there is none: not_found
page = sendack.org_audit("acme", before=None, limit=20)    # AuditPage(audit, next_before), newest first; owners and staff only (403 for a member)
for rec in sendack.iter_org_audit("acme"): ...             # pages to the oldest, then stops (no polling)

A DeliveryAttempt is seq, pos, id, at_ms, ok, status, latency_ms, attempt, next_retry_ms, redelivery, host (status is the receiver's HTTP status as text, or an error class such as timeout or dns). webhook_redeliver is limited to 10 a minute per webhook: beyond that it raises SendackError with code == "resource_exhausted" and retry_after_s (None unless the server sent Retry-After).

Also: create_subscription, pull, ack, nack, seek, list_subscriptions, get_subscription, delete_subscription; create_webhook, list_webhooks, get_webhook, delete_webhook, rotate_webhook_secret (the old secret signs beside the new for 24 h); and notifications: notify_key, subscribe_push, unsubscribe_push, get_preferences, set_preferences(Preferences(push, quiet, email)).

Tests

python3 -I -m unittest in this directory runs the unit tests (a fake HTTP server; no Sendack server needed).

Proof

python3 -I prove_sdk.py http://127.0.0.1:18197 against a running sendack-proto serve (open, with a VAPID key): publish and duplicates, reads, a live subscription through a proxy that cuts a connection mid-stream, kills one, refuses for half a second and answers an expired token (no gap or repeat), the subscription, webhook (signatures before and after a rotation) and notification calls.