cap-sdk-python 2.14.0__tar.gz → 2.16.1__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 (119) hide show
  1. cap_sdk_python-2.16.1/LICENSE +190 -0
  2. cap_sdk_python-2.16.1/PKG-INFO +414 -0
  3. cap_sdk_python-2.16.1/README.md +378 -0
  4. {cap_sdk_python-2.14.0 → cap_sdk_python-2.16.1}/cap/__init__.py +92 -25
  5. {cap_sdk_python-2.14.0 → cap_sdk_python-2.16.1}/cap/client.py +14 -11
  6. {cap_sdk_python-2.14.0 → cap_sdk_python-2.16.1}/cap/handshake.py +24 -13
  7. {cap_sdk_python-2.14.0 → cap_sdk_python-2.16.1}/cap/heartbeat.py +55 -36
  8. {cap_sdk_python-2.14.0 → cap_sdk_python-2.16.1}/cap/metrics.py +16 -1
  9. cap_sdk_python-2.16.1/cap/packet_boundary.py +155 -0
  10. {cap_sdk_python-2.14.0 → cap_sdk_python-2.16.1}/cap/pb/cordum/agent/v1/alert_pb2.py +3 -3
  11. {cap_sdk_python-2.14.0 → cap_sdk_python-2.16.1}/cap/pb/cordum/agent/v1/alert_pb2_grpc.py +1 -1
  12. {cap_sdk_python-2.14.0 → cap_sdk_python-2.16.1}/cap/pb/cordum/agent/v1/buspacket_pb2.py +7 -5
  13. {cap_sdk_python-2.14.0 → cap_sdk_python-2.16.1}/cap/pb/cordum/agent/v1/buspacket_pb2_grpc.py +1 -1
  14. cap_sdk_python-2.16.1/cap/pb/cordum/agent/v1/handshake_pb2.py +58 -0
  15. {cap_sdk_python-2.14.0 → cap_sdk_python-2.16.1}/cap/pb/cordum/agent/v1/handshake_pb2_grpc.py +1 -1
  16. {cap_sdk_python-2.14.0 → cap_sdk_python-2.16.1}/cap/pb/cordum/agent/v1/heartbeat_pb2.py +3 -3
  17. {cap_sdk_python-2.14.0 → cap_sdk_python-2.16.1}/cap/pb/cordum/agent/v1/heartbeat_pb2_grpc.py +1 -1
  18. cap_sdk_python-2.16.1/cap/pb/cordum/agent/v1/job_pb2.py +86 -0
  19. {cap_sdk_python-2.14.0 → cap_sdk_python-2.16.1}/cap/pb/cordum/agent/v1/job_pb2_grpc.py +1 -1
  20. {cap_sdk_python-2.14.0 → cap_sdk_python-2.16.1}/cap/pb/cordum/agent/v1/policy_pb2.py +3 -3
  21. {cap_sdk_python-2.14.0 → cap_sdk_python-2.16.1}/cap/pb/cordum/agent/v1/policy_pb2_grpc.py +4 -4
  22. cap_sdk_python-2.16.1/cap/pb/cordum/agent/v1/safety_pb2.py +68 -0
  23. {cap_sdk_python-2.14.0 → cap_sdk_python-2.16.1}/cap/pb/cordum/agent/v1/safety_pb2_grpc.py +4 -4
  24. cap_sdk_python-2.16.1/cap/production_events.py +222 -0
  25. cap_sdk_python-2.16.1/cap/production_replay.py +79 -0
  26. cap_sdk_python-2.16.1/cap/production_resource.py +163 -0
  27. cap_sdk_python-2.16.1/cap/production_signing.py +293 -0
  28. cap_sdk_python-2.16.1/cap/production_validation.py +50 -0
  29. {cap_sdk_python-2.14.0 → cap_sdk_python-2.16.1}/cap/progress.py +23 -23
  30. cap_sdk_python-2.16.1/cap/runtime.py +1404 -0
  31. {cap_sdk_python-2.14.0 → cap_sdk_python-2.16.1}/cap/subjects.py +2 -0
  32. {cap_sdk_python-2.14.0 → cap_sdk_python-2.16.1}/cap/testing.py +10 -2
  33. cap_sdk_python-2.16.1/cap/trust_signing.py +148 -0
  34. cap_sdk_python-2.16.1/cap/validate.py +178 -0
  35. cap_sdk_python-2.16.1/cap/worker.py +295 -0
  36. cap_sdk_python-2.16.1/cap/worker_trust.py +223 -0
  37. cap_sdk_python-2.16.1/cap/worker_trust_async.py +85 -0
  38. cap_sdk_python-2.16.1/cap/worker_trust_build.py +128 -0
  39. cap_sdk_python-2.16.1/cap/worker_trust_codec.py +34 -0
  40. cap_sdk_python-2.16.1/cap/worker_trust_runtime.py +272 -0
  41. cap_sdk_python-2.16.1/cap/worker_trust_runtime_config.py +148 -0
  42. cap_sdk_python-2.16.1/cap/worker_trust_validate.py +213 -0
  43. cap_sdk_python-2.16.1/cap/worker_trust_verify.py +117 -0
  44. cap_sdk_python-2.16.1/cap_sdk_python.egg-info/PKG-INFO +414 -0
  45. cap_sdk_python-2.16.1/cap_sdk_python.egg-info/SOURCES.txt +104 -0
  46. cap_sdk_python-2.16.1/cap_sdk_python.egg-info/dependency_links.txt +1 -0
  47. cap_sdk_python-2.16.1/cap_sdk_python.egg-info/requires.txt +18 -0
  48. cap_sdk_python-2.16.1/cap_sdk_python.egg-info/top_level.txt +1 -0
  49. cap_sdk_python-2.16.1/pyproject.toml +55 -0
  50. cap_sdk_python-2.16.1/tests/test_agent_trust_boundary.py +172 -0
  51. cap_sdk_python-2.16.1/tests/test_agent_worker_trust.py +285 -0
  52. cap_sdk_python-2.16.1/tests/test_artifact_trust_smoke.py +73 -0
  53. cap_sdk_python-2.16.1/tests/test_artifact_verifier.py +320 -0
  54. cap_sdk_python-2.16.1/tests/test_artifacts.py +153 -0
  55. cap_sdk_python-2.16.1/tests/test_ci_workflow_contract.py +270 -0
  56. cap_sdk_python-2.16.1/tests/test_generate_protos.py +146 -0
  57. cap_sdk_python-2.16.1/tests/test_handshake_fixture_acceptance.py +37 -0
  58. cap_sdk_python-2.16.1/tests/test_handshake_security_contract.py +264 -0
  59. {cap_sdk_python-2.14.0 → cap_sdk_python-2.16.1}/tests/test_heartbeat.py +12 -19
  60. cap_sdk_python-2.16.1/tests/test_imports.py +160 -0
  61. {cap_sdk_python-2.14.0 → cap_sdk_python-2.16.1}/tests/test_metrics.py +1 -0
  62. {cap_sdk_python-2.14.0 → cap_sdk_python-2.16.1}/tests/test_middleware.py +1 -0
  63. cap_sdk_python-2.16.1/tests/test_payload_validation.py +101 -0
  64. cap_sdk_python-2.16.1/tests/test_production_admission.py +300 -0
  65. cap_sdk_python-2.16.1/tests/test_production_events.py +482 -0
  66. cap_sdk_python-2.16.1/tests/test_production_resource.py +189 -0
  67. cap_sdk_python-2.16.1/tests/test_production_runtime_hardening.py +93 -0
  68. cap_sdk_python-2.16.1/tests/test_production_signing.py +197 -0
  69. cap_sdk_python-2.16.1/tests/test_production_wire_parser.py +262 -0
  70. cap_sdk_python-2.16.1/tests/test_production_worker_echo.py +168 -0
  71. {cap_sdk_python-2.14.0 → cap_sdk_python-2.16.1}/tests/test_progress.py +7 -2
  72. cap_sdk_python-2.16.1/tests/test_publish_node_workflow_contract.py +46 -0
  73. cap_sdk_python-2.16.1/tests/test_publish_workflow_contract.py +261 -0
  74. {cap_sdk_python-2.14.0 → cap_sdk_python-2.16.1}/tests/test_runtime.py +1 -0
  75. cap_sdk_python-2.16.1/tests/test_runtime_hardening.py +300 -0
  76. cap_sdk_python-2.16.1/tests/test_runtime_lifecycle.py +287 -0
  77. cap_sdk_python-2.16.1/tests/test_runtime_parallelism.py +111 -0
  78. {cap_sdk_python-2.14.0 → cap_sdk_python-2.16.1}/tests/test_testing.py +2 -1
  79. cap_sdk_python-2.16.1/tests/test_trust_signing.py +283 -0
  80. cap_sdk_python-2.16.1/tests/test_trust_signing_unknown.py +25 -0
  81. cap_sdk_python-2.16.1/tests/test_typing_contract.py +38 -0
  82. {cap_sdk_python-2.14.0 → cap_sdk_python-2.16.1}/tests/test_validate.py +17 -2
  83. cap_sdk_python-2.16.1/tests/test_validate_release.py +276 -0
  84. cap_sdk_python-2.16.1/tests/test_worker_failures.py +280 -0
  85. cap_sdk_python-2.16.1/tests/test_worker_observability.py +141 -0
  86. cap_sdk_python-2.16.1/tests/test_worker_security_boundary.py +300 -0
  87. cap_sdk_python-2.16.1/tests/test_worker_trust.py +279 -0
  88. cap_sdk_python-2.16.1/tests/test_worker_trust_adversarial.py +291 -0
  89. cap_sdk_python-2.16.1/tests/test_worker_trust_codec.py +32 -0
  90. cap_sdk_python-2.16.1/tests/test_worker_trust_low_level_adversarial.py +43 -0
  91. cap_sdk_python-2.16.1/tests/test_worker_trust_runtime.py +235 -0
  92. cap_sdk_python-2.14.0/PKG-INFO +0 -241
  93. cap_sdk_python-2.14.0/README.md +0 -220
  94. cap_sdk_python-2.14.0/cap/pb/cordum/agent/v1/handshake_pb2.py +0 -43
  95. cap_sdk_python-2.14.0/cap/pb/cordum/agent/v1/job_pb2.py +0 -79
  96. cap_sdk_python-2.14.0/cap/pb/cordum/agent/v1/safety_pb2.py +0 -68
  97. cap_sdk_python-2.14.0/cap/runtime.py +0 -638
  98. cap_sdk_python-2.14.0/cap/validate.py +0 -137
  99. cap_sdk_python-2.14.0/cap/worker.py +0 -144
  100. cap_sdk_python-2.14.0/cap_sdk_python.egg-info/PKG-INFO +0 -241
  101. cap_sdk_python-2.14.0/cap_sdk_python.egg-info/SOURCES.txt +0 -52
  102. cap_sdk_python-2.14.0/cap_sdk_python.egg-info/requires.txt +0 -9
  103. cap_sdk_python-2.14.0/cap_sdk_python.egg-info/top_level.txt +0 -2
  104. cap_sdk_python-2.14.0/pyproject.toml +0 -33
  105. {cap_sdk_python-2.14.0 → cap_sdk_python-2.16.1}/cap/bus.py +0 -0
  106. {cap_sdk_python-2.14.0 → cap_sdk_python-2.16.1}/cap/constants.py +0 -0
  107. {cap_sdk_python-2.14.0 → cap_sdk_python-2.16.1}/cap/errors.py +0 -0
  108. {cap_sdk_python-2.14.0 → cap_sdk_python-2.16.1}/cap/middleware.py +0 -0
  109. {cap_sdk_python-2.14.0 → cap_sdk_python-2.16.1}/cap/pb/__init__.py +0 -0
  110. {cap_sdk_python-2.14.0 → cap_sdk_python-2.16.1}/cap/pb/cordum/__init__.py +0 -0
  111. {cap_sdk_python-2.14.0 → cap_sdk_python-2.16.1}/cap/pb/cordum/agent/__init__.py +0 -0
  112. {cap_sdk_python-2.14.0 → cap_sdk_python-2.16.1}/cap/pb/cordum/agent/v1/__init__.py +0 -0
  113. /cap_sdk_python-2.14.0/cap_sdk_python.egg-info/dependency_links.txt → /cap_sdk_python-2.16.1/cap/py.typed +0 -0
  114. {cap_sdk_python-2.14.0 → cap_sdk_python-2.16.1}/setup.cfg +0 -0
  115. {cap_sdk_python-2.14.0 → cap_sdk_python-2.16.1}/tests/test_conformance.py +0 -0
  116. {cap_sdk_python-2.14.0 → cap_sdk_python-2.16.1}/tests/test_errors.py +0 -0
  117. {cap_sdk_python-2.14.0 → cap_sdk_python-2.16.1}/tests/test_handshake.py +0 -0
  118. {cap_sdk_python-2.14.0 → cap_sdk_python-2.16.1}/tests/test_redis_tls.py +0 -0
  119. {cap_sdk_python-2.14.0 → cap_sdk_python-2.16.1}/tests/test_sdk.py +0 -0
