pamoja-sync 0.1.18__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Anthony Wiedman
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: pamoja-sync
|
|
3
|
+
Version: 0.1.18
|
|
4
|
+
Summary: Offline-first queues: in memory, and a crash-safe on-disk queue that survives power loss.
|
|
5
|
+
Project-URL: Repository, https://github.com/molexxxx/pamoja
|
|
6
|
+
Project-URL: Documentation, https://pamoja.molex.cloud/docs/guides/sync.html
|
|
7
|
+
Author: molexxxx
|
|
8
|
+
License: MIT
|
|
9
|
+
License-File: LICENSE-MIT
|
|
10
|
+
Keywords: iot,pamoja,robotics,sync
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Typing :: Typed
|
|
15
|
+
Requires-Python: >=3.10
|
|
16
|
+
Requires-Dist: pamoja-native==0.1.18
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
|
|
19
|
+
# pamoja-sync
|
|
20
|
+
|
|
21
|
+
Offline-first queues: in memory, and a crash-safe on-disk queue that survives power loss. One capability of [pamoja](https://github.com/molexxxx/pamoja), one memory-safe Rust core with bindings for TypeScript, Python, and C#.
|
|
22
|
+
|
|
23
|
+
[](https://pamoja.molex.cloud/docs/guides/sync.html)
|
|
24
|
+
[](https://pamoja.molex.cloud/docs/)
|
|
25
|
+
[](https://pamoja.molex.cloud/docs/reference/python/pamoja/sync.html)
|
|
26
|
+
|
|
27
|
+
## Install
|
|
28
|
+
|
|
29
|
+
```sh
|
|
30
|
+
pip install pamoja-sync
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
```python
|
|
34
|
+
from pamoja import sync
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
This pulls in `pamoja-native`, the compiled engine. `pip install pamoja` is the whole framework in one package.
|
|
38
|
+
|
|
39
|
+
## Example
|
|
40
|
+
|
|
41
|
+
The script the test suite runs, spliced here as it ran.
|
|
42
|
+
|
|
43
|
+
From [`bindings/python/guides/sync.py`](https://github.com/molexxxx/pamoja/blob/main/bindings/python/guides/sync.py):
|
|
44
|
+
|
|
45
|
+
```python
|
|
46
|
+
import asyncio
|
|
47
|
+
|
|
48
|
+
from pamoja.core import PamojaError
|
|
49
|
+
from pamoja.sync import Store
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
async def main() -> None:
|
|
53
|
+
# A node with nowhere to send buffers its readings. This queue is held in memory, so it
|
|
54
|
+
# lasts as long as the process; Store.file(dir) is the same queue on disk, which is what
|
|
55
|
+
# a node uses to survive a reboot with its backlog intact.
|
|
56
|
+
outbox = Store.memory()
|
|
57
|
+
for reading in ("20.1", "20.4", "20.2"):
|
|
58
|
+
await outbox.append(reading)
|
|
59
|
+
print(f"queued {await outbox.len()} readings with no link")
|
|
60
|
+
|
|
61
|
+
# Peek reads the oldest record without taking it, so a send that fails part-way leaves
|
|
62
|
+
# the queue exactly as it was.
|
|
63
|
+
oldest = await outbox.peek_text()
|
|
64
|
+
print(f"oldest {oldest} and still {await outbox.len()} held")
|
|
65
|
+
|
|
66
|
+
# The link returns and the queue drains oldest first, in the order the readings were
|
|
67
|
+
# taken rather than the order they happen to come back off a buffer.
|
|
68
|
+
drained = []
|
|
69
|
+
while (record := await outbox.pop_text()) is not None:
|
|
70
|
+
drained.append(record)
|
|
71
|
+
print(f"drained {', '.join(drained)}")
|
|
72
|
+
|
|
73
|
+
# A bounded queue refuses the append that would overflow it. A full store is
|
|
74
|
+
# backpressure the caller is told about, not a reading dropped behind its back.
|
|
75
|
+
bounded = Store.memory(capacity=2)
|
|
76
|
+
await bounded.append("20.1")
|
|
77
|
+
await bounded.append("20.4")
|
|
78
|
+
try:
|
|
79
|
+
await bounded.append("20.2")
|
|
80
|
+
print("a full queue took a third reading, which should never happen")
|
|
81
|
+
except PamojaError as error:
|
|
82
|
+
print(f"full refused the third reading: {error}")
|
|
83
|
+
|
|
84
|
+
return oldest, drained, await outbox.len(), await bounded.len()
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
oldest, drained, left, held = asyncio.run(main())
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## The same capability in every language
|
|
91
|
+
|
|
92
|
+
| Language | Package | Reference |
|
|
93
|
+
| --- | --- | --- |
|
|
94
|
+
| Rust | [`pamoja-sync`](https://crates.io/crates/pamoja-sync) | [reference](https://pamoja.molex.cloud/docs/reference/rust/pamoja_sync/index.html), [docs.rs](https://docs.rs/pamoja-sync), [install](https://pamoja.molex.cloud/docs/reference/rust.html#rust-sync) |
|
|
95
|
+
| TypeScript | [`@pamoja/sync`](https://www.npmjs.com/package/@pamoja/sync) | [reference](https://pamoja.molex.cloud/docs/reference/node/modules/_pamoja_sync.html), [install](https://pamoja.molex.cloud/docs/reference/node.html#node-sync) |
|
|
96
|
+
| Python | [`pamoja-sync`](https://pypi.org/project/pamoja-sync/) | [reference](https://pamoja.molex.cloud/docs/reference/python/pamoja/sync.html), [install](https://pamoja.molex.cloud/docs/reference/python.html#python-sync) |
|
|
97
|
+
| C# | [`Pamoja.Sync`](https://www.nuget.org/packages/Pamoja.Sync) | [reference](https://pamoja.molex.cloud/docs/reference/dotnet/api/Pamoja.Sync.html), [install](https://pamoja.molex.cloud/docs/reference/dotnet.html#dotnet-sync) |
|
|
98
|
+
|
|
99
|
+
## Documentation
|
|
100
|
+
|
|
101
|
+
- [`pamoja.sync` reference](https://pamoja.molex.cloud/docs/reference/python/pamoja/sync.html), every class and function in this module.
|
|
102
|
+
- [The Store and forward guide](https://pamoja.molex.cloud/docs/guides/sync.html), with the same example in Rust, TypeScript, and C#.
|
|
103
|
+
- [Every capability](https://pamoja.molex.cloud/docs/), and the [install page](https://pamoja.molex.cloud/docs/install.html).
|
|
104
|
+
|
|
105
|
+
## License
|
|
106
|
+
|
|
107
|
+
MIT
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# pamoja-sync
|
|
2
|
+
|
|
3
|
+
Offline-first queues: in memory, and a crash-safe on-disk queue that survives power loss. One capability of [pamoja](https://github.com/molexxxx/pamoja), one memory-safe Rust core with bindings for TypeScript, Python, and C#.
|
|
4
|
+
|
|
5
|
+
[](https://pamoja.molex.cloud/docs/guides/sync.html)
|
|
6
|
+
[](https://pamoja.molex.cloud/docs/)
|
|
7
|
+
[](https://pamoja.molex.cloud/docs/reference/python/pamoja/sync.html)
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
pip install pamoja-sync
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
```python
|
|
16
|
+
from pamoja import sync
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
This pulls in `pamoja-native`, the compiled engine. `pip install pamoja` is the whole framework in one package.
|
|
20
|
+
|
|
21
|
+
## Example
|
|
22
|
+
|
|
23
|
+
The script the test suite runs, spliced here as it ran.
|
|
24
|
+
|
|
25
|
+
From [`bindings/python/guides/sync.py`](https://github.com/molexxxx/pamoja/blob/main/bindings/python/guides/sync.py):
|
|
26
|
+
|
|
27
|
+
```python
|
|
28
|
+
import asyncio
|
|
29
|
+
|
|
30
|
+
from pamoja.core import PamojaError
|
|
31
|
+
from pamoja.sync import Store
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
async def main() -> None:
|
|
35
|
+
# A node with nowhere to send buffers its readings. This queue is held in memory, so it
|
|
36
|
+
# lasts as long as the process; Store.file(dir) is the same queue on disk, which is what
|
|
37
|
+
# a node uses to survive a reboot with its backlog intact.
|
|
38
|
+
outbox = Store.memory()
|
|
39
|
+
for reading in ("20.1", "20.4", "20.2"):
|
|
40
|
+
await outbox.append(reading)
|
|
41
|
+
print(f"queued {await outbox.len()} readings with no link")
|
|
42
|
+
|
|
43
|
+
# Peek reads the oldest record without taking it, so a send that fails part-way leaves
|
|
44
|
+
# the queue exactly as it was.
|
|
45
|
+
oldest = await outbox.peek_text()
|
|
46
|
+
print(f"oldest {oldest} and still {await outbox.len()} held")
|
|
47
|
+
|
|
48
|
+
# The link returns and the queue drains oldest first, in the order the readings were
|
|
49
|
+
# taken rather than the order they happen to come back off a buffer.
|
|
50
|
+
drained = []
|
|
51
|
+
while (record := await outbox.pop_text()) is not None:
|
|
52
|
+
drained.append(record)
|
|
53
|
+
print(f"drained {', '.join(drained)}")
|
|
54
|
+
|
|
55
|
+
# A bounded queue refuses the append that would overflow it. A full store is
|
|
56
|
+
# backpressure the caller is told about, not a reading dropped behind its back.
|
|
57
|
+
bounded = Store.memory(capacity=2)
|
|
58
|
+
await bounded.append("20.1")
|
|
59
|
+
await bounded.append("20.4")
|
|
60
|
+
try:
|
|
61
|
+
await bounded.append("20.2")
|
|
62
|
+
print("a full queue took a third reading, which should never happen")
|
|
63
|
+
except PamojaError as error:
|
|
64
|
+
print(f"full refused the third reading: {error}")
|
|
65
|
+
|
|
66
|
+
return oldest, drained, await outbox.len(), await bounded.len()
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
oldest, drained, left, held = asyncio.run(main())
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## The same capability in every language
|
|
73
|
+
|
|
74
|
+
| Language | Package | Reference |
|
|
75
|
+
| --- | --- | --- |
|
|
76
|
+
| Rust | [`pamoja-sync`](https://crates.io/crates/pamoja-sync) | [reference](https://pamoja.molex.cloud/docs/reference/rust/pamoja_sync/index.html), [docs.rs](https://docs.rs/pamoja-sync), [install](https://pamoja.molex.cloud/docs/reference/rust.html#rust-sync) |
|
|
77
|
+
| TypeScript | [`@pamoja/sync`](https://www.npmjs.com/package/@pamoja/sync) | [reference](https://pamoja.molex.cloud/docs/reference/node/modules/_pamoja_sync.html), [install](https://pamoja.molex.cloud/docs/reference/node.html#node-sync) |
|
|
78
|
+
| Python | [`pamoja-sync`](https://pypi.org/project/pamoja-sync/) | [reference](https://pamoja.molex.cloud/docs/reference/python/pamoja/sync.html), [install](https://pamoja.molex.cloud/docs/reference/python.html#python-sync) |
|
|
79
|
+
| C# | [`Pamoja.Sync`](https://www.nuget.org/packages/Pamoja.Sync) | [reference](https://pamoja.molex.cloud/docs/reference/dotnet/api/Pamoja.Sync.html), [install](https://pamoja.molex.cloud/docs/reference/dotnet.html#dotnet-sync) |
|
|
80
|
+
|
|
81
|
+
## Documentation
|
|
82
|
+
|
|
83
|
+
- [`pamoja.sync` reference](https://pamoja.molex.cloud/docs/reference/python/pamoja/sync.html), every class and function in this module.
|
|
84
|
+
- [The Store and forward guide](https://pamoja.molex.cloud/docs/guides/sync.html), with the same example in Rust, TypeScript, and C#.
|
|
85
|
+
- [Every capability](https://pamoja.molex.cloud/docs/), and the [install page](https://pamoja.molex.cloud/docs/install.html).
|
|
86
|
+
|
|
87
|
+
## License
|
|
88
|
+
|
|
89
|
+
MIT
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"""Idiomatic store-and-forward facade.
|
|
2
|
+
|
|
3
|
+
The queue a node writes into while it has nowhere to send. An in-memory buffer
|
|
4
|
+
suits a test or a process that will not outlive it; a file-backed one survives a
|
|
5
|
+
reboot, which is what a node somewhere without reliable power actually needs.
|
|
6
|
+
|
|
7
|
+
A full store refuses the next append rather than dropping anything, so a record
|
|
8
|
+
is never lost without the caller being told.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
from pamoja._native import Store
|
|
14
|
+
|
|
15
|
+
__all__ = ["Store"]
|
|
File without changes
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.27"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "pamoja-sync"
|
|
7
|
+
version = "0.1.18"
|
|
8
|
+
description = "Offline-first queues: in memory, and a crash-safe on-disk queue that survives power loss."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = { text = "MIT" }
|
|
11
|
+
license-files = ["LICENSE-MIT"]
|
|
12
|
+
requires-python = ">=3.10"
|
|
13
|
+
authors = [{ name = "molexxxx" }]
|
|
14
|
+
keywords = ["pamoja", "iot", "robotics", "sync"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Programming Language :: Python :: 3",
|
|
17
|
+
"License :: OSI Approved :: MIT License",
|
|
18
|
+
"Operating System :: OS Independent",
|
|
19
|
+
"Typing :: Typed",
|
|
20
|
+
]
|
|
21
|
+
dependencies = [
|
|
22
|
+
"pamoja-native==0.1.18",
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
[project.urls]
|
|
26
|
+
Repository = "https://github.com/molexxxx/pamoja"
|
|
27
|
+
Documentation = "https://pamoja.molex.cloud/docs/guides/sync.html"
|
|
28
|
+
|
|
29
|
+
[tool.hatch.build.targets.wheel]
|
|
30
|
+
packages = ["pamoja"]
|