pamoja-sync
Offline-first queues in memory or on disk, bounded or not, the on-disk one surviving power loss, and the drain that forwards them in order when a link returns. One capability of pamoja, one memory-safe Rust core with bindings for TypeScript, Python, and C#.
Install
pip install pamoja-sync
from pamoja import sync
This pulls in pamoja-native, the compiled engine. pip install pamoja is the whole framework in one package.
Example
The script the test suite runs, spliced here as it ran.
From bindings/python/guides/sync.py:
import asyncio
import tempfile
from pamoja.core import PamojaError, Transport
from pamoja.loopback import LoopbackBroker
from pamoja.sync import Store
TOPIC = "apiary/hive-3/weight"
async def main(folder: str) -> None:
# The scale logs its weight to a queue on its SD card, bounded so a long outage
# cannot fill the card. The directory is the queue, so the scale can lose power at
# any moment and lose nothing it logged.
outbox = Store.file(folder, 3)
for weight in ("41.2", "41.5", "40.9"):
await outbox.append(weight)
logged = await outbox.len()
print(f"hive logged {logged} weights with no link, the most its store holds")
# A full store refuses the next weight rather than dropping one it already holds.
try:
await outbox.append("41.1")
except PamojaError as error:
print(f"hive was refused a 4th: {error}")
# The scale reboots. Its queue is the directory, so it comes back whole and in
# order.
outbox = Store.file(folder, 3)
held = await outbox.len()
oldest = await outbox.peek_text()
print(f"hive restarted and still holds {held}, oldest first: {oldest}")
# The cellular uplink carries one weight, then drops. A weight leaves the queue only
# once a link has taken it, so what the uplink never took stays, in order.
cellular = LoopbackBroker()
uplink = Transport.degraded(cellular.rung(), up=1, down=10)
await uplink.connect()
forwarded = 0
try:
await outbox.drain_to(uplink, TOPIC)
except PamojaError as error:
forwarded = held - await outbox.len()
print(f"uplink forwarded {forwarded}, then failed: {error}")
left = await outbox.len()
next_weight = await outbox.peek_text()
print(f"hive still holds {left}, oldest first: {next_weight}")
# The beekeeper's gateway comes within reach, and the scale drains the rest onto
# it.
visit = LoopbackBroker()
gateway = visit.link()
await gateway.connect()
await gateway.subscribe(TOPIC)
to_gateway = visit.rung()
await to_gateway.connect()
await outbox.drain_to(to_gateway, TOPIC)
took = [(await gateway.recv()).text for _ in range(left)]
print(f"gateway took {', '.join(took)} when the beekeeper came by")
empty = await outbox.len()
print(f"hive holds {empty} once the backlog is through")
return (logged, held, forwarded, left, empty), oldest, next_weight, took
with tempfile.TemporaryDirectory(prefix="pamoja-hive-") as folder:
counts, oldest, next_weight, took = asyncio.run(main(folder))
The same capability in every language
| Language | Package | Reference |
|---|---|---|
| Rust | pamoja-sync |
reference, docs.rs, install |
| TypeScript | @pamoja/sync |
reference, install |
| Python | pamoja-sync |
reference, install |
| C# | Pamoja.Sync |
reference, install |
Documentation
pamoja.syncreference, every class and function in this module.- The Store and forward guide, with the same example in Rust, TypeScript, and C#.
- Every capability, and the install page.
License
MIT
Metadata
Release files for pamoja-sync 0.2.1
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 |
|---|---|---|---|---|
| pamoja_sync-0.2.1.tar.gz | 3.7 kB | Without provenance | Details for pamoja_sync-0.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pamoja_sync-0.2.1-py3-none-any.whl | Python 3 | none | any | Details for pamoja_sync-0.2.1-py3-none-any.whl |
Total release size: 8.1 kB
Release files / pamoja_sync-0.2.1.tar.gz
| Download URL | pamoja_sync-0.2.1.tar.gz |
|---|---|
| Size | 3.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cab4bbe2ec87331d9a632fe929687fac8458c789e9333905f36f065e4c25d027
|
|
BLAKE2b-256 checksum How to use checksums |
7183deaa127e6ff5e0b0ace882e63e6fbf3f532698363b908004bf76cf50491b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.18
|
Release files / pamoja_sync-0.2.1-py3-none-any.whl
| Download URL | pamoja_sync-0.2.1-py3-none-any.whl |
|---|---|
| Size | 4.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7371e915bf91692e5032ffa705b97e9c7d7959c5b0b0f20140c0b42837b4c110
|
|
BLAKE2b-256 checksum How to use checksums |
d9ff2b94fb854be51a9994e00881f8d26cdd32618296a4cd5d5704b14b89a5b8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.18
|
Security for pamoja-sync 0.2.1
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.