@@ -0,0 +1,190 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright (c) 2025 The cordum Agent Protocol Authors
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
@@ -0,0 +1,414 @@
1
+ Metadata-Version: 2.4
2
+ Name: cap-sdk-python
3
+ Version: 2.16.1
4
+ Summary: CAP (Cordum Agent Protocol) Python SDK
5
+ Author-email: Cordum <eng@cordum.io>
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/cordum-io/cap
8
+ Project-URL: Repository, https://github.com/cordum-io/cap
9
+ Project-URL: Issues, https://github.com/cordum-io/cap/issues
10
+ Keywords: cap,cordum,agent,protocol,sdk,ai
11
+ Classifier: Programming Language :: Python :: 3.9
12
+ Classifier: Programming Language :: Python :: 3.10
13
+ Classifier: Programming Language :: Python :: 3.11
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Programming Language :: Python :: 3.13
16
+ Classifier: Programming Language :: Python :: 3.14
17
+ Requires-Python: >=3.9
18
+ Description-Content-Type: text/markdown
19
+ License-File: LICENSE
20
+ Requires-Dist: protobuf<7,>=6.31.1
21
+ Requires-Dist: grpcio<2,>=1.76.0
22
+ Requires-Dist: nats-py>=2.6.0
23
+ Requires-Dist: cryptography>=41.0.0
24
+ Requires-Dist: pydantic>=2.6.0
25
+ Requires-Dist: redis>=5.0.0
26
+ Provides-Extra: dev
27
+ Requires-Dist: build<2,>=1.2; extra == "dev"
28
+ Requires-Dist: mypy<2,>=1.8; extra == "dev"
29
+ Requires-Dist: packaging>=23.2; extra == "dev"
30
+ Requires-Dist: pdoc>=14.0; extra == "dev"
31
+ Requires-Dist: PyYAML<7,>=6.0; extra == "dev"
32
+ Requires-Dist: pytest<9,>=8.0; extra == "dev"
33
+ Requires-Dist: tomli>=2.0; python_version < "3.11" and extra == "dev"
34
+ Requires-Dist: twine<7,>=5.0; extra == "dev"
35
+ Dynamic: license-file
36
+
37
+ # CAP Python SDK
38
+
39
+ Asyncio-first SDK with NATS helpers for CAP workers and clients. The supported
40
+ and CI-verified interpreter range is CPython 3.9 through 3.14.
41
+
42
+ ## Compatibility
43
+
44
+ - Python: `>=3.9` (tested on every minor release from 3.9 through 3.14).
45
+ - Protobuf runtime: `protobuf>=6.31.1,<7`.
46
+ - gRPC runtime: `grpcio>=1.76.0,<2`.
47
+
48
+ The protobuf modules are included in the wheel and sdist; consumers do not need
49
+ `protoc` or `grpcio-tools`. The minimum runtime versions match the headers in
50
+ the checked-in generated modules.
51
+
52
+ ## Consumer Quickstart (echo over NATS)
53
+
54
+ From an empty directory, install the released package and run an echo round-trip
55
+ against a running NATS server (`nats://127.0.0.1:4222`, or set `CAP_NATS_URL`).
56
+ This is the **direct-pool development-lab** wiring (worker on the submit subject,
57
+ no Scheduler/Safety Kernel); production submits through the governed
58
+ Scheduler/Safety path (see `docs/reference.md`).
59
+
60
+ ```bash
61
+ python -m venv .venv && . .venv/bin/activate
62
+ pip install cap-sdk-python==2.14.0 nats-py
63
+ # add echo.py below, then:
64
+ python echo.py
65
+ ```
66
+
67
+ <!-- cap-release:snippet:python-echo:python -->
68
+ ```python
69
+ import asyncio
70
+ import os
71
+
72
+ import nats
73
+ from cap import client, worker, SUBJECT_RESULT
74
+ from cap.pb.cordum.agent.v1 import buspacket_pb2, job_pb2
75
+
76
+ JOB_ID = "echo-1"
77
+
78
+
79
+ async def handle(req: job_pb2.JobRequest) -> job_pb2.JobResult:
80
+ return job_pb2.JobResult(
81
+ job_id=req.job_id,
82
+ status=job_pb2.JOB_STATUS_SUCCEEDED,
83
+ result_ptr=f"echo://{req.job_id}",
84
+ worker_id="echo-worker",
85
+ )
86
+
87
+
88
+ async def main() -> None:
89
+ url = os.environ.get("CAP_NATS_URL", "nats://127.0.0.1:4222")
90
+
91
+ # Dev-lab worker: consume submitted jobs directly (no Scheduler/Safety).
92
+ worker_task = asyncio.create_task(
93
+ worker.run_worker(nats_url=url, subject="sys.job.submit", handler=handle, sender_id="echo-worker")
94
+ )
95
+ await asyncio.sleep(0.5) # allow the worker subscription to register
96
+
97
+ nc = await nats.connect(url)
98
+ fut: asyncio.Future = asyncio.get_running_loop().create_future()
99
+
100
+ async def on_result(msg):
101
+ pkt = buspacket_pb2.BusPacket()
102
+ pkt.ParseFromString(msg.data)
103
+ if pkt.HasField("job_result") and pkt.job_result.job_id == JOB_ID and not fut.done():
104
+ fut.set_result(pkt.job_result)
105
+
106
+ await nc.subscribe(SUBJECT_RESULT, cb=on_result)
107
+ await nc.flush()
108
+
109
+ await client.submit_job(nc, job_pb2.JobRequest(job_id=JOB_ID, topic="job.echo"), JOB_ID, "echo-client", None)
110
+
111
+ try:
112
+ result = await asyncio.wait_for(fut, timeout=10)
113
+ except asyncio.TimeoutError:
114
+ raise SystemExit("timed out waiting for JobResult (no worker?)")
115
+ if result.status != job_pb2.JOB_STATUS_SUCCEEDED:
116
+ raise SystemExit(f"job {result.job_id} ended {result.status}")
117
+ print(f"job {result.job_id}: SUCCEEDED payload={result.result_ptr}")
118
+ await nc.drain()
119
+ worker_task.cancel()
120
+ try:
121
+ await worker_task
122
+ except asyncio.CancelledError:
123
+ pass
124
+
125
+
126
+ if __name__ == "__main__":
127
+ asyncio.run(main())
128
+ ```
129
+ <!-- cap-release:snippet-end -->
130
+
131
+ ## Quick Start
132
+ 1. Install:
133
+ ```bash
134
+ pip install -e .
135
+ ```
136
+
137
+ 2. Run a worker:
138
+ ```python
139
+ import asyncio
140
+ from cap import worker
141
+ from cap.pb.cordum.agent.v1 import job_pb2
142
+
143
+ async def handle(req: job_pb2.JobRequest):
144
+ return job_pb2.JobResult(
145
+ job_id=req.job_id,
146
+ status=job_pb2.JOB_STATUS_SUCCEEDED,
147
+ result_ptr=f"redis://res/{req.job_id}",
148
+ worker_id="worker-echo-1",
149
+ )
150
+
151
+ asyncio.run(worker.run_worker("nats://127.0.0.1:4222", "job.echo", handle))
152
+ ```
153
+
154
+ 3. Submit a job (client):
155
+ ```python
156
+ import asyncio
157
+ from cryptography.hazmat.primitives.asymmetric import ec
158
+ from cap import client
159
+ from cap.pb.cordum.agent.v1 import job_pb2
160
+ import nats
161
+
162
+ async def main():
163
+ nc = await nats.connect("nats://127.0.0.1:4222")
164
+ priv = ec.generate_private_key(ec.SECP256R1())
165
+ req = job_pb2.JobRequest(
166
+ job_id="job-echo-1",
167
+ topic="job.echo",
168
+ context_ptr="redis://ctx/job-echo-1",
169
+ )
170
+ await client.submit_job(nc, req, "trace-1", "client-py", priv)
171
+ await nc.drain()
172
+
173
+ asyncio.run(main())
174
+ ```
175
+
176
+ ## Files
177
+ - `cap/bus.py` — NATS connector.
178
+ - `cap/worker.py` — worker skeleton with handler hook.
179
+ - `cap/client.py` — publish JobRequest to `sys.job.submit`.
180
+ - `cap/pb/` — protobuf stubs (generated).
181
+
182
+ ## Defaults
183
+ - Subjects: `sys.job.submit`, `sys.job.result`, `sys.heartbeat`.
184
+ - Protocol version: `1`.
185
+ - Signing: `submit_job` and `run_worker` sign envelopes when given an `ec.EllipticCurvePrivateKey`. Signatures use deterministic protobuf serialization (map entries ordered by key) for cross-SDK verification. Generate a keypair with `cryptography`:
186
+ ```python
187
+ from cryptography.hazmat.primitives.asymmetric import ec
188
+ priv = ec.generate_private_key(ec.SECP256R1())
189
+ pub = priv.public_key()
190
+ ```
191
+ - Set `public_keys` on `run_worker` to verify incoming packets.
192
+ - Omit `public_keys` to accept unsigned packets.
193
+ - Pass `private_key=None` to `submit_job` if you want to send unsigned envelopes.
194
+
195
+ Swap out `cap.bus` if you need a different transport.
196
+
197
+ ## Testing
198
+
199
+ The `cap.testing` module lets you test handlers without running NATS or Redis.
200
+
201
+ ```python
202
+ from cap.testing import run_handler
203
+ from cap.pb.cordum.agent.v1 import job_pb2
204
+
205
+ async def test_echo():
206
+ result = await run_handler(
207
+ lambda ctx, data: {"echo": data["prompt"]},
208
+ {"prompt": "hello"},
209
+ topic="job.echo",
210
+ )
211
+ assert result.status == job_pb2.JOB_STATUS_SUCCEEDED
212
+ ```
213
+
214
+ - `run_handler(handler, input, **options)` — runs a single handler invocation and returns the `JobResult`.
215
+ - `create_test_agent(**options)` — returns `(agent, mock_nats, store)` pre-wired with `MockNATS` + `InMemoryBlobStore`.
216
+ - `MockNATS` — in-memory NATS mock for custom test setups.
217
+
218
+ ## Runtime (High-Level SDK)
219
+ The runtime hides NATS/Redis plumbing and gives you typed handlers.
220
+
221
+ ```python
222
+ import asyncio
223
+ from pydantic import BaseModel
224
+ from cap.runtime import Agent, Context
225
+
226
+ class Input(BaseModel):
227
+ prompt: str
228
+
229
+ class Output(BaseModel):
230
+ summary: str
231
+
232
+ agent = Agent(retries=2)
233
+
234
+ @agent.job("job.summarize", input_model=Input, output_model=Output)
235
+ async def summarize(ctx: Context, data: Input) -> Output:
236
+ return Output(summary=data.prompt[:140])
237
+
238
+ asyncio.run(agent.run())
239
+ ```
240
+
241
+ ### Authenticated worker trust
242
+
243
+ - In this unreleased source tree, `Agent` accepts `worker_trust_mode`, `worker_trust`, bounded timeout/retry/renewal tuning, or the `CORDUM_SDK_HANDSHAKE` mode. `warn`/`enforce` require a complete `WorkerTrustConfig` with enrolled identities, exact audience, active P-256 proof key, scheduler identity/pins, and SDK version.
244
+ - Omitting every trust option retains legacy `off` for source compatibility. Once configuration or tuning is present, mode is explicit and `off` rejects dormant material; use `warn` only for visible migration and `enforce` for fail-closed admission.
245
+ - Before handlers, the runtime uses bounded protobuf request/reply on `sys.worker.handshake.challenge` and `sys.worker.handshake.authenticate`, verifies the pinned scheduler, installs and attaches the opaque token, and renews with the current token. It never falls back to ISSUE; expired, revoked, superseded, wrong-audience, or binding-mismatched sessions are invalid.
246
+ - Enroll/rotate through an authenticated control plane: register only the public key, retain the private key in the worker, overlap scheduler pins, then revoke old authoritative key/session records.
247
+ - `build_challenge_request`, `build_authenticate`, trust codecs/signers/verifiers, and `handshake_payload` / `publish_handshake` support adapters and compatibility; they do not enroll keys, issue/revoke sessions, grant topics, or authenticate `sys.handshake`.
248
+ - Low-level `run_worker(..., session_token=...)` is caller-managed static compatibility only: it does not mint, renew, reauthenticate after reconnect, or observe revocation. Use high-level `Agent` with `warn`/`enforce` for authenticated worker trust. `warn` fails open only for transport availability errors; malformed, rejected, unpinned, expired, or otherwise invalid proofs stop trust admission.
249
+ - Never log key material, tokens, signatures, nonces, complete trust packets, or raw rejections; use bounded mode/phase/outcome/coarse-reason telemetry.
250
+
251
+ ### Failure and shutdown contract
252
+
253
+ - In both `run_worker()` and the high-level `Agent`, an ordinary handler
254
+ `Exception` produces exactly one `JOB_STATUS_FAILED` result with the generic
255
+ external message `handler failed`. Diagnostics use bounded, newline-safe
256
+ identifiers and the exception type without exposing exception text. Logging
257
+ and metrics hooks are best-effort and cannot block the terminal result; the
258
+ worker remains available for later jobs.
259
+ - `asyncio.CancelledError`, `KeyboardInterrupt`, and `SystemExit` remain control
260
+ flow and are not converted into job results.
261
+ - Cancelling `run_worker()` drains its NATS connection before exit.
262
+ - `Agent.run()` always enters cleanup without letting a cleanup error replace
263
+ cancellation or another primary failure. `Agent.close()` stops intake, stops
264
+ the heartbeat, waits for tracked handlers (retaining the live session for their
265
+ terminal results), drains NATS, and closes the blob
266
+ store. Each asynchronous cleanup stage has the `shutdown_timeout` deadline
267
+ (30 seconds by default), and later stages are still attempted after a timeout.
268
+ Pass `None` only to opt out of deadlines; zero and negative values are
269
+ rejected. Repeated or concurrent calls share the same cleanup operation.
270
+
271
+ ### Middleware
272
+
273
+ Add cross-cutting concerns (logging, auth, metrics) without modifying handlers:
274
+
275
+ ```python
276
+ from cap.middleware import logging_middleware
277
+
278
+ # Built-in logging middleware
279
+ agent.use(logging_middleware())
280
+
281
+ # Custom middleware
282
+ async def timing(ctx, data, next_fn):
283
+ import time
284
+ start = time.monotonic()
285
+ result = await next_fn(ctx, data)
286
+ elapsed = time.monotonic() - start
287
+ print(f"job {ctx.job_id} took {elapsed:.3f}s")
288
+ return result
289
+
290
+ agent.use(timing)
291
+ ```
292
+
293
+ Middleware executes in registration order (FIFO). Each can inspect context,
294
+ measure timing, or short-circuit by returning without calling `next_fn`.
295
+
296
+ ### Redis TLS
297
+ The Python SDK provides `redis_ssl_context_from_env()` to build an `SSLContext` for secure Redis connections. It reads:
298
+ - `REDIS_TLS_CA` (or `SSL_CERT_FILE` fallback): Path to CA certificate.
299
+ - `REDIS_TLS_CERT` / `REDIS_TLS_KEY`: Path to client certificate/key pair.
300
+ - `REDIS_TLS_SERVER_NAME`: SNI server name override.
301
+ - `REDIS_TLS_INSECURE`: Set to `1` or `true` to skip certificate verification (dev only).
302
+
303
+ ### Environment
304
+ - `NATS_URL` (default `nats://127.0.0.1:4222`)
305
+ - `REDIS_URL` (default `redis://127.0.0.1:6379/0`)
306
+
307
+ ## Contributor and Release Verification
308
+
309
+ Run these commands from the repository root. Generated Python modules are
310
+ checked, never rewritten, by the pinned toolchain:
311
+
312
+ ```bash
313
+ python -m pip install -e "sdk/python[dev]"
314
+ python -m pytest -q sdk/python/tests --ignore=sdk/python/tests/integration
315
+
316
+ python -m pip install -r sdk/python/requirements-codegen.txt
317
+ python sdk/python/scripts/generate_protos.py --check
318
+ ```
319
+
320
+ The real-NATS test is mandatory in CI and never skips. Run it against an
321
+ explicit broker URL (CI and publishing pin NATS 2.12.6 by image digest):
322
+
323
+ ```bash
324
+ CAP_TEST_NATS_URL=nats://127.0.0.1:4222 \
325
+ python -m pytest -q sdk/python/tests/integration/test_worker_nats.py
326
+ ```
327
+
328
+ Build and verify the exact wheel/sdist pair in clean consumer environments:
329
+
330
+ ```bash
331
+ rm -rf dist/python
332
+ python -m build --outdir dist/python sdk/python
333
+ python -m twine check dist/python/*
334
+ python sdk/python/scripts/verify_artifacts.py \
335
+ --wheel dist/python/*.whl \
336
+ --sdist dist/python/*.tar.gz \
337
+ > dist/python/artifact-verification.json
338
+ ```
339
+
340
+ Before creating a release, bump the checked-in package version and require an
341
+ exact lowercase `v<version>` tag. Replace `<version>` below with the version in
342
+ `sdk/python/pyproject.toml`:
343
+
344
+ ```bash
345
+ python sdk/python/scripts/validate_release.py \
346
+ --tag "v<version>" \
347
+ --artifact-report dist/python/artifact-verification.json
348
+ ```
349
+
350
+ The publish workflow exports the tagged commit, builds once, records the exact
351
+ artifact inventory and SHA-256 checksums, and publishes only that verified
352
+ pair. Do not mutate generated code or package metadata during publishing, and
353
+ do not use a manual or `skip-existing` fallback.
354
+
355
+ ## Generating API Docs
356
+
357
+ Generate HTML API reference locally using [pdoc](https://pdoc.dev/):
358
+
359
+ ```bash
360
+ pip install cap-sdk-python[dev]
361
+ pdoc ./cap --output-dir docs
362
+ ```
363
+
364
+ Output is written to `docs/` (gitignored). Open `docs/index.html` to browse.
365
+
366
+ ## Observability
367
+
368
+ ### Structured Logging
369
+ The runtime Agent and Worker use `logging.Logger` (stdlib) for structured logging. All log calls include contextual fields (`job_id`, `trace_id`, `topic`, `sender_id`). Pass a custom logger or leave as default:
370
+
371
+ ```python
372
+ import logging
373
+ from cap.runtime import Agent
374
+
375
+ logger = logging.getLogger("my-agent")
376
+ logger.setLevel(logging.DEBUG)
377
+ agent = Agent(logger=logger)
378
+ ```
379
+
380
+ ### MetricsHook
381
+ Implement the `MetricsHook` protocol to integrate with Prometheus, OpenTelemetry, or any metrics system:
382
+
383
+ ```python
384
+ from cap.metrics import MetricsHook
385
+
386
+ class MetricsHook(Protocol):
387
+ def on_job_received(self, job_id: str, topic: str) -> None: ...
388
+ def on_job_completed(self, job_id: str, duration_ms: int, status: str) -> None: ...
389
+ def on_job_failed(self, job_id: str, error_msg: str) -> None: ...
390
+ def on_heartbeat_sent(self, worker_id: str) -> None: ...
391
+ ```
392
+
393
+ The default is `NoopMetrics` (zero overhead). Example Prometheus integration:
394
+
395
+ ```python
396
+ from cap.runtime import Agent
397
+
398
+ class PromMetrics:
399
+ def on_job_received(self, job_id, topic):
400
+ jobs_received.labels(topic=topic).inc()
401
+
402
+ def on_job_completed(self, job_id, duration_ms, status):
403
+ job_duration.labels(status=status).observe(duration_ms)
404
+
405
+ def on_job_failed(self, job_id, error_msg):
406
+ jobs_failed.inc()
407
+
408
+ def on_heartbeat_sent(self, worker_id):
409
+ pass
410
+
411
+ agent = Agent(metrics=PromMetrics())
412
+ ```
413
+
414
+ The `trace_id` is propagated through all log and metrics calls for distributed tracing correlation.