Polyglot RPC protocol layer (pre-1.0; API may break in minor versions).
Project description
clamator-protocol
Pure JSON-RPC 2.0 protocol primitives plus Pydantic-derived envelope types for clamator. No I/O, ever — anything that touches a network, filesystem, or process belongs in a transport adapter.
Install
pip install clamator-protocol
When you reach for this
- Defining a
Contract(in tests, in custom tooling). - Building a custom transport adapter that needs the wire-envelope models, the
TransportandDispatcherinterfaces, or the reserved JSON-RPC error codes.
If you only consume generated clients and servers, you don't import this package directly — your transport package (clamator-over-memory, clamator-over-redis) re-exports the few symbols you need.
Defining a contract
The Python counterpart of a Zod contract is a Contract with MethodEntry rows that bind Pydantic models to handler attribute names:
arith = Contract(
service="arith",
methods={
"add": MethodEntry(params_model=AddP, result_model=AddR, handler_attr="add"),
"ping": MethodEntry(params_model=PingP, result_model=None, handler_attr="ping"),
},
)
(Verbatim from py/packages/over-memory/tests/test_loopback.py:21-27.)
When clamator-protocol is consumed alongside generated wrappers from @clamator/codegen, the Contract and MethodEntry values are produced by codegen — the snippet above is what direct authors of test contracts or custom tooling write.
Key exports
Contract,MethodEntry— declare a service's methods and notifications with Pydantic models for params and results.RpcError— the error type you raise from a handler to surface a structured JSON-RPC error to the caller.ClamatorProtocolError,ClamatorTransportError— distinguishable error classes for protocol-level vs. transport-level failures.Transport,Dispatcher— interfaces a custom transport adapter implements.
Codegen workflow
clamator's codegen tool is published to npm (@clamator/codegen) regardless of which language consumes the output. Python users run the TS-side tool against their Zod contract source and consume the emitted Python wrappers from their package. See @clamator/codegen for the CLI invocation.
Method or notification?
Both methods and notifications send a request envelope; only methods produce a response envelope. Pick by the caller's needs, not the handler's.
- Use a method when the caller needs to know whether the operation succeeded, get a value back, surface a structured
RpcError, or sequence subsequent calls on completion. Methods carry a request id and the caller waits for the matching response or a timeout. - Use a notification when the caller is doing fire-and-forget work where neither success/failure nor a return value matters in the moment — telemetry, cache-busting, status pings. Notifications have no request id and produce no response; the caller cannot tell whether the handler ran, succeeded, or threw.
If you would otherwise add a method that returns nothing solely to confirm delivery, prefer a method returning an empty Pydantic model over a notification — the response envelope is the confirmation. Pick a notification only when "did this run?" is genuinely not a question the caller will ever ask.
Errors
Raise RpcError from a handler to surface a structured JSON-RPC error to the caller. The constructor takes a code, a message, and an optional data payload:
from clamator_protocol import RpcError
RPC_FORBIDDEN = -32001 # application-defined; outside the reserved -32600..-32099 range
def test_rpc_error_construction():
err = RpcError(RPC_FORBIDDEN, "forbidden", {"reason": "no-token"})
assert err.code == RPC_FORBIDDEN
assert err.message == "forbidden"
assert err.data == {"reason": "no-token"}
(Verbatim from py/packages/protocol/tests/test_rpc_error.py:1-10.)
Reserved JSON-RPC error codes (-32600 to -32603 for protocol-level errors, -32000 to -32099 reserved for transport implementations) are owned by the protocol layer; pick application-specific codes outside that range.
Links
- Sibling (TypeScript):
@clamator/protocol - Codegen:
@clamator/codegen(run from TS side; consume the generated Python output) - Design spec:
docs/2026-05-07-clamator-design.md - Agent rules:
AGENTS.md
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file clamator_protocol-0.1.2.tar.gz.
File metadata
- Download URL: clamator_protocol-0.1.2.tar.gz
- Upload date:
- Size: 10.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
65255901722674301a03be369f2ea8e61cc55b268cf8b3c739cb8e68df343dd8
|
|
| MD5 |
90d0fa3ade8456a0abe7c8c676915f6c
|
|
| BLAKE2b-256 |
1d9ea8b76e5ca40671483a928e20f04cd49d88b459c23355fb29e12ee4780bef
|
File details
Details for the file clamator_protocol-0.1.2-py3-none-any.whl.
File metadata
- Download URL: clamator_protocol-0.1.2-py3-none-any.whl
- Upload date:
- Size: 13.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
271c4b55de901d3c5916152a21cfde7a46a8caf6738514de50d598782da194c5
|
|
| MD5 |
90a3596ec7e5da505da0b84a7b472956
|
|
| BLAKE2b-256 |
812afcf10d4bacc66874bc4196d66293248d682ba9f98a06d2807491561e626f
|