rulfo
Request and reply between processes for asyncio: every request has a deadline, gets zero, one or many replies, and ends with one of four outcomes.
Python guide · Operations · Model · API reference · Changelog
Overview
rulfo is a Python package on a C core. Two processes share one connection, and each side can
send requests and answer them. A request has a key, a body of bytes and a deadline. It gets zero,
one or many replies, in order, and then one outcome: completed, busy, expired or
unroutable.
Use it between two services, or between a service and its workers, when the caller must know what happened to each request: it ran, it did not run, or that is unknown.
Status: early. Only the request operation is built, and the API can change.
Install
pip install rulfo # or: uv add rulfo
Linux and macOS with CPython 3.12 or later, tested on 3.12 to 3.15. Free-threaded Python is not
supported. There are wheels for Linux x86_64 and aarch64, and for macOS 11 or later (Apple silicon
and Intel). Other machines build the package from source, with a C compiler and the Python headers
(python3-dev for a Debian system Python).
Quickstart
One process here plays both sides: a server with two handlers and a client that sends three requests over TCP.
import asyncio
import rulfo
async def greet(request: rulfo.Request) -> bytes:
return b"hello " + request.body # one reply, then the end
async def count(request: rulfo.Request) -> None:
for number in range(int(request.body)):
await request.reply(f"item {number}".encode()) # many replies, then the end
async def main() -> None:
# One Peer for each remote party. This server has one client.
server = rulfo.Peer(handlers={"greet": greet, "count": count})
async def accept(reader: asyncio.StreamReader, writer: asyncio.StreamWriter) -> None:
await server.serve(rulfo.StreamTransport(reader, writer))
listener = await asyncio.start_server(accept, "127.0.0.1", 0)
port = listener.sockets[0].getsockname()[1]
client = rulfo.Peer()
reader, writer = await asyncio.open_connection("127.0.0.1", port)
connection = asyncio.create_task(client.serve(rulfo.StreamTransport(reader, writer)))
await client.wait_connected()
greeting = await client.request("greet", b"world", timeout=5)
print(greeting.outcome.value, greeting.one())
numbers = await client.request("count", b"3", timeout=5)
print(numbers.outcome.value, [reply.body for reply in numbers.replies])
missing = await client.request("unknown", timeout=5)
print(missing.outcome.value)
await client.aclose()
await server.aclose()
await connection
listener.close()
await listener.wait_closed()
asyncio.run(main())
Output:
completed b'hello world'
completed [b'item 0', b'item 1', b'item 2']
unroutable
Outcomes
request returns one of four outcomes. timeout has no default: every request has a deadline.
| Outcome | What happened | Did the handler run |
|---|---|---|
completed |
The handler ran and every reply arrived. A reply can be an error reply. | Yes |
busy |
The other side refused the request. | No |
unroutable |
No handler for the key, or no connection. | No |
expired |
The deadline passed first. | Unknown |
A busy or unroutable request is safe to send as a new request. An expired one may have
run. The rules are in Operations.
Why rulfo
HTTP: a call that times out, or whose connection drops, does not say whether the handler ran. A retry can run it twice unless you add your own request ids. Many replies need a stream, and resuming a stream that dropped is your code.
ZeroMQ: it gives you sockets and patterns. Its guide builds reliable request and reply as patterns in your own program: retries, and detecting a request that arrives twice.
rulfo has these rules built in, for request and reply only:
- The requester sends an open request again after a reconnect, with the same id. The replier runs one id at most once while its process lives.
- The end of a request has the number of replies.
completedmeans that all of them arrived. - A request that the replier refuses ends
busy. It did not run.
Use something else when you need publish and subscribe, work queues, a broker, discovery, a schema, or a language other than Python. rulfo has none of them.
Key features
- Four outcomes:
completed,busy,expired,unroutable. Two of them say it did not run. - A deadline on every request, also when the clocks of the two processes differ.
- Zero, one or many replies, in order.
- A request stays open across a reconnect. Replies lost in the reconnect are sent again, up to a memory limit.
- Limits with a stated result: a replier at
max_runningrefuses withbusy. - Many clients:
rulfo.Serverkeeps onePeerfor each name, and your program accepts the connections. - A request that a second process can take over:
request_copysends an id and a deadline that you stored. - Any ordered byte stream: TCP and unix sockets with
rulfo.StreamTransport, and a memory transport for tests. Two WebSocket adapters to copy are in the Python guide. rulfo.PeerState: the same logic without I/O and without a clock, for another event loop.- The rules are checked with a musil model. A test replays 12000 random runs of that model on the library.
Limits
- Only
requestis built. The newest value of a key and a check that the other side is gone are planned, and a work queue waits for a program that needs it: see Operations. - A
Peerserves one remote party over one connection.rulfo.Serverkeeps one for each name. - rulfo does not encrypt or authenticate. Use a transport that does.
- The body is bytes. rulfo has no serialization and no schema.
- A replier that restarts forgets the ids it ran. A request that is still open runs again, and
the handler sees
request.repeatas true. requestkeeps all replies in memory until the outcome.- Cancelling the task that awaits
requestdoes not stop the handler on the other side. - The model covers small cases only. Model lists what it proves and what it does not.
Links
- Documentation: https://cardona-oss.gitlab.io/rulfo/
- Wire format: the bytes, version 1
- Repository: https://gitlab.com/cardona-oss/rulfo
- PyPI: https://pypi.org/project/rulfo/
- Changelog: CHANGELOG.md
Contributing
The build needs a C compiler, and the C tests need cmake. The toolchain, the checks and the release process are in CONTRIBUTING.md.
License
MIT © Jorge Cardona. See LICENSE.
Metadata
Release files for rulfo 0.1.11
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 |
|---|---|---|---|---|
| rulfo-0.1.11.tar.gz | 71.8 kB | Without provenance | Details for rulfo-0.1.11.tar.gz |
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| rulfo-0.1.11-cp312-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl | CPython 3.12 | abi3 | Linux glibc 2.17+ x86-64 | Details for rulfo-0.1.11-cp312-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl |
| rulfo-0.1.11-cp312-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl | CPython 3.12 | abi3 | Linux glibc 2.17+ ARM64 | Details for rulfo-0.1.11-cp312-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl |
| rulfo-0.1.11-cp312-abi3-macosx_11_0_universal2.whl | CPython 3.12 | abi3 | macOS 11.0+ universal2 (ARM64, x86-64) | Details for rulfo-0.1.11-cp312-abi3-macosx_11_0_universal2.whl |
Total release size: 223.0 kB
Release files / rulfo-0.1.11.tar.gz
| Download URL | rulfo-0.1.11.tar.gz |
|---|---|
| Size | 71.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
067a03cfa6a74e6bdac889c0c27588d8d25bcad225cebe3e58d3477ecd4d5cc0
|
|
BLAKE2b-256 checksum How to use checksums |
35301bf3e0d1f1f093fc2a06df714db34dde92a74a0ad012bd58ce85c042207e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"12","id":"bookworm","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / rulfo-0.1.11-cp312-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
| Download URL | rulfo-0.1.11-cp312-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl |
|---|---|
| Size | 45.1 kB |
| Tags | CPython 3.12 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
75a0217374de77c385bb3c988450ee4c52692d65db704cc331e3f9330c4a1377
|
|
BLAKE2b-256 checksum How to use checksums |
2a65372e495d69e5146e17155095bd9b3bb5284bf558b1c10e3477ae6e45640f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"12","id":"bookworm","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / rulfo-0.1.11-cp312-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
| Download URL | rulfo-0.1.11-cp312-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl |
|---|---|
| Size | 44.6 kB |
| Tags | CPython 3.12 Linux glibc 2.17+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
887c787295f545a3cff065d5f08248aa3a5303cb729f61444433c80013973285
|
|
BLAKE2b-256 checksum How to use checksums |
fffd06d32036ec074f133fe06357be88ecb68d0d87ed054ca94bf232c2b4d0fa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"12","id":"bookworm","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / rulfo-0.1.11-cp312-abi3-macosx_11_0_universal2.whl
| Download URL | rulfo-0.1.11-cp312-abi3-macosx_11_0_universal2.whl |
|---|---|
| Size | 61.5 kB |
| Tags | CPython 3.12 abi3 macOS 11.0+ universal2 (ARM64, x86-64) |
|
SHA-256 checksum How to use checksums |
d463037b613c37fa2a9cff5633e167192486cc52eb5338269c4b7a07d10018e8
|
|
BLAKE2b-256 checksum How to use checksums |
0888e4c4b7f38b8596311dc367dc56ce2c56df7f014cd359b2b6438a4feb07be
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"12","id":"bookworm","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for rulfo 0.1.11
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.