rulfo 0.1.7__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.
Files changed (38) hide show
  1. rulfo-0.1.7/.gitignore +46 -0
  2. rulfo-0.1.7/CHANGELOG.md +30 -0
  3. rulfo-0.1.7/LICENSE +21 -0
  4. rulfo-0.1.7/PKG-INFO +131 -0
  5. rulfo-0.1.7/README.md +99 -0
  6. rulfo-0.1.7/core/CMakeLists.txt +42 -0
  7. rulfo-0.1.7/core/fuzz/fuzz_frame.c +77 -0
  8. rulfo-0.1.7/core/fuzz/fuzz_peer.c +372 -0
  9. rulfo-0.1.7/core/include/rulfo.h +321 -0
  10. rulfo-0.1.7/core/src/frame.c +276 -0
  11. rulfo-0.1.7/core/src/peer.c +638 -0
  12. rulfo-0.1.7/core/tests/check.h +15 -0
  13. rulfo-0.1.7/core/tests/test_frame.c +408 -0
  14. rulfo-0.1.7/core/tests/test_peer.c +549 -0
  15. rulfo-0.1.7/core/tests/test_replier.c +479 -0
  16. rulfo-0.1.7/core/tests/wire.h +82 -0
  17. rulfo-0.1.7/hatch_build.py +108 -0
  18. rulfo-0.1.7/models/request_reply.py +610 -0
  19. rulfo-0.1.7/pyproject.toml +135 -0
  20. rulfo-0.1.7/scripts/core-fuzz +13 -0
  21. rulfo-0.1.7/scripts/core-test +7 -0
  22. rulfo-0.1.7/src/rulfo/__init__.py +54 -0
  23. rulfo-0.1.7/src/rulfo/_core.pyi +6 -0
  24. rulfo-0.1.7/src/rulfo/_peer.py +491 -0
  25. rulfo-0.1.7/src/rulfo/_state.py +468 -0
  26. rulfo-0.1.7/src/rulfo/_transport.py +50 -0
  27. rulfo-0.1.7/src/rulfo/_types.py +179 -0
  28. rulfo-0.1.7/src/rulfo/py.typed +0 -0
  29. rulfo-0.1.7/src/rulfo/testing.py +37 -0
  30. rulfo-0.1.7/tests/links.py +61 -0
  31. rulfo-0.1.7/tests/test_conformance.py +297 -0
  32. rulfo-0.1.7/tests/test_core_module.py +26 -0
  33. rulfo-0.1.7/tests/test_import.py +5 -0
  34. rulfo-0.1.7/tests/test_peer_asyncio.py +685 -0
  35. rulfo-0.1.7/tests/test_peer_state.py +296 -0
  36. rulfo-0.1.7/tests/test_peer_state_walk.py +171 -0
  37. rulfo-0.1.7/tests/test_readme.py +29 -0
  38. rulfo-0.1.7/tests/test_request_reply_model.py +279 -0
