munarium-client 1.1.0__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 (75) hide show
  1. munarium_client-1.1.0/.gitignore +7 -0
  2. munarium_client-1.1.0/LICENSE +202 -0
  3. munarium_client-1.1.0/NOTICE +15 -0
  4. munarium_client-1.1.0/PKG-INFO +184 -0
  5. munarium_client-1.1.0/README.md +159 -0
  6. munarium_client-1.1.0/conformance/compose.server-111.yaml +38 -0
  7. munarium_client-1.1.0/conformance/conftest.py +96 -0
  8. munarium_client-1.1.0/conformance/ollama_fixture.py +85 -0
  9. munarium_client-1.1.0/conformance/test_platform.py +787 -0
  10. munarium_client-1.1.0/conformance/test_scenarios.py +216 -0
  11. munarium_client-1.1.0/conformance/test_server_111.py +225 -0
  12. munarium_client-1.1.0/conformance/test_server_api_conformance.py +156 -0
  13. munarium_client-1.1.0/conformance/test_smokes.py +156 -0
  14. munarium_client-1.1.0/pyproject.toml +72 -0
  15. munarium_client-1.1.0/scripts/gen_protos.py +82 -0
  16. munarium_client-1.1.0/src/munarium_client/__init__.py +390 -0
  17. munarium_client-1.1.0/src/munarium_client/_chunks.py +70 -0
  18. munarium_client-1.1.0/src/munarium_client/_errors.py +300 -0
  19. munarium_client-1.1.0/src/munarium_client/_grpc_common.py +642 -0
  20. munarium_client-1.1.0/src/munarium_client/_options.py +53 -0
  21. munarium_client-1.1.0/src/munarium_client/_proto/__init__.py +0 -0
  22. munarium_client-1.1.0/src/munarium_client/_proto/mmp/__init__.py +0 -0
  23. munarium_client-1.1.0/src/munarium_client/_proto/mmp/v1/__init__.py +0 -0
  24. munarium_client-1.1.0/src/munarium_client/_proto/mmp/v1/admin_pb2.py +65 -0
  25. munarium_client-1.1.0/src/munarium_client/_proto/mmp/v1/admin_pb2.pyi +142 -0
  26. munarium_client-1.1.0/src/munarium_client/_proto/mmp/v1/admin_pb2_grpc.py +314 -0
  27. munarium_client-1.1.0/src/munarium_client/_proto/mmp/v1/command_pb2.py +70 -0
  28. munarium_client-1.1.0/src/munarium_client/_proto/mmp/v1/command_pb2.pyi +175 -0
  29. munarium_client-1.1.0/src/munarium_client/_proto/mmp/v1/command_pb2_grpc.py +398 -0
  30. munarium_client-1.1.0/src/munarium_client/_proto/mmp/v1/common_pb2.py +53 -0
  31. munarium_client-1.1.0/src/munarium_client/_proto/mmp/v1/common_pb2.pyi +103 -0
  32. munarium_client-1.1.0/src/munarium_client/_proto/mmp/v1/common_pb2_grpc.py +24 -0
  33. munarium_client-1.1.0/src/munarium_client/_proto/mmp/v1/ingest_pb2.py +54 -0
  34. munarium_client-1.1.0/src/munarium_client/_proto/mmp/v1/ingest_pb2.pyi +101 -0
  35. munarium_client-1.1.0/src/munarium_client/_proto/mmp/v1/ingest_pb2_grpc.py +184 -0
  36. munarium_client-1.1.0/src/munarium_client/_proto/mmp/v1/ledger_pb2.py +60 -0
  37. munarium_client-1.1.0/src/munarium_client/_proto/mmp/v1/ledger_pb2.pyi +201 -0
  38. munarium_client-1.1.0/src/munarium_client/_proto/mmp/v1/ledger_pb2_grpc.py +24 -0
  39. munarium_client-1.1.0/src/munarium_client/_proto/mmp/v1/provider_pb2.py +54 -0
  40. munarium_client-1.1.0/src/munarium_client/_proto/mmp/v1/provider_pb2.pyi +114 -0
  41. munarium_client-1.1.0/src/munarium_client/_proto/mmp/v1/provider_pb2_grpc.py +226 -0
  42. munarium_client-1.1.0/src/munarium_client/_proto/mmp/v1/query_pb2.py +74 -0
  43. munarium_client-1.1.0/src/munarium_client/_proto/mmp/v1/query_pb2.pyi +147 -0
  44. munarium_client-1.1.0/src/munarium_client/_proto/mmp/v1/query_pb2_grpc.py +441 -0
  45. munarium_client-1.1.0/src/munarium_client/_proto/mmp/v1/retrieval_pb2.py +57 -0
  46. munarium_client-1.1.0/src/munarium_client/_proto/mmp/v1/retrieval_pb2.pyi +124 -0
  47. munarium_client-1.1.0/src/munarium_client/_proto/mmp/v1/retrieval_pb2_grpc.py +270 -0
  48. munarium_client-1.1.0/src/munarium_client/_proto/mmp/v1/runbook_pb2.py +87 -0
  49. munarium_client-1.1.0/src/munarium_client/_proto/mmp/v1/runbook_pb2.pyi +266 -0
  50. munarium_client-1.1.0/src/munarium_client/_proto/mmp/v1/runbook_pb2_grpc.py +485 -0
  51. munarium_client-1.1.0/src/munarium_client/_proto/mmp/v1/server_api_pb2.py +50 -0
  52. munarium_client-1.1.0/src/munarium_client/_proto/mmp/v1/server_api_pb2.pyi +53 -0
  53. munarium_client-1.1.0/src/munarium_client/_proto/mmp/v1/server_api_pb2_grpc.py +5378 -0
  54. munarium_client-1.1.0/src/munarium_client/_proto/mmp/v1/session_pb2.py +67 -0
  55. munarium_client-1.1.0/src/munarium_client/_proto/mmp/v1/session_pb2.pyi +214 -0
  56. munarium_client-1.1.0/src/munarium_client/_proto/mmp/v1/session_pb2_grpc.py +227 -0
  57. munarium_client-1.1.0/src/munarium_client/_retry.py +24 -0
  58. munarium_client-1.1.0/src/munarium_client/_server_api.py +298 -0
  59. munarium_client-1.1.0/src/munarium_client/_specs.py +1100 -0
  60. munarium_client-1.1.0/src/munarium_client/_sse.py +228 -0
  61. munarium_client-1.1.0/src/munarium_client/grpc_transport.py +1245 -0
  62. munarium_client-1.1.0/src/munarium_client/models.py +1242 -0
  63. munarium_client-1.1.0/src/munarium_client/py.typed +0 -0
  64. munarium_client-1.1.0/src/munarium_client/rest.py +478 -0
  65. munarium_client-1.1.0/src/munarium_client/rest_planes.py +1350 -0
  66. munarium_client-1.1.0/src/munarium_client/server_api.py +3158 -0
  67. munarium_client-1.1.0/tests/test_c8_surface.py +135 -0
  68. munarium_client-1.1.0/tests/test_compatibility_record.py +61 -0
  69. munarium_client-1.1.0/tests/test_errors.py +134 -0
  70. munarium_client-1.1.0/tests/test_evidence_hierarchy.py +367 -0
  71. munarium_client-1.1.0/tests/test_max_tokens.py +291 -0
  72. munarium_client-1.1.0/tests/test_replay_safety.py +79 -0
  73. munarium_client-1.1.0/tests/test_review_batch.py +337 -0
  74. munarium_client-1.1.0/tests/test_server_api.py +86 -0
  75. munarium_client-1.1.0/tests/test_sse.py +220 -0
