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, transactionalenqueue_in_tx, workerscontract_backoff,full_jitter_backoff,BackoffConfig— retry schedulesContractRegistry— JSON-schema event-type validationmake_envelope/validate_envelope— canonical event envelopes- Adapters:
MemoryQueueDriver(offline) andpsycopg(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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
58c13ccad25ee278b9a0aac5f18f6f86e77b5b0e3ad325d05c82160a73f999f1
|
|
| MD5 |
82aaaac43016fdfe71417e3d37600da0
|
|
| BLAKE2b-256 |
7db26ea4f635aae8282df53ff87f237e21a06050cab851658660e42cd851903c
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
demystify_events-0.3.0.tar.gz -
Subject digest:
58c13ccad25ee278b9a0aac5f18f6f86e77b5b0e3ad325d05c82160a73f999f1 - Sigstore transparency entry: 2188361806
- Sigstore integration time:
-
Permalink:
demystify-systems/ai-services-tools@8a03d52d29b940de704d971b9c437493879613a4 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/demystify-systems
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@8a03d52d29b940de704d971b9c437493879613a4 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file demystify_events-0.3.0-py3-none-any.whl.
File metadata
- Download URL: demystify_events-0.3.0-py3-none-any.whl
- Upload date:
- Size: 41.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
04b97a849f157b9543e8facafcc1cca361f6b2498b199aafc6af65c0fc0ddb75
|
|
| MD5 |
5ae623fd495ed089c10d5f69fef3dc44
|
|
| BLAKE2b-256 |
965b33e827a889a80212e8405a29a9e9440ff0e4b28f6bfaa65443e3f7a16001
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
demystify_events-0.3.0-py3-none-any.whl -
Subject digest:
04b97a849f157b9543e8facafcc1cca361f6b2498b199aafc6af65c0fc0ddb75 - Sigstore transparency entry: 2188361816
- Sigstore integration time:
-
Permalink:
demystify-systems/ai-services-tools@8a03d52d29b940de704d971b9c437493879613a4 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/demystify-systems
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@8a03d52d29b940de704d971b9c437493879613a4 -
Trigger Event:
workflow_dispatch
-
Statement type: