Skip to main content

Durable jobs/events for Demystify: asyncio mirror of @demystify/events (enqueue, transactional outbox, idempotent workers, backoff+jitter, DLQ).

Project description

demystify-events

Durable jobs and events for Python — the asyncio mirror of the TypeScript @demystify/events runtime. Postgres-backed (pgmq) with a transactional outbox, idempotent consumers, exponential backoff + full jitter retries, and a dead-letter queue — with a full-fidelity in-memory driver so the same code runs offline with no database.

Part of the Demystify Core Services suite.

Install

pip install demystify-events
# real Postgres driver (psycopg + connection pool):
pip install "demystify-events[pg]"

Quickstart (offline, no database)

from demystify_events import create_events_client
from demystify_events.adapters.memory import MemoryQueueDriver

client = create_events_client(driver=MemoryQueueDriver())

# enqueue a job
await client.enqueue("email.send", {"to": "user@example.com"})

# process it (idempotent, retried with backoff+jitter, DLQ on poison)
async def handler(ctx, job):
    ...  # do work; effects committed in the same transaction as the ack
await client.work("email.send", handler)

Switch to real Postgres by passing the psycopg driver (from the [pg] extra) with a database_url — the handler contract is identical.

Postgres requirements

PsycopgPgmqDriver runs on the pgmq Postgres extension — install it in the target database first (CREATE EXTENSION pgmq;). Stock postgres images do not ship pgmq; use one that does, e.g. ghcr.io/demystify-systems/postgres-pgvector-pgmq (ours, pgvector + pgmq combined) or quay.io/tembo/pg16-pgmq. If the extension is missing, driver operations raise an actionable RuntimeError ("pgmq extension not available in this database. Run CREATE EXTENSION pgmq; ...") with the original psycopg error chained as __cause__, instead of a cryptic relation "pgmq.q_x" does not exist.

MemoryQueueDriver (alias EphemeralQueueDriver — the same class) is ephemeral: jobs live in process memory and are lost on restart. Outside pytest runs its constructor emits a warnings.warn once per process; set DMSTFY_EVENTS_ALLOW_EPHEMERAL=1 to silence it when running in-memory on purpose.

What's in the box

  • create_events_client / EventsClient — enqueue, transactional enqueue_in_tx, workers
  • contract_backoff, full_jitter_backoff, BackoffConfig — retry schedules
  • ContractRegistry — JSON-schema event-type validation
  • make_envelope / validate_envelope — canonical event envelopes
  • Adapters: MemoryQueueDriver (offline) and psycopg (Postgres/pgmq)

The published wheel is self-contained — it does not vendor demystify-platform-contracts; contract convergence is asserted by the test suite. See the module README for the delivery guarantees, chaos-test results, and the /ops/v1 API.

License

MIT © Demystify Systems

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

demystify_events-0.3.0.tar.gz (113.3 kB view details)

Uploaded Source

Built Distribution

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

demystify_events-0.3.0-py3-none-any.whl (41.3 kB view details)

Uploaded Python 3

File details

Details for the file demystify_events-0.3.0.tar.gz.

File metadata

  • Download URL: demystify_events-0.3.0.tar.gz
  • Upload date:
  • Size: 113.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for demystify_events-0.3.0.tar.gz
Algorithm Hash digest
SHA256 58c13ccad25ee278b9a0aac5f18f6f86e77b5b0e3ad325d05c82160a73f999f1
MD5 82aaaac43016fdfe71417e3d37600da0
BLAKE2b-256 7db26ea4f635aae8282df53ff87f237e21a06050cab851658660e42cd851903c

See more details on using hashes here.

Provenance

The following attestation bundles were made for demystify_events-0.3.0.tar.gz:

Publisher: publish-pypi.yml on demystify-systems/ai-services-tools

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file demystify_events-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for demystify_events-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 04b97a849f157b9543e8facafcc1cca361f6b2498b199aafc6af65c0fc0ddb75
MD5 5ae623fd495ed089c10d5f69fef3dc44
BLAKE2b-256 965b33e827a889a80212e8405a29a9e9440ff0e4b28f6bfaa65443e3f7a16001

See more details on using hashes here.

Provenance

The following attestation bundles were made for demystify_events-0.3.0-py3-none-any.whl:

Publisher: publish-pypi.yml on demystify-systems/ai-services-tools

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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