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 every message-store port: the outbox, the processed-event markers, the dead letters, the processor control state, the external-call records and the saga records. The level-3 and level-4 store checks pass on a replica set.

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.13.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.13.0
File Size Uploaded Provenance Actions
snodra_messaging_mongo-0.13.0.tar.gz 35.6 kB With provenance Details for snodra_messaging_mongo-0.13.0.tar.gz

Built distribution (wheel)

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

Total release size: 61.4 kB

Release files / snodra_messaging_mongo-0.13.0.tar.gz

Download URL snodra_messaging_mongo-0.13.0.tar.gz
Size 35.6 kB
Tags Source
SHA-256 checksum
How to use checksums
37a61ef92902ce171443dbe936ad09d0d32d5ce3e321e7d2513694268722a4fb
BLAKE2b-256 checksum
How to use checksums
efd40367780ba56e4067a5e1ae21a55bc696550cf44fd188f569f5f41a4f625b
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 Dec 1, 2026.

Transparency log

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

Download URL snodra_messaging_mongo-0.13.0-py3-none-any.whl
Size 25.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e69f8ee89177ce3e93cda306d1d2d8d6e758070736401e3dfab29939f80751d6
BLAKE2b-256 checksum
How to use checksums
93b682e3d0bba89bed83a0b705e6d31138ace048effa39ec1a87cf52932c4f3e
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 Dec 1, 2026.

Transparency log

Security for snodra-messaging-mongo 0.13.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.13.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 Dec 1, 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