Skip to main content

pamoja-sync

Offline-first queues: in memory, and a crash-safe on-disk queue that survives power loss. One capability of pamoja, one memory-safe Rust core with bindings for TypeScript, Python, and C#.

read the guide documentation API reference

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

from pamoja.core import PamojaError
from pamoja.sync import Store


async def main() -> None:
    # A node with nowhere to send buffers its readings. This queue is held in memory, so it
    # lasts as long as the process; Store.file(dir) is the same queue on disk, which is what
    # a node uses to survive a reboot with its backlog intact.
    outbox = Store.memory()
    for reading in ("20.1", "20.4", "20.2"):
        await outbox.append(reading)
    print(f"queued    {await outbox.len()} readings with no link")

    # Peek reads the oldest record without taking it, so a send that fails part-way leaves
    # the queue exactly as it was.
    oldest = await outbox.peek_text()
    print(f"oldest    {oldest} and still {await outbox.len()} held")

    # The link returns and the queue drains oldest first, in the order the readings were
    # taken rather than the order they happen to come back off a buffer.
    drained = []
    while (record := await outbox.pop_text()) is not None:
        drained.append(record)
    print(f"drained   {', '.join(drained)}")

    # A bounded queue refuses the append that would overflow it. A full store is
    # backpressure the caller is told about, not a reading dropped behind its back.
    bounded = Store.memory(capacity=2)
    await bounded.append("20.1")
    await bounded.append("20.4")
    try:
        await bounded.append("20.2")
        print("a full queue took a third reading, which should never happen")
    except PamojaError as error:
        print(f"full      refused the third reading: {error}")

    return oldest, drained, await outbox.len(), await bounded.len()


oldest, drained, left, held = asyncio.run(main())

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

License

MIT

Release files for pamoja-sync 0.1.18

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

Source distribution (sdist)

Source distribution for pamoja-sync 0.1.18
File Size Uploaded
pamoja_sync-0.1.18.tar.gz 3.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pamoja-sync 0.1.18
File Interpreter ABI Platform
pamoja_sync-0.1.18-py3-none-any.whl Python 3 none any Details

Total release size: 7.4 kB

Release files / pamoja_sync-0.1.18.tar.gz

Download URL pamoja_sync-0.1.18.tar.gz
Size 3.4 kB
Tags Source
SHA-256 checksum
How to use checksums
24bbfd2515ccfb0875ea73d990af7d6ea5b42bedd858bda249311e9b254260ff
BLAKE2b-256 checksum
How to use checksums
8579ae81f262b3c0c26aefe9aeec194430a0c2ffd5306cd927cedf8a7136c65d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.15

Release files / pamoja_sync-0.1.18-py3-none-any.whl

Download URL pamoja_sync-0.1.18-py3-none-any.whl
Size 4.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ce34885d239a9faba96d7e4adc0f7bfdb360317da34ea039e89c5dd40075b0d6
BLAKE2b-256 checksum
How to use checksums
8de396fe7a386e8f6ab1a8ee280e9818c4f84e1e3170d55cc78a1e102cdadf1a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.15

Release history Release notifications | RSS feed

0.2.0

2 release files

This release

0.1.18 This release

2 release files

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