snodra-messaging-sql
The PostgreSQL and MySQL 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 database, on the shared SQL layout version 1 that every Snodra library reads and writes.
Install
pip install snodra-messaging-sql
The distribution needs Python 3.12 or later and depends on snodra-messaging, asyncpg (PostgreSQL) and
asyncmy (MySQL). The core library never imports a SQL client; this add-on is where they live.
Use
import asyncio
import snodra
from snodra_sql import SqlConfig, SqlStore
async def main() -> None:
store = SqlStore(SqlConfig.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())
SqlConfig.from_env() reads SNODRA_STORE_SQL_URL (required), SNODRA_STORE_SQL_DRIVER,
SNODRA_STORE_SQL_NOTIFY and SNODRA_STORE_SQL_PURGE_INTERVAL_MS. The URL names the database:
postgres:// or postgresql:// for PostgreSQL, mysql:// for MySQL. The driver is read from the scheme when
the variable is empty.
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, 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 a transaction on its own connection binds it with store.transaction(conn=conn):
the store writes on that connection and never commits or rolls back the service's transaction.
async with pool.acquire() as conn:
async with conn.transaction():
async with store.transaction(conn=conn):
await store.outbox.append(entry)
await conn.execute("INSERT INTO orders (id) VALUES ($1)", order.id)
The store's own transactions (claims, the purge) run at READ COMMITTED. An outbox claim takes
SELECT ... FOR UPDATE SKIP LOCKED in (created_at, seq) order, so two relays on one outbox never hold the
same entry.
The layout
The schema files are the published version 1 files, byte for byte, embedded in the package
(src/snodra_sql/schema/{postgresql,mysql}/V1__snodra.sql) and checked against their published SHA-256
values. init_schema() applies version 1 unless the database has it or later, under the database lock every
Snodra library uses, so instances starting together apply it once. check_schema() only checks it, for a
service that runs its own migrations. The add-on also reads snodra_schema and refuses a database below
version 1. Schema versions are additive: code that knows version 1 reads a database at version 1 or later.
PostgreSQL 13 or later; MySQL 8.0.17 or later on InnoDB with a strict sql_mode (MariaDB is not supported).
The store needs a connection pool of at least two connections: a write that commits on its own inside the
service's transaction takes a second one.
Lifecycle
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. A failing schema step fails start(), naming
the store; an error from background() is logged and the app keeps running.
use_clock(clock)sets the application's clock (epoch milliseconds), which stamps every time the store sets itself: an entry's sending, a claim's lease, a purge bound.init_schema()prepares the schema;check_schema()fails unless it is there. They are public for a store constructed afterapp.start(), or used outside anApp.background()runs the retention purge everypurge_intervalseconds until it is cancelled. A negative interval turns it off and it waits for cancellation.open()opens the pool on demand;close()closes the pool and the PostgreSQL listener.
On PostgreSQL an append's transaction sends pg_notify('snodra_outbox', '') and outbox.on_append(wake)
listens on a connection of its own, so a relay claims as soon as an append commits; a rollback notifies
nobody. MySQL has no such notification and the relay polls.
Where the public specification leaves a choice, SPEC-GAPS.md records what this library does. The driver behaviour the add-on relies on is recorded in DRIVER-SPIKE.md.
Test
The tests start PostgreSQL and MySQL through Testcontainers (pinned by digest) and run the message-store conformance kit against both. Docker is required:
uv run pytest -q packages/snodra-messaging-sql/tests
Links
Metadata
Release files for snodra-messaging-sql 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_sql-0.5.0.tar.gz | 37.2 kB | With provenance | Details for snodra_messaging_sql-0.5.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| snodra_messaging_sql-0.5.0-py3-none-any.whl | Python 3 | none | any | Details for snodra_messaging_sql-0.5.0-py3-none-any.whl |
Total release size: 67.8 kB
Release files / snodra_messaging_sql-0.5.0.tar.gz
| Download URL | snodra_messaging_sql-0.5.0.tar.gz |
|---|---|
| Size | 37.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4432c6fb0a67e4dcc6d3787d07855193dca65f37aad03869ad850dafb0823285
|
|
BLAKE2b-256 checksum How to use checksums |
6aaad2ee9fc51716e7076b083ebd960e75853aa86d21f496506d329542e79f34
|
| 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_sql-0.5.0-py3-none-any.whl
| Download URL | snodra_messaging_sql-0.5.0-py3-none-any.whl |
|---|---|
| Size | 30.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1ca8cf5beeb5d4f2781ff742a5db8fb8903bb7793a1727ccf22d61978c310de2
|
|
BLAKE2b-256 checksum How to use checksums |
ef2c36053b9e255ab474aeea7e408125f3e6f93212bb0ab3ab8ab90d140e273f
|
| 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-sql 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_sql-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.