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 level-2 ports: the outbox and the processed-event markers. The dead-letter,
processor-control, 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
Links
Metadata
Release files for snodra-messaging-mongo 0.5.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| snodra_messaging_mongo-0.5.0.tar.gz | 27.0 kB | With provenance | Details for snodra_messaging_mongo-0.5.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| snodra_messaging_mongo-0.5.0-py3-none-any.whl | Python 3 | none | any | Details for snodra_messaging_mongo-0.5.0-py3-none-any.whl |
Total release size: 46.7 kB
Release files / snodra_messaging_mongo-0.5.0.tar.gz
| Download URL | snodra_messaging_mongo-0.5.0.tar.gz |
|---|---|
| Size | 27.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7ad8c64887773780d06c4c3cc0575267836c9f012a38fa1f5c6ef62d3cc1523f
|
|
BLAKE2b-256 checksum How to use checksums |
2b20c831124907b43a052948411c6f67955efee3f6fa283bc044b7bebf876560
|
| 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 26, 2026.
Transparency logRelease files / snodra_messaging_mongo-0.5.0-py3-none-any.whl
| Download URL | snodra_messaging_mongo-0.5.0-py3-none-any.whl |
|---|---|
| Size | 19.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8ed92c5914245848674ede97e10f32ad4494676eacb2cf9dd031c4cd147e24b6
|
|
BLAKE2b-256 checksum How to use checksums |
e63dd15df50c29210af961c8787b89c8c1830186362b2bfd35be49120dd867ac
|
| 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 26, 2026.
Transparency logSecurity for snodra-messaging-mongo 0.5.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.
Attestation for snodra_messaging_mongo-0.5.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 26, 2026.
Transparency logA 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.