Skip to main content

snodra-messaging-mongo

The MongoDB message store for the Snodra messaging suite: the outbox, the processed-event markers and the rest of the message-store ports in the service's own MongoDB database, in the collections and with the document fields the published MongoDB layout fixes, so documents written by any Snodra library stay readable without a migration.

Install

pip install snodra-messaging-mongo

The distribution needs Python 3.12 or later and depends on snodra-messaging and PyMongo's async client. The core library never imports a MongoDB client; this add-on is where it lives.

Use

import asyncio

import snodra
from snodra_mongo import MongoConfig, MongoStore


async def main() -> None:
    store = MongoStore(MongoConfig.from_env())
    try:
        settings = snodra.Settings.from_env(service="orders-service")
        # The event store reads what the relay publishes; the message store holds the outbox and markers.
        app = snodra.App(settings, store=store, event_store=...)
        await app.run()
    finally:
        await store.close()


asyncio.run(main())

MongoConfig.from_env() reads SNODRA_STORE_MONGO_URI and SNODRA_STORE_MONGO_DATABASE; the URI is required unless the store is given a client. A service that owns its PyMongo client passes it to MongoStore(config, client=client) with an empty url: the store does not close a client it does not own.

The store's transactions are MongoDB multi-document transactions on a client session, so the database must be a replica set (a single-node one is enough).

The store implements the outbox, the processed-event markers, the dead letters and the processor control state; the level-3 store checks pass on a replica set. The external-call and saga ports are part of the interface frozen at level 2 and report snodra.MessageStoreUnsupported for now; the official add-ons implement every port by level 4.

The transaction is the service's

async with store.transaction(): begins a transaction on a client session, binds it to the current context and commits on a clean exit or rolls back on an exception. An outbox append and a processed marker recorded inside it join it. A service that already runs its own MongoDB transaction binds that session with store.transaction(session=session), and a handler that writes its own documents in the handled event's transaction asks for the session with store.session(tx):

async with store.transaction() as tx:
    await store.outbox.append(entry)
    session = store.session(tx)
    await store.database["orders"].insert_one(order, session=session)

A claim, a marker's existence check, the marks, the purges and an append outside a transaction are writes of their own that commit on their own, never in the caller's transaction. A duplicate key, a write conflict and an error MongoDB labels a transient transaction error are snodra.Conflict (a retry of the whole attempt resolves them); every other driver error is snodra.MessageStoreFailed.

The layout

init_schema() creates every index and TTL index of the layout, idempotently: creating them creates the collections a transaction writes to before the first transaction does. Neither an index that exists nor its options change, so every instance sharing a database must be given the same retentions. check_schema() only checks the collections and indexes, for a service that prepares its schema itself; a TTL that differs from the store's settings counts as a schema failure. TTLs are stored in whole seconds, floored as the published retentions are.

App.start() drives the store's lifecycle when it is the app's store: it hands the store the application's clock, calls init_schema() (or check_schema() when Settings.store_init_schema is false) and starts background() in a snodra:store-background task until shutdown. The methods are public for a store constructed after app.start(), or used outside an App. background() runs nothing: MongoDB's TTL monitor removes expired documents on the server. use_clock(clock) sets the application's clock (epoch milliseconds), which stamps every time the store sets itself: an entry's sending and failure, a claim's lease.

Where the public specification leaves a choice, SPEC-GAPS.md records what this library does.

Test

The tests start a single-node MongoDB replica set through Testcontainers (pinned by digest) and run the message-store conformance kit against it. Docker is required:

uv run pytest -q packages/snodra-messaging-mongo/tests

Metadata

Release files for snodra-messaging-mongo 0.7.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for snodra-messaging-mongo 0.7.0
File Size Uploaded Provenance Actions
snodra_messaging_mongo-0.7.0.tar.gz 31.4 kB With provenance Details for snodra_messaging_mongo-0.7.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for snodra-messaging-mongo 0.7.0
File Interpreter ABI Platform Actions
snodra_messaging_mongo-0.7.0-py3-none-any.whl Python 3 none any Details for snodra_messaging_mongo-0.7.0-py3-none-any.whl

Total release size: 53.9 kB

Release files / snodra_messaging_mongo-0.7.0.tar.gz

Download URL snodra_messaging_mongo-0.7.0.tar.gz
Size 31.4 kB
Tags Source
SHA-256 checksum
How to use checksums
fa301105136d7d38f0bdf46ea04b966360a201d3217d59a05781a09d5c8fdd07
BLAKE2b-256 checksum
How to use checksums
dc7d0fda7c3bade8a4fcdb077cc4ff44fd860d46eb958fbe4799f09afef55a98
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 27, 2026.

Transparency log

Release files / snodra_messaging_mongo-0.7.0-py3-none-any.whl

Download URL snodra_messaging_mongo-0.7.0-py3-none-any.whl
Size 22.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c59cf4e651517fb7872e2c658bbdbdc99af684cc0fcfa1be7f1eba685232f41e
BLAKE2b-256 checksum
How to use checksums
a9a84b84853581a0599572c0d54520f1c680e2b8f9716368077d66fe79dc58bd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 27, 2026.

Transparency log

Security for snodra-messaging-mongo 0.7.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for snodra_messaging_mongo-0.7.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 27, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page