@@ -0,0 +1,7 @@
1
+ .venv/
2
+ __pycache__/
3
+ *.egg-info/
4
+ dist/
5
+ .mypy_cache/
6
+ .ruff_cache/
7
+ .pytest_cache/
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,15 @@
1
+ Munarium client libraries
2
+ Copyright (c) 2026 Ioka LLC
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use
5
+ these files except in compliance with the License. A copy of the License is in
6
+ the LICENSE file beside this notice.
7
+
8
+ "Munarium" and "Ioka" are trademarks of Ioka LLC. The License grants no right
9
+ to use them beyond what is needed to describe the origin of these files.
10
+
11
+ These libraries speak to Munarium Server, a separate work licensed under its
12
+ own terms; nothing here grants any right to it, to Munarium Matrix, or to any
13
+ support from Ioka LLC.
14
+
15
+ The MMP contract bundle under contract/ carries its own NOTICE.
@@ -0,0 +1,184 @@
1
+ Metadata-Version: 2.5
2
+ Name: munarium-client
3
+ Version: 1.1.0
4
+ Summary: Official Python client for munarium-server: one plane surface, two transports (REST + gRPC), sync and async, typed errors keyed on the problem-slug registry, and the head-conflict write loop built in.
5
+ Project-URL: Homepage, https://github.com/iokaio/munarium
6
+ Project-URL: Repository, https://github.com/iokaio/munarium
7
+ Project-URL: Changelog, https://github.com/iokaio/munarium/blob/main/clients/CHANGELOG.md
8
+ Author: Ioka
9
+ License-Expression: Apache-2.0
10
+ License-File: LICENSE
11
+ License-File: NOTICE
12
+ Requires-Python: >=3.11
13
+ Requires-Dist: googleapis-common-protos>=1.60
14
+ Requires-Dist: grpcio>=1.83
15
+ Requires-Dist: httpx>=0.27
16
+ Requires-Dist: protobuf>=7.35.1
17
+ Requires-Dist: pydantic>=2.5
18
+ Provides-Extra: dev
19
+ Requires-Dist: grpcio-tools==1.83.1; extra == 'dev'
20
+ Requires-Dist: mypy>=1.10; extra == 'dev'
21
+ Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
22
+ Requires-Dist: pytest>=8; extra == 'dev'
23
+ Requires-Dist: ruff>=0.5; extra == 'dev'
24
+ Description-Content-Type: text/markdown
25
+
26
+ # munarium-client (Python)
27
+
28
+ Targets **Munarium Server 1.2.1**. Client package **1.1.0** provides the complete `ServerApiClient` over REST and native gRPC, while the existing typed planes retain their Server 1.1 baseline. See the [Server 1.2 guide](../docs/guides/server-1.2.md) for vocabulary, collection queries, publication governance, answers and source references. Transport limitations below apply to the older typed planes.
29
+
30
+ Official Python client for munarium-server: the full ten-plane surface
31
+ (`commands`, `query`, `ingest`, `retrieval`, `runbooks`, `providers`,
32
+ `sessions`, `tokens`, `reports`, `authoring`), sync **and** async, both
33
+ transports, typed exceptions, the head-conflict write loop built in. See the
34
+ [clients front door](../README.md) for the invariants, the transport-gap
35
+ ledger, and guides.
36
+
37
+ Python ≥ 3.11 · fully typed (`py.typed`, mypy --strict clean).
38
+
39
+ ## Install
40
+
41
+ From the repository root (Python 3.11+):
42
+
43
+ ```console
44
+ python -m pip install ./clients/python
45
+ # For client development:
46
+ python -m pip install -e "./clients/python[dev]"
47
+ ```
48
+
49
+ The source version is 1.0.0; a PyPI release was not available at the
50
+ [publication check](../README.md#installation-and-publication).
51
+
52
+ ## Use
53
+
54
+ ```python
55
+ from munarium_client import (
56
+ AsyncMunariumClient, ClientOptions, HeadConflictError, MunariumClient,
57
+ )
58
+
59
+ # sync + REST
60
+ client = MunariumClient.rest(
61
+ ClientOptions("http://127.0.0.1:8080", token="devtoken", uid="user-1"))
62
+ # …or sync + gRPC / async + REST / async + gRPC
63
+ client = MunariumClient.grpc(ClientOptions("127.0.0.1:50051", token="devtoken", uid="user-1"))
64
+ aclient = AsyncMunariumClient.rest(
65
+ ClientOptions("http://127.0.0.1:8080", token="devtoken", uid="user-1"))
66
+
67
+ v = client.commands.create_version()
68
+
69
+ # Disputed is SUCCESS — the governance record, not an error.
70
+ outcome = client.commands.propose_claim(v, subject="hero", key="eyes", value="blue")
71
+ if outcome.is_disputed:
72
+ for f in outcome.findings:
73
+ print(f.rule_id, f.message)
74
+
75
+ # The write loop: expected_head + fresh idempotency key per attempt.
76
+ outcome = client.propose_claim_with_retry(
77
+ v, lambda head: {"subject": "hero", "key": "home", "value": "harbor"})
78
+
79
+ # One pin bounds all stores.
80
+ page = client.query.facts(v, as_of_seq=1)
81
+ ```
82
+
83
+ `uid` is the acting end-user id (audit attribution), required by the server's
84
+ default posture (`MUNARIUM_REQUIRE_UID=true`) — omit it and every call draws the
85
+ typed `uid-required` error.
86
+
87
+ The platform surface stays Pythonic: `sessions.turn_stream(...)` is a plain
88
+ `Iterator` (async: an async generator) of `TurnProgress` events whose **last
89
+ item is the `TurnResult`** — typed errors raise during iteration, and a
90
+ stream that ends without a terminal event raises `TransportError`. If you
91
+ may leave the ASYNC stream early, wrap it in `contextlib.aclosing(...)` so
92
+ the pooled connection is released deterministically instead of whenever the
93
+ garbage collector finalizes the abandoned generator:
94
+
95
+ ```python
96
+ from contextlib import aclosing
97
+ from munarium_client.models import TurnProgress
98
+
99
+ async with aclosing(aclient.sessions.turn_stream(sid, query="vacation policy")) as events:
100
+ async for event in events:
101
+ if isinstance(event, TurnProgress) and event.stage == "model":
102
+ break
103
+ ```
104
+
105
+ On gRPC `turn_stream` is REST-only: the sync plane raises `UnsupportedError`
106
+ when called, and `AsyncMunariumClient.grpc(...).sessions.turn_stream` is a real
107
+ async generator that raises it on the first iteration. When the 60 s SSE
108
+ idle watchdog fires, the `TransportError` says the turn may still be
109
+ executing server-side (the completion was paid) — read the transcript with
110
+ `sessions.get` before re-sending. Unary turns are deadline-exempt and never
111
+ auto-retried (they spend provider tokens a client abort cannot stop); bulk
112
+ upload sessions ride `ingest.bulk_open/bulk_chunk/bulk_complete`;
113
+ `tokens`/`reports`/`authoring` cover the management plane (mint with a
114
+ mgmt-role bearer).
115
+
116
+ `providers.max_tokens()` / `providers.replace_max_tokens(budgets)` read and
117
+ replace the tenant's per-call output-token budgets (`GET`/`POST
118
+ /v1/max-tokens`). `MaxTokensResponse` is the eight `MaxTokensBudgets` fields
119
+ flattened beside `source` (`tenant` | `environment`) and `updated_at`, and
120
+ it subclasses the budgets model, so a read result edited in place
121
+ round-trips into the replacement — only the eight budget fields go on the
122
+ wire. There is no partial update: a dict missing a field is refused before
123
+ it is sent, an out-of-range value is the server's `InvalidInputError`, the
124
+ replace needs the static **rw** role (`ForbiddenError` otherwise), and both
125
+ are REST-only (`UnsupportedError` on gRPC).
126
+
127
+ `sessions.turn`/`turn_stream` take an optional `research_profile=`: the
128
+ turn runs through a named evidence hierarchy and `TurnResult.hierarchy`
129
+ carries the decision — which layers ran, which refused, whether a
130
+ completeness claim was permissible at all. Omit it and nothing changes:
131
+ the request body grows no key and the response carries no `hierarchy`.
132
+ A streamed turn under a profile adds the `profile` / `layer_start` /
133
+ `layer_source` / `layer_complete` / `coverage` / `compose` stages after
134
+ the existing ones (`TurnProgress` declares only `stage`, so per-stage
135
+ fields ride as extras). On the operator side `reports.evidence(window=)`
136
+ shows which layer is quietly refusing — those turns still return 200, so
137
+ no error rate reveals them — and `reports.matrix()` reports Matrix's
138
+ reachability, keeping `configured=False` (never wired) distinct from
139
+ `circuit_open=True` (tripped).
140
+
141
+ Exceptions mirror the problem-slug registry (`HeadConflictError`,
142
+ `PolicyRejectionError` with findings + truncation markers, `RunLockedError`
143
+ — typed but NOT transient, pace it like a rate limit —
144
+ `RateLimitedError.retry_after` — populated only if the server sends a
145
+ `Retry-After` header, which it does not today). `UnsupportedError` marks the documented
146
+ gRPC gaps.
147
+
148
+ Command retry is deliberately narrow: on REST a command re-sends its SAME
149
+ idempotency key only after a connect-phase failure (`httpx.ConnectError` /
150
+ `ConnectTimeout` / `ProxyError` — the request never left) or the typed
151
+ `OverloadedError` (shed before executing); a gateway 502/504 is transient
152
+ for reads but never re-sent as a command, because it may still be executing
153
+ upstream. On gRPC commands re-send only on `OverloadedError` — never on a
154
+ transport failure. Two gRPC input rules beyond the proto3 zero sentinels:
155
+ `ingest()` mirrors REST `POST /v1/ingest` (a locally undecodable
156
+ `content_base64` raises `InvalidInputError`; a server-side per-item error on
157
+ that one file raises `UnexpectedError` with the text — the wire has no slug;
158
+ `ingest_batch` keeps per-item results), and an explicit `collections=[]` on
159
+ an ingest file or `runbook_refs=[]` on `tokens.mint` raises
160
+ `InvalidInputError` (proto3 cannot carry "explicitly empty"; pass `None` or
161
+ use REST). Both transports accept base64 with surrounding whitespace.
162
+
163
+ The async gRPC variant drives the thread-safe sync stubs via
164
+ `asyncio.to_thread` (documented implementation choice); async REST is native
165
+ httpx.
166
+
167
+ ## Regenerating the gRPC stubs
168
+
169
+ The generated stubs under `src/munarium_client/_proto/` are committed and
170
+ CI-drift-checked. After a proto change:
171
+
172
+ ```bash
173
+ python scripts/gen_protos.py
174
+ ```
175
+
176
+ ## Tests
177
+
178
+ ```bash
179
+ pytest tests # offline unit tests
180
+ MUNARIUM_REST_URL=http://127.0.0.1:18080 MUNARIUM_GRPC_URL=127.0.0.1:15051 \
181
+ MUNARIUM_TOKEN=devtoken MUNARIUM_MGMT_TOKEN=devmgmt \
182
+ pytest conformance # scenarios x {rest,grpc} x {sync,async} + smokes
183
+ # + the platform tests (skipped without the mgmt token)
184
+ ```
@@ -0,0 +1,159 @@
1
+ # munarium-client (Python)
2
+
3
+ Targets **Munarium Server 1.2.1**. Client package **1.1.0** provides the complete `ServerApiClient` over REST and native gRPC, while the existing typed planes retain their Server 1.1 baseline. See the [Server 1.2 guide](../docs/guides/server-1.2.md) for vocabulary, collection queries, publication governance, answers and source references. Transport limitations below apply to the older typed planes.
4
+
5
+ Official Python client for munarium-server: the full ten-plane surface
6
+ (`commands`, `query`, `ingest`, `retrieval`, `runbooks`, `providers`,
7
+ `sessions`, `tokens`, `reports`, `authoring`), sync **and** async, both
8
+ transports, typed exceptions, the head-conflict write loop built in. See the
9
+ [clients front door](../README.md) for the invariants, the transport-gap
10
+ ledger, and guides.
11
+
12
+ Python ≥ 3.11 · fully typed (`py.typed`, mypy --strict clean).
13
+
14
+ ## Install
15
+
16
+ From the repository root (Python 3.11+):
17
+
18
+ ```console
19
+ python -m pip install ./clients/python
20
+ # For client development:
21
+ python -m pip install -e "./clients/python[dev]"
22
+ ```
23
+
24
+ The source version is 1.0.0; a PyPI release was not available at the
25
+ [publication check](../README.md#installation-and-publication).
26
+
27
+ ## Use
28
+
29
+ ```python
30
+ from munarium_client import (
31
+ AsyncMunariumClient, ClientOptions, HeadConflictError, MunariumClient,
32
+ )
33
+
34
+ # sync + REST
35
+ client = MunariumClient.rest(
36
+ ClientOptions("http://127.0.0.1:8080", token="devtoken", uid="user-1"))
37
+ # …or sync + gRPC / async + REST / async + gRPC
38
+ client = MunariumClient.grpc(ClientOptions("127.0.0.1:50051", token="devtoken", uid="user-1"))
39
+ aclient = AsyncMunariumClient.rest(
40
+ ClientOptions("http://127.0.0.1:8080", token="devtoken", uid="user-1"))
41
+
42
+ v = client.commands.create_version()
43
+
44
+ # Disputed is SUCCESS — the governance record, not an error.
45
+ outcome = client.commands.propose_claim(v, subject="hero", key="eyes", value="blue")
46
+ if outcome.is_disputed:
47
+ for f in outcome.findings:
48
+ print(f.rule_id, f.message)
49
+
50
+ # The write loop: expected_head + fresh idempotency key per attempt.
51
+ outcome = client.propose_claim_with_retry(
52
+ v, lambda head: {"subject": "hero", "key": "home", "value": "harbor"})
53
+
54
+ # One pin bounds all stores.
55
+ page = client.query.facts(v, as_of_seq=1)
56
+ ```
57
+
58
+ `uid` is the acting end-user id (audit attribution), required by the server's
59
+ default posture (`MUNARIUM_REQUIRE_UID=true`) — omit it and every call draws the
60
+ typed `uid-required` error.
61
+
62
+ The platform surface stays Pythonic: `sessions.turn_stream(...)` is a plain
63
+ `Iterator` (async: an async generator) of `TurnProgress` events whose **last
64
+ item is the `TurnResult`** — typed errors raise during iteration, and a
65
+ stream that ends without a terminal event raises `TransportError`. If you
66
+ may leave the ASYNC stream early, wrap it in `contextlib.aclosing(...)` so
67
+ the pooled connection is released deterministically instead of whenever the
68
+ garbage collector finalizes the abandoned generator:
69
+
70
+ ```python
71
+ from contextlib import aclosing
72
+ from munarium_client.models import TurnProgress
73
+
74
+ async with aclosing(aclient.sessions.turn_stream(sid, query="vacation policy")) as events:
75
+ async for event in events:
76
+ if isinstance(event, TurnProgress) and event.stage == "model":
77
+ break
78
+ ```
79
+
80
+ On gRPC `turn_stream` is REST-only: the sync plane raises `UnsupportedError`
81
+ when called, and `AsyncMunariumClient.grpc(...).sessions.turn_stream` is a real
82
+ async generator that raises it on the first iteration. When the 60 s SSE
83
+ idle watchdog fires, the `TransportError` says the turn may still be
84
+ executing server-side (the completion was paid) — read the transcript with
85
+ `sessions.get` before re-sending. Unary turns are deadline-exempt and never
86
+ auto-retried (they spend provider tokens a client abort cannot stop); bulk
87
+ upload sessions ride `ingest.bulk_open/bulk_chunk/bulk_complete`;
88
+ `tokens`/`reports`/`authoring` cover the management plane (mint with a
89
+ mgmt-role bearer).
90
+
91
+ `providers.max_tokens()` / `providers.replace_max_tokens(budgets)` read and
92
+ replace the tenant's per-call output-token budgets (`GET`/`POST
93
+ /v1/max-tokens`). `MaxTokensResponse` is the eight `MaxTokensBudgets` fields
94
+ flattened beside `source` (`tenant` | `environment`) and `updated_at`, and
95
+ it subclasses the budgets model, so a read result edited in place
96
+ round-trips into the replacement — only the eight budget fields go on the
97
+ wire. There is no partial update: a dict missing a field is refused before
98
+ it is sent, an out-of-range value is the server's `InvalidInputError`, the
99
+ replace needs the static **rw** role (`ForbiddenError` otherwise), and both
100
+ are REST-only (`UnsupportedError` on gRPC).
101
+
102
+ `sessions.turn`/`turn_stream` take an optional `research_profile=`: the
103
+ turn runs through a named evidence hierarchy and `TurnResult.hierarchy`
104
+ carries the decision — which layers ran, which refused, whether a
105
+ completeness claim was permissible at all. Omit it and nothing changes:
106
+ the request body grows no key and the response carries no `hierarchy`.
107
+ A streamed turn under a profile adds the `profile` / `layer_start` /
108
+ `layer_source` / `layer_complete` / `coverage` / `compose` stages after
109
+ the existing ones (`TurnProgress` declares only `stage`, so per-stage
110
+ fields ride as extras). On the operator side `reports.evidence(window=)`
111
+ shows which layer is quietly refusing — those turns still return 200, so
112
+ no error rate reveals them — and `reports.matrix()` reports Matrix's
113
+ reachability, keeping `configured=False` (never wired) distinct from
114
+ `circuit_open=True` (tripped).
115
+
116
+ Exceptions mirror the problem-slug registry (`HeadConflictError`,
117
+ `PolicyRejectionError` with findings + truncation markers, `RunLockedError`
118
+ — typed but NOT transient, pace it like a rate limit —
119
+ `RateLimitedError.retry_after` — populated only if the server sends a
120
+ `Retry-After` header, which it does not today). `UnsupportedError` marks the documented
121
+ gRPC gaps.
122
+
123
+ Command retry is deliberately narrow: on REST a command re-sends its SAME
124
+ idempotency key only after a connect-phase failure (`httpx.ConnectError` /
125
+ `ConnectTimeout` / `ProxyError` — the request never left) or the typed
126
+ `OverloadedError` (shed before executing); a gateway 502/504 is transient
127
+ for reads but never re-sent as a command, because it may still be executing
128
+ upstream. On gRPC commands re-send only on `OverloadedError` — never on a
129
+ transport failure. Two gRPC input rules beyond the proto3 zero sentinels:
130
+ `ingest()` mirrors REST `POST /v1/ingest` (a locally undecodable
131
+ `content_base64` raises `InvalidInputError`; a server-side per-item error on
132
+ that one file raises `UnexpectedError` with the text — the wire has no slug;
133
+ `ingest_batch` keeps per-item results), and an explicit `collections=[]` on
134
+ an ingest file or `runbook_refs=[]` on `tokens.mint` raises
135
+ `InvalidInputError` (proto3 cannot carry "explicitly empty"; pass `None` or
136
+ use REST). Both transports accept base64 with surrounding whitespace.
137
+
138
+ The async gRPC variant drives the thread-safe sync stubs via
139
+ `asyncio.to_thread` (documented implementation choice); async REST is native
140
+ httpx.
141
+
142
+ ## Regenerating the gRPC stubs
143
+
144
+ The generated stubs under `src/munarium_client/_proto/` are committed and
145
+ CI-drift-checked. After a proto change:
146
+
147
+ ```bash
148
+ python scripts/gen_protos.py
149
+ ```
150
+
151
+ ## Tests
152
+
153
+ ```bash
154
+ pytest tests # offline unit tests
155
+ MUNARIUM_REST_URL=http://127.0.0.1:18080 MUNARIUM_GRPC_URL=127.0.0.1:15051 \
156
+ MUNARIUM_TOKEN=devtoken MUNARIUM_MGMT_TOKEN=devmgmt \
157
+ pytest conformance # scenarios x {rest,grpc} x {sync,async} + smokes
158
+ # + the platform tests (skipped without the mgmt token)
159
+ ```
@@ -0,0 +1,38 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ # Isolated, disposable qualification stack. Credentials are test-only.
3
+ services:
4
+ postgres:
5
+ image: pgvector/pgvector:pg16
6
+ environment:
7
+ POSTGRES_USER: munarium
8
+ POSTGRES_PASSWORD: clients-test-only
9
+ POSTGRES_DB: munarium
10
+ healthcheck:
11
+ test: [CMD-SHELL, "pg_isready -U munarium"]
12
+ interval: 2s
13
+ timeout: 2s
14
+ retries: 30
15
+ ollama:
16
+ image: python:3.12-slim
17
+ command: [python, /fixture.py, --bind, "0.0.0.0"]
18
+ volumes:
19
+ - ./ollama_fixture.py:/fixture.py:ro
20
+ ports:
21
+ - "127.0.0.1:38114:11434"
22
+ server:
23
+ image: iokaio/munarium:1.1.1
24
+ depends_on:
25
+ postgres:
26
+ condition: service_healthy
27
+ ollama:
28
+ condition: service_started
29
+ environment:
30
+ MUNARIUM_STORE: postgres
31
+ MUNARIUM_SOURCE_STORE: pg
32
+ MUNARIUM_DATABASE_URL: postgres://munarium:clients-test-only@postgres:5432/munarium
33
+ MUNARIUM_AUTH_MODE: static
34
+ MUNARIUM_STATIC_TOKENS: "citoken:ci-clients:rw,cimgmt:ci-clients:mgmt"
35
+ MUNARIUM_TOKEN_SECRET: ci-clients-conformance-hs256-key-0001
36
+ ports:
37
+ - "127.0.0.1:38080:8080"
38
+ - "127.0.0.1:35051:50051"