rulfo-0.1.7/.gitignore ADDED
@@ -0,0 +1,46 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *.egg-info/
5
+ .eggs/
6
+
7
+ # Build artifacts
8
+ /dist/
9
+ /build/
10
+ /site/
11
+ /public/
12
+
13
+ # uv / venv
14
+ .venv/
15
+ uv.lock.bak
16
+
17
+ # Tool caches
18
+ .pytest_cache/
19
+ .ruff_cache/
20
+ .pyright/
21
+ .mypy_cache/
22
+ .moon/cache/
23
+
24
+ # Editor
25
+ .vscode/
26
+ .idea/
27
+ *.swp
28
+
29
+ # Local session logs
30
+ logs/
31
+
32
+ # Personal, machine-specific agent overrides (AGENTS.md is tracked)
33
+ AGENTS.local.md
34
+ CLAUDE.local.md
35
+
36
+ # Claude Code: per-machine local settings + worktrees are local; .claude/settings.json IS tracked.
37
+ .claude/settings.local.json
38
+ .claude/worktrees/
39
+
40
+ # Local agent wiring: names cabildo-issues-mcp, which is not a dependency of this
41
+ # package. docs/issues/ IS tracked — the register is plain markdown anyone can read.
42
+ .mcp.json
43
+
44
+ # Rust extension build output (maturin develop)
45
+ /rust/target/
46
+ src/*/*.so
@@ -0,0 +1,30 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project are documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [0.1.7] - 2026-11-27
11
+
12
+ First release on PyPI.
13
+
14
+ ### Added
15
+
16
+ - Wire format version 1 and the `request` operation, in `docs/`.
17
+ - Outcome `busy` for a refused request; `replied` is now `completed`; 16 capability bits.
18
+ - Deadlines are times on the requester's clock; a new CLOCK frame lets a replier convert them, so
19
+ a copy that waits in a buffer cannot run twice.
20
+ - A replier can send its replies again when a request comes again, so replies lost in a reconnect
21
+ no longer force `expired`.
22
+ - C frame codec for wire format version 1, with a libFuzzer target, in `core/`; the header
23
+ can be read and written without the key and the body.
24
+ - Model of request and replies with N repliers, a deadline and faults, in `models/`.
25
+ - `rf_peer` in C: handshake, requests, ordered replies, one outcome, resend after a reconnect,
26
+ a store of ids, busy refusal and sending replies again. A test replays model runs on it.
27
+ - Python package: `Peer` on asyncio with handlers, outcomes and deadlines, `PeerState` without
28
+ I/O, TCP and unix socket transport, and a memory transport for tests.
29
+ - A wheel for CPython 3.12 and later on Linux x86_64.
30
+ - A requester can stop waiting for a request (`rf_abandon`, a cancelled `request`).
rulfo-0.1.7/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Jorge Cardona
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.
rulfo-0.1.7/PKG-INFO ADDED
@@ -0,0 +1,131 @@
1
+ Metadata-Version: 2.5
2
+ Name: rulfo
3
+ Version: 0.1.7
4
+ Summary: Messaging between processes where a request gets zero, one or many replies and always an end. Status: early
5
+ Project-URL: Homepage, https://gitlab.com/cardona-oss/rulfo
6
+ Project-URL: Repository, https://gitlab.com/cardona-oss/rulfo
7
+ Project-URL: Documentation, https://cardona-oss.gitlab.io/rulfo/
8
+ Project-URL: Changelog, https://gitlab.com/cardona-oss/rulfo/-/blob/main/CHANGELOG.md
9
+ Project-URL: Issues, https://gitlab.com/cardona-oss/rulfo/-/issues
10
+ Author-email: Jorge Cardona <jorgeecardona@gmail.com>
11
+ License-Expression: MIT
12
+ License-File: LICENSE
13
+ Keywords: ipc,messaging,request-reply
14
+ Classifier: Development Status :: 2 - Pre-Alpha
15
+ Classifier: Framework :: AsyncIO
16
+ Classifier: Intended Audience :: Developers
17
+ Classifier: Operating System :: POSIX :: Linux
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Programming Language :: Python :: 3.14
22
+ Classifier: Topic :: Software Development :: Libraries
23
+ Classifier: Typing :: Typed
24
+ Requires-Python: >=3.12
25
+ Requires-Dist: cffi>=2.0
26
+ Provides-Extra: docs
27
+ Requires-Dist: mkdocs-llmstxt>=0.5; extra == 'docs'
28
+ Requires-Dist: mkdocs-material>=9.5; extra == 'docs'
29
+ Requires-Dist: mkdocs>=1.6; extra == 'docs'
30
+ Requires-Dist: mkdocstrings[python]>=0.27; extra == 'docs'
31
+ Description-Content-Type: text/markdown
32
+
33
+ # rulfo
34
+
35
+ Messaging between processes where a request gets zero, one or many replies and always an end.
36
+ A Python package on a C core, for asyncio.
37
+
38
+ Status: early. The API can change.
39
+
40
+ ## Install
41
+
42
+ ```bash
43
+ uv add rulfo
44
+ ```
45
+
46
+ Linux with CPython 3.12 or later. Free-threaded Python is not supported. The wheel is for x86_64.
47
+ Other machines build the package from source, with a C compiler and the Python headers
48
+ (`python3-dev` for a Debian system Python).
49
+
50
+ ## Quickstart
51
+
52
+ ```python
53
+ import asyncio
54
+
55
+ import rulfo
56
+
57
+
58
+ async def greet(request: rulfo.Request) -> bytes:
59
+ return b"hello " + request.body # one reply, then the end
60
+
61
+
62
+ async def count(request: rulfo.Request) -> None:
63
+ for number in range(int(request.body)):
64
+ await request.reply(f"item {number}".encode()) # many replies, then the end
65
+
66
+
67
+ async def main() -> None:
68
+ # One Peer for each remote party. This server has one client.
69
+ server = rulfo.Peer(handlers={"greet": greet, "count": count})
70
+
71
+ async def accept(reader: asyncio.StreamReader, writer: asyncio.StreamWriter) -> None:
72
+ await server.serve(rulfo.StreamTransport(reader, writer))
73
+
74
+ listener = await asyncio.start_server(accept, "127.0.0.1", 0)
75
+ port = listener.sockets[0].getsockname()[1]
76
+
77
+ client = rulfo.Peer()
78
+ reader, writer = await asyncio.open_connection("127.0.0.1", port)
79
+ connection = asyncio.create_task(client.serve(rulfo.StreamTransport(reader, writer)))
80
+ await client.wait_connected()
81
+
82
+ greeting = await client.request("greet", b"world", timeout=5)
83
+ print(greeting.outcome.value, greeting.one())
84
+
85
+ numbers = await client.request("count", b"3", timeout=5)
86
+ print(numbers.outcome.value, [reply.body for reply in numbers.replies])
87
+
88
+ missing = await client.request("unknown", timeout=5)
89
+ print(missing.outcome.value)
90
+
91
+ await client.aclose()
92
+ await server.aclose()
93
+ await connection
94
+ listener.close()
95
+ await listener.wait_closed()
96
+
97
+
98
+ asyncio.run(main())
99
+ ```
100
+
101
+ Output:
102
+
103
+ ```text
104
+ completed b'hello world'
105
+ completed [b'item 0', b'item 1', b'item 2']
106
+ unroutable
107
+ ```
108
+
109
+ ## Features
110
+
111
+ - Four outcomes: `completed`, `busy`, `expired`, `unroutable`. Two of them say it did not run.
112
+ - A deadline on every request, also when the two clocks differ.
113
+ - Zero, one or many replies, in order.
114
+ - A request survives a reconnect and runs once while the other process lives. Replies lost in
115
+ the reconnect are sent again, up to a memory limit.
116
+ - Any byte stream: TCP and unix sockets included, WebSocket adapters in the docs.
117
+ - A model checks the rules, and the library replays runs of that model.
118
+
119
+ Not designed yet: latest value per key, work with acknowledgement, presence.
120
+
121
+ ## Links
122
+
123
+ - [Python guide](https://cardona-oss.gitlab.io/rulfo/python/)
124
+ - [Operations](https://cardona-oss.gitlab.io/rulfo/operations/): the rules
125
+ - [Wire format](https://cardona-oss.gitlab.io/rulfo/wire-format/)
126
+ - [Model](https://cardona-oss.gitlab.io/rulfo/model/): what is proved and what is not
127
+ - [Contributing](https://gitlab.com/cardona-oss/rulfo/-/blob/main/CONTRIBUTING.md)
128
+
129
+ ## License
130
+
131
+ MIT. See [LICENSE](https://gitlab.com/cardona-oss/rulfo/-/blob/main/LICENSE).
rulfo-0.1.7/README.md ADDED
@@ -0,0 +1,99 @@
1
+ # rulfo
2
+
3
+ Messaging between processes where a request gets zero, one or many replies and always an end.
4
+ A Python package on a C core, for asyncio.
5
+
6
+ Status: early. The API can change.
7
+
8
+ ## Install
9
+
10
+ ```bash
11
+ uv add rulfo
12
+ ```
13
+
14
+ Linux with CPython 3.12 or later. Free-threaded Python is not supported. The wheel is for x86_64.
15
+ Other machines build the package from source, with a C compiler and the Python headers
16
+ (`python3-dev` for a Debian system Python).
17
+
18
+ ## Quickstart
19
+
20
+ ```python
21
+ import asyncio
22
+
23
+ import rulfo
24
+
25
+
26
+ async def greet(request: rulfo.Request) -> bytes:
27
+ return b"hello " + request.body # one reply, then the end
28
+
29
+
30
+ async def count(request: rulfo.Request) -> None:
31
+ for number in range(int(request.body)):
32
+ await request.reply(f"item {number}".encode()) # many replies, then the end
33
+
34
+
35
+ async def main() -> None:
36
+ # One Peer for each remote party. This server has one client.
37
+ server = rulfo.Peer(handlers={"greet": greet, "count": count})
38
+
39
+ async def accept(reader: asyncio.StreamReader, writer: asyncio.StreamWriter) -> None:
40
+ await server.serve(rulfo.StreamTransport(reader, writer))
41
+
42
+ listener = await asyncio.start_server(accept, "127.0.0.1", 0)
43
+ port = listener.sockets[0].getsockname()[1]
44
+
45
+ client = rulfo.Peer()
46
+ reader, writer = await asyncio.open_connection("127.0.0.1", port)
47
+ connection = asyncio.create_task(client.serve(rulfo.StreamTransport(reader, writer)))
48
+ await client.wait_connected()
49
+
50
+ greeting = await client.request("greet", b"world", timeout=5)
51
+ print(greeting.outcome.value, greeting.one())
52
+
53
+ numbers = await client.request("count", b"3", timeout=5)
54
+ print(numbers.outcome.value, [reply.body for reply in numbers.replies])
55
+
56
+ missing = await client.request("unknown", timeout=5)
57
+ print(missing.outcome.value)
58
+
59
+ await client.aclose()
60
+ await server.aclose()
61
+ await connection
62
+ listener.close()
63
+ await listener.wait_closed()
64
+
65
+
66
+ asyncio.run(main())
67
+ ```
68
+
69
+ Output:
70
+
71
+ ```text
72
+ completed b'hello world'
73
+ completed [b'item 0', b'item 1', b'item 2']
74
+ unroutable
75
+ ```
76
+
77
+ ## Features
78
+
79
+ - Four outcomes: `completed`, `busy`, `expired`, `unroutable`. Two of them say it did not run.
80
+ - A deadline on every request, also when the two clocks differ.
81
+ - Zero, one or many replies, in order.
82
+ - A request survives a reconnect and runs once while the other process lives. Replies lost in
83
+ the reconnect are sent again, up to a memory limit.
84
+ - Any byte stream: TCP and unix sockets included, WebSocket adapters in the docs.
85
+ - A model checks the rules, and the library replays runs of that model.
86
+
87
+ Not designed yet: latest value per key, work with acknowledgement, presence.
88
+
89
+ ## Links
90
+
91
+ - [Python guide](https://cardona-oss.gitlab.io/rulfo/python/)
92
+ - [Operations](https://cardona-oss.gitlab.io/rulfo/operations/): the rules
93
+ - [Wire format](https://cardona-oss.gitlab.io/rulfo/wire-format/)
94
+ - [Model](https://cardona-oss.gitlab.io/rulfo/model/): what is proved and what is not
95
+ - [Contributing](https://gitlab.com/cardona-oss/rulfo/-/blob/main/CONTRIBUTING.md)
96
+
97
+ ## License
98
+
99
+ MIT. See [LICENSE](https://gitlab.com/cardona-oss/rulfo/-/blob/main/LICENSE).
@@ -0,0 +1,42 @@
1
+ cmake_minimum_required(VERSION 3.20)
2
+ project(rulfo LANGUAGES C)
3
+
4
+ option(RULFO_SANITIZE "Build with AddressSanitizer and UndefinedBehaviorSanitizer" OFF)
5
+ option(RULFO_FUZZ "Build the libFuzzer target (clang only)" OFF)
6
+
7
+ set(CMAKE_C_STANDARD 11)
8
+ set(CMAKE_C_STANDARD_REQUIRED ON)
9
+ set(CMAKE_C_EXTENSIONS OFF)
10
+
11
+ add_compile_options(-Wall -Wextra -Wpedantic -Wconversion -Wshadow -Wstrict-prototypes -Werror)
12
+
13
+ if(RULFO_SANITIZE OR RULFO_FUZZ)
14
+ set(sanitizers -fsanitize=address,undefined -fno-sanitize-recover=all -fno-omit-frame-pointer -g)
15
+ add_compile_options(${sanitizers})
16
+ add_link_options(${sanitizers})
17
+ endif()
18
+
19
+ add_library(rulfo STATIC src/frame.c src/peer.c)
20
+ target_include_directories(rulfo PUBLIC include)
21
+
22
+ enable_testing()
23
+ add_executable(test_frame tests/test_frame.c)
24
+ target_link_libraries(test_frame PRIVATE rulfo)
25
+ add_test(NAME frame COMMAND test_frame)
26
+ add_executable(test_peer tests/test_peer.c)
27
+ target_link_libraries(test_peer PRIVATE rulfo)
28
+ add_test(NAME peer COMMAND test_peer)
29
+ add_executable(test_replier tests/test_replier.c)
30
+ target_link_libraries(test_replier PRIVATE rulfo)
31
+ add_test(NAME replier COMMAND test_replier)
32
+
33
+ if(RULFO_FUZZ)
34
+ # Coverage counters in the library, the fuzzer's main in the target.
35
+ target_compile_options(rulfo PRIVATE -fsanitize=fuzzer-no-link)
36
+ add_executable(fuzz_frame fuzz/fuzz_frame.c)
37
+ target_link_libraries(fuzz_frame PRIVATE rulfo)
38
+ target_link_options(fuzz_frame PRIVATE -fsanitize=fuzzer)
39
+ add_executable(fuzz_peer fuzz/fuzz_peer.c)
40
+ target_link_libraries(fuzz_peer PRIVATE rulfo)
41
+ target_link_options(fuzz_peer PRIVATE -fsanitize=fuzzer)
42
+ endif()
@@ -0,0 +1,77 @@
1
+ /* libFuzzer target: any input is refused, asks for more, or decodes to a frame that encodes
2
+ * back to the same bytes. */
3
+ #include "rulfo.h"
4
+
5
+ #include <stdlib.h>
6
+ #include <string.h>
7
+
8
+ #define REQUIRE(condition) \
9
+ do { \
10
+ if (!(condition)) { \
11
+ abort(); \
12
+ } \
13
+ } while (0)
14
+
15
+ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
16
+
17
+ static void preface(const uint8_t *data, size_t size) {
18
+ uint16_t capabilities = 0;
19
+ if (rf_preface_decode(data, size, &capabilities) == RF_OK) {
20
+ uint8_t out[RF_PREFACE_SIZE];
21
+ rf_preface_encode(capabilities, out);
22
+ REQUIRE(memcmp(out, data, sizeof out) == 0);
23
+ }
24
+ }
25
+
26
+ /* The header functions refuse what the frame decoder refuses, apart from the key bytes. */
27
+ static void header_agrees(const uint8_t *data, size_t size, uint32_t max_length,
28
+ rf_status frame_status) {
29
+ rf_header header;
30
+ rf_status status = rf_header_decode(data, size, max_length, &header);
31
+ if (status != RF_OK) {
32
+ REQUIRE(frame_status == status);
33
+ return;
34
+ }
35
+ REQUIRE(frame_status == RF_OK || frame_status == RF_NEED_MORE || frame_status == RF_ERR_KEY);
36
+ uint8_t out[RF_HEADER_SIZE];
37
+ REQUIRE(rf_header_encode(&header, max_length, out) == RF_OK);
38
+ REQUIRE(memcmp(out, data, sizeof out) == 0);
39
+ }
40
+
41
+ static void frames(const uint8_t *data, size_t size, uint32_t max_length) {
42
+ size_t at = 0;
43
+ for (;;) {
44
+ rf_frame frame;
45
+ size_t used = 0;
46
+ rf_status status = rf_frame_decode(data + at, size - at, max_length, &frame, &used);
47
+ header_agrees(data + at, size - at, max_length, status);
48
+ if (status == RF_NEED_MORE) {
49
+ REQUIRE(used > size - at);
50
+ REQUIRE(used <= (size_t)RF_HEADER_SIZE + max_length);
51
+ return;
52
+ }
53
+ if (status != RF_OK) {
54
+ return;
55
+ }
56
+ REQUIRE(used >= RF_HEADER_SIZE && used <= size - at);
57
+ REQUIRE(frame.key.ptr == data + at + RF_HEADER_SIZE);
58
+ REQUIRE(frame.body.ptr == frame.key.ptr + frame.key.len);
59
+ REQUIRE(RF_HEADER_SIZE + frame.key.len + frame.body.len == used);
60
+
61
+ uint8_t *out = malloc(used);
62
+ REQUIRE(out != NULL);
63
+ size_t written = 0;
64
+ REQUIRE(rf_frame_encode(&frame, max_length, out, used, &written) == RF_OK);
65
+ REQUIRE(written == used);
66
+ REQUIRE(memcmp(out, data + at, used) == 0);
67
+ free(out);
68
+ at += used;
69
+ }
70
+ }
71
+
72
+ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
73
+ preface(data, size);
74
+ frames(data, size, 64); /* a small limit, so the limit is reached often */
75
+ frames(data, size, RF_DEFAULT_MAX_LENGTH);
76
+ return 0;
77
+ }