tarka-sdk 0.4.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 (133) hide show
  1. tarka_sdk-0.4.0/.gitignore +14 -0
  2. tarka_sdk-0.4.0/API_REVISION +1 -0
  3. tarka_sdk-0.4.0/LICENSE +201 -0
  4. tarka_sdk-0.4.0/Makefile +45 -0
  5. tarka_sdk-0.4.0/PKG-INFO +334 -0
  6. tarka_sdk-0.4.0/README.md +307 -0
  7. tarka_sdk-0.4.0/docs/api-reference.md +126 -0
  8. tarka_sdk-0.4.0/docs/async.md +62 -0
  9. tarka_sdk-0.4.0/docs/authentication.md +36 -0
  10. tarka_sdk-0.4.0/docs/channels.md +59 -0
  11. tarka_sdk-0.4.0/docs/control-api.md +125 -0
  12. tarka_sdk-0.4.0/docs/development.md +69 -0
  13. tarka_sdk-0.4.0/docs/errors.md +66 -0
  14. tarka_sdk-0.4.0/docs/index.md +24 -0
  15. tarka_sdk-0.4.0/docs/inference.md +97 -0
  16. tarka_sdk-0.4.0/docs/installation.md +48 -0
  17. tarka_sdk-0.4.0/docs/migration.md +43 -0
  18. tarka_sdk-0.4.0/docs/protobuf.md +56 -0
  19. tarka_sdk-0.4.0/docs/quickstart.md +40 -0
  20. tarka_sdk-0.4.0/docs/sandboxes.md +101 -0
  21. tarka_sdk-0.4.0/docs/troubleshooting.md +20 -0
  22. tarka_sdk-0.4.0/examples/01_quickstart.py +15 -0
  23. tarka_sdk-0.4.0/examples/02_chat_completion.py +20 -0
  24. tarka_sdk-0.4.0/examples/03_streaming_chat.py +25 -0
  25. tarka_sdk-0.4.0/examples/04_openai_payload.py +22 -0
  26. tarka_sdk-0.4.0/examples/05_sandbox_execute.py +39 -0
  27. tarka_sdk-0.4.0/examples/06_async_client.py +25 -0
  28. tarka_sdk-0.4.0/examples/README.md +28 -0
  29. tarka_sdk-0.4.0/examples/agent_host_private_images.py +31 -0
  30. tarka_sdk-0.4.0/proto/third_party/grpc-gateway-LICENSE +27 -0
  31. tarka_sdk-0.4.0/proto/third_party/protoc-gen-openapiv2/options/annotations.proto +51 -0
  32. tarka_sdk-0.4.0/proto/third_party/protoc-gen-openapiv2/options/openapiv2.proto +762 -0
  33. tarka_sdk-0.4.0/pyproject.toml +98 -0
  34. tarka_sdk-0.4.0/scripts/generate.py +134 -0
  35. tarka_sdk-0.4.0/scripts/generate_models.py +214 -0
  36. tarka_sdk-0.4.0/scripts/generate_services.py +92 -0
  37. tarka_sdk-0.4.0/scripts/generate_sync.py +137 -0
  38. tarka_sdk-0.4.0/scripts/test_package.py +65 -0
  39. tarka_sdk-0.4.0/src/protoc_gen_openapiv2/__init__.py +1 -0
  40. tarka_sdk-0.4.0/src/protoc_gen_openapiv2/options/__init__.py +1 -0
  41. tarka_sdk-0.4.0/src/protoc_gen_openapiv2/options/annotations_pb2.py +37 -0
  42. tarka_sdk-0.4.0/src/protoc_gen_openapiv2/options/annotations_pb2.pyi +18 -0
  43. tarka_sdk-0.4.0/src/protoc_gen_openapiv2/options/openapiv2_pb2.py +148 -0
  44. tarka_sdk-0.4.0/src/protoc_gen_openapiv2/options/openapiv2_pb2.pyi +494 -0
  45. tarka_sdk-0.4.0/src/tarka/__init__.py +75 -0
  46. tarka_sdk-0.4.0/src/tarka/_conversion.py +102 -0
  47. tarka_sdk-0.4.0/src/tarka/_options.py +120 -0
  48. tarka_sdk-0.4.0/src/tarka/_records.py +33 -0
  49. tarka_sdk-0.4.0/src/tarka/_streams.py +84 -0
  50. tarka_sdk-0.4.0/src/tarka/_transport.py +205 -0
  51. tarka_sdk-0.4.0/src/tarka/access/v1/access_pb2.py +91 -0
  52. tarka_sdk-0.4.0/src/tarka/access/v1/access_pb2.pyi +235 -0
  53. tarka_sdk-0.4.0/src/tarka/access/v1/access_pb2_grpc.py +489 -0
  54. tarka_sdk-0.4.0/src/tarka/access/v1/access_pb2_grpc.pyi +148 -0
  55. tarka_sdk-0.4.0/src/tarka/aio/__init__.py +1 -0
  56. tarka_sdk-0.4.0/src/tarka/aio/_base.py +29 -0
  57. tarka_sdk-0.4.0/src/tarka/aio/inference.py +1235 -0
  58. tarka_sdk-0.4.0/src/tarka/aio/provisioning.py +1441 -0
  59. tarka_sdk-0.4.0/src/tarka/aio/sandboxes.py +726 -0
  60. tarka_sdk-0.4.0/src/tarka/aio/services.py +3520 -0
  61. tarka_sdk-0.4.0/src/tarka/channels/v1/channels_pb2.py +107 -0
  62. tarka_sdk-0.4.0/src/tarka/channels/v1/channels_pb2.pyi +276 -0
  63. tarka_sdk-0.4.0/src/tarka/channels/v1/channels_pb2_grpc.py +614 -0
  64. tarka_sdk-0.4.0/src/tarka/channels/v1/channels_pb2_grpc.pyi +160 -0
  65. tarka_sdk-0.4.0/src/tarka/client.py +239 -0
  66. tarka_sdk-0.4.0/src/tarka/errors.py +173 -0
  67. tarka_sdk-0.4.0/src/tarka/gateway/v1/gateway_pb2.py +199 -0
  68. tarka_sdk-0.4.0/src/tarka/gateway/v1/gateway_pb2.pyi +640 -0
  69. tarka_sdk-0.4.0/src/tarka/gateway/v1/gateway_pb2_grpc.py +1302 -0
  70. tarka_sdk-0.4.0/src/tarka/gateway/v1/gateway_pb2_grpc.pyi +304 -0
  71. tarka_sdk-0.4.0/src/tarka/grpc.py +114 -0
  72. tarka_sdk-0.4.0/src/tarka/iam/v1/iam_pb2.py +297 -0
  73. tarka_sdk-0.4.0/src/tarka/iam/v1/iam_pb2.pyi +1045 -0
  74. tarka_sdk-0.4.0/src/tarka/iam/v1/iam_pb2_grpc.py +2207 -0
  75. tarka_sdk-0.4.0/src/tarka/iam/v1/iam_pb2_grpc.pyi +515 -0
  76. tarka_sdk-0.4.0/src/tarka/inference/__init__.py +1 -0
  77. tarka_sdk-0.4.0/src/tarka/inference/v1/__init__.py +1 -0
  78. tarka_sdk-0.4.0/src/tarka/inference/v1/inference_pb2.py +215 -0
  79. tarka_sdk-0.4.0/src/tarka/inference/v1/inference_pb2.pyi +636 -0
  80. tarka_sdk-0.4.0/src/tarka/inference/v1/inference_pb2_grpc.py +927 -0
  81. tarka_sdk-0.4.0/src/tarka/inference/v1/inference_pb2_grpc.pyi +250 -0
  82. tarka_sdk-0.4.0/src/tarka/provisioning/__init__.py +1 -0
  83. tarka_sdk-0.4.0/src/tarka/provisioning/v1/__init__.py +1 -0
  84. tarka_sdk-0.4.0/src/tarka/provisioning/v1/agent_secrets_pb2.py +48 -0
  85. tarka_sdk-0.4.0/src/tarka/provisioning/v1/agent_secrets_pb2.pyi +63 -0
  86. tarka_sdk-0.4.0/src/tarka/provisioning/v1/agent_secrets_pb2_grpc.py +24 -0
  87. tarka_sdk-0.4.0/src/tarka/provisioning/v1/agent_secrets_pb2_grpc.pyi +22 -0
  88. tarka_sdk-0.4.0/src/tarka/provisioning/v1/billing_quote_pb2.py +51 -0
  89. tarka_sdk-0.4.0/src/tarka/provisioning/v1/billing_quote_pb2.pyi +157 -0
  90. tarka_sdk-0.4.0/src/tarka/provisioning/v1/billing_quote_pb2_grpc.py +24 -0
  91. tarka_sdk-0.4.0/src/tarka/provisioning/v1/billing_quote_pb2_grpc.pyi +22 -0
  92. tarka_sdk-0.4.0/src/tarka/provisioning/v1/job_pb2.py +71 -0
  93. tarka_sdk-0.4.0/src/tarka/provisioning/v1/job_pb2.pyi +169 -0
  94. tarka_sdk-0.4.0/src/tarka/provisioning/v1/job_pb2_grpc.py +24 -0
  95. tarka_sdk-0.4.0/src/tarka/provisioning/v1/job_pb2_grpc.pyi +22 -0
  96. tarka_sdk-0.4.0/src/tarka/provisioning/v1/provisioning_pb2.py +456 -0
  97. tarka_sdk-0.4.0/src/tarka/provisioning/v1/provisioning_pb2.pyi +1352 -0
  98. tarka_sdk-0.4.0/src/tarka/provisioning/v1/provisioning_pb2_grpc.py +3758 -0
  99. tarka_sdk-0.4.0/src/tarka/provisioning/v1/provisioning_pb2_grpc.pyi +1292 -0
  100. tarka_sdk-0.4.0/src/tarka/provisioning/v1/registry_credentials_pb2.py +65 -0
  101. tarka_sdk-0.4.0/src/tarka/provisioning/v1/registry_credentials_pb2.pyi +97 -0
  102. tarka_sdk-0.4.0/src/tarka/provisioning/v1/registry_credentials_pb2_grpc.py +24 -0
  103. tarka_sdk-0.4.0/src/tarka/provisioning/v1/registry_credentials_pb2_grpc.pyi +22 -0
  104. tarka_sdk-0.4.0/src/tarka/provisioning/v1/sandbox_pb2.py +101 -0
  105. tarka_sdk-0.4.0/src/tarka/provisioning/v1/sandbox_pb2.pyi +294 -0
  106. tarka_sdk-0.4.0/src/tarka/provisioning/v1/sandbox_pb2_grpc.py +505 -0
  107. tarka_sdk-0.4.0/src/tarka/provisioning/v1/sandbox_pb2_grpc.pyi +189 -0
  108. tarka_sdk-0.4.0/src/tarka/provisioning/v1/source_builds_pb2.py +121 -0
  109. tarka_sdk-0.4.0/src/tarka/provisioning/v1/source_builds_pb2.pyi +383 -0
  110. tarka_sdk-0.4.0/src/tarka/provisioning/v1/source_builds_pb2_grpc.py +24 -0
  111. tarka_sdk-0.4.0/src/tarka/provisioning/v1/source_builds_pb2_grpc.pyi +22 -0
  112. tarka_sdk-0.4.0/src/tarka/py.typed +1 -0
  113. tarka_sdk-0.4.0/src/tarka/resources/__init__.py +1 -0
  114. tarka_sdk-0.4.0/src/tarka/resources/_base.py +29 -0
  115. tarka_sdk-0.4.0/src/tarka/resources/inference.py +1230 -0
  116. tarka_sdk-0.4.0/src/tarka/resources/provisioning.py +1442 -0
  117. tarka_sdk-0.4.0/src/tarka/resources/sandboxes.py +722 -0
  118. tarka_sdk-0.4.0/src/tarka/resources/services.py +3521 -0
  119. tarka_sdk-0.4.0/src/tarka/runtime.py +814 -0
  120. tarka_sdk-0.4.0/src/tarka/types.py +2253 -0
  121. tarka_sdk-0.4.0/tests/conftest.py +217 -0
  122. tarka_sdk-0.4.0/tests/fixtures/README.md +4 -0
  123. tarka_sdk-0.4.0/tests/fixtures/server.crt +19 -0
  124. tarka_sdk-0.4.0/tests/fixtures/server.key +28 -0
  125. tarka_sdk-0.4.0/tests/package_consumer.txt +95 -0
  126. tarka_sdk-0.4.0/tests/test_agent_host_registry.py +43 -0
  127. tarka_sdk-0.4.0/tests/test_ci_policy.py +34 -0
  128. tarka_sdk-0.4.0/tests/test_client.py +85 -0
  129. tarka_sdk-0.4.0/tests/test_generated_api.py +49 -0
  130. tarka_sdk-0.4.0/tests/test_recovery.py +448 -0
  131. tarka_sdk-0.4.0/tests/test_resources.py +422 -0
  132. tarka_sdk-0.4.0/tests/test_runtime.py +345 -0
  133. tarka_sdk-0.4.0/tests/test_values.py +110 -0
@@ -0,0 +1,14 @@
1
+ .venv/
2
+ build/
3
+ dist/
4
+ *.egg-info/
5
+ __pycache__/
6
+ .pytest_cache/
7
+ .ruff_cache/
8
+ .coverage
9
+
10
+ # Credentials — never commit a real token.
11
+ # .env.example is the committed template; .env is yours and stays local.
12
+ .env
13
+ .env.*
14
+ !.env.example
@@ -0,0 +1 @@
1
+ 1bbe9c6ab8c1cdd73e4309b1ad062a44eb2964e9
@@ -0,0 +1,201 @@
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
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Tarka
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,45 @@
1
+ .PHONY: build check-examples check-generated check-resources generate generate-resources lint test test-package typecheck verify
2
+
3
+ API_DIR ?= ../api
4
+
5
+ generate:
6
+ uv run python scripts/generate.py --api-dir $(API_DIR)
7
+ $(MAKE) generate-resources
8
+
9
+ generate-resources:
10
+ uv run python scripts/generate_models.py
11
+ uv run python scripts/generate_services.py
12
+ uv run python scripts/generate_sync.py
13
+
14
+ check-resources:
15
+ uv run python scripts/generate_models.py --check
16
+ uv run python scripts/generate_services.py --check
17
+ uv run python scripts/generate_sync.py --check
18
+
19
+ check-generated:
20
+ uv run python scripts/generate.py --api-dir $(API_DIR) --check
21
+ $(MAKE) check-resources
22
+
23
+ lint:
24
+ uv run ruff check src/tarka scripts tests examples
25
+ uv run ruff format --check src/tarka scripts tests examples
26
+ $(MAKE) check-resources
27
+
28
+ check-examples:
29
+ uv run ruff check examples
30
+ uv run ruff format --check examples
31
+ uv run python -m compileall -q examples
32
+
33
+ typecheck:
34
+ uv run mypy
35
+
36
+ test:
37
+ uv run pytest
38
+
39
+ build:
40
+ uv build
41
+
42
+ test-package:
43
+ uv run python scripts/test_package.py
44
+
45
+ verify: lint check-examples typecheck test build test-package
@@ -0,0 +1,334 @@
1
+ Metadata-Version: 2.5
2
+ Name: tarka-sdk
3
+ Version: 0.4.0
4
+ Summary: Official Python SDK for Tarka: typed sync and async resource clients
5
+ Project-URL: Homepage, https://tarka.rest
6
+ Project-URL: Repository, https://github.com/TarkaHQ/sdk-python
7
+ Project-URL: Issues, https://github.com/TarkaHQ/sdk-python/issues
8
+ Author: Tarka
9
+ License-Expression: Apache-2.0
10
+ License-File: LICENSE
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: Apache Software License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.9
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Typing :: Typed
21
+ Requires-Python: >=3.9
22
+ Requires-Dist: googleapis-common-protos<2,>=1.70.0
23
+ Requires-Dist: grpcio<2,>=1.74.0
24
+ Requires-Dist: httpx<1,>=0.28.1
25
+ Requires-Dist: protobuf<7,>=6.31.1
26
+ Description-Content-Type: text/markdown
27
+
28
+ # Tarka Python SDK
29
+
30
+ The official Python SDK for Tarka, with typed synchronous and asynchronous
31
+ resources for inference, organizations, compute, storage, Git, and sandboxes.
32
+
33
+ ```python
34
+ models = client.models.list()
35
+ text = client.chat.text(model=model, prompt="Hello!")
36
+ sandbox = client.org(org_id).sandboxes.create(template=template)
37
+ execution = sandbox.run('print("Hello from Tarka")')
38
+ print(execution.status, execution.stdout)
39
+ ```
40
+
41
+ - Python 3.9+, with type hints, docstrings and a `py.typed` marker.
42
+ - Friendly wrappers for **all 77 RPCs** in the pinned API contract.
43
+ - Lists return lists; reads and writes return typed records; deletes return `None`.
44
+ - Plain dictionaries for JSON, `bytes` for audio, `datetime` timestamps, lossless integers.
45
+ - Sandbox handles with bounded polling and explicit recovery after interruption.
46
+ - The same resource paths and behavior on sync and async clients.
47
+ - The original three runtime dependencies: `grpcio`, `protobuf`, `googleapis-common-protos`.
48
+ - Native stubs remain available only under `client.grpc` on the client.
49
+
50
+ [Documentation](docs/index.md) · [Runnable examples](examples/) ·
51
+ [Migration from 0.2](docs/migration.md) · [RPC coverage and JavaScript parity](docs/api-reference.md)
52
+
53
+ Inference uses `tarka.inference.v1.InferenceService`. Regenerate native gRPC
54
+ clients when upgrading from the previous inference namespace; RPC paths and
55
+ generated import paths now use `v1`. The resource API is unchanged.
56
+
57
+ ## Install this version
58
+
59
+ The **0.4.0 resource API is not yet published to PyPI**. Install from the checkout
60
+ containing these changes:
61
+
62
+ ```sh
63
+ python -m pip install .
64
+ # Or build a distributable wheel:
65
+ uv build
66
+ python -m pip install dist/tarka_sdk-0.4.0-py3-none-any.whl
67
+ ```
68
+
69
+ The distribution is `tarka-sdk`, imported as `tarka`. Installing this checkout
70
+ needs no API repository or protoc. Existing 0.2.0 GitHub release artifacts use
71
+ the older low-level interface; the candidate is not published until the release workflow completes.
72
+ See [installation](docs/installation.md).
73
+
74
+ ## Quick start
75
+
76
+ ```python
77
+ import os
78
+ from tarka import TarkaClient
79
+
80
+ with TarkaClient(os.environ["TARKA_API_KEY"], timeout=30) as client:
81
+ models = client.models.list()
82
+ print([model.id for model in models])
83
+ text = client.chat.text(
84
+ model=os.environ["TARKA_MODEL"],
85
+ prompt="Explain HTTP/2 in one sentence.",
86
+ max_tokens=100,
87
+ )
88
+ print(text)
89
+ ```
90
+
91
+ Reuse a client across calls. SDK-owned channels use TLS and bearer authentication
92
+ at `grpc.tarka.rest:443`; close them on shutdown or use a context manager.
93
+ Pass the token without `Bearer`. The application reads environment variables.
94
+ Use an inference-scoped key for inference, an account token for control resources,
95
+ and an account token or sandbox-scoped key for sandboxes. See [authentication](docs/authentication.md).
96
+
97
+ ## Predictable calls and results
98
+
99
+ Arguments are Python keyword parameters. No request messages or empty dictionaries
100
+ are required, even when specifying only request settings:
101
+
102
+ ```python
103
+ client.models.list(timeout=10)
104
+ client.catalog.list(timeout=10)
105
+ client.catalog.list(modality="text", timeout=10)
106
+ client.chat.text(model=model, prompt="Hello", headers={"x-request-id": "example"})
107
+ ```
108
+
109
+ Every call accepts `timeout` (seconds), `headers` (plain metadata), and `cancel`
110
+ (an optional `CancellationToken`). Payload `metadata` remains a separate field.
111
+ A per-call timeout overrides the client default. Ordinary RPCs have no SDK deadline
112
+ if both are omitted; wait/run helpers default to a 60-second **total** budget.
113
+
114
+ | Operation | Result |
115
+ | --- | --- |
116
+ | `list()` | Python list from one server response; no envelopes or hidden pagination |
117
+ | `get(id)`, `create(...)`, `update(...)` | Typed record |
118
+ | `delete(id)` | `None` after acknowledgement |
119
+ | `revoke(...)`, `cancel(...)` | Updated record/body |
120
+ | `stream(...)` | Lazy, closeable iterator; async iterator on the async client |
121
+ | Sandbox list/get/create/wait | The same handle classes for that client mode |
122
+
123
+ Records live in `tarka.types`, support attribute access, and provide `to_dict()`.
124
+ `to_dict(json_safe=True)` converts bytes to base64 and timestamps to ISO strings.
125
+ Optional absent fields are `None`; counters keep full integer precision.
126
+ API key creation adds a one-time `.secret`; storage credential creation adds
127
+ `.access_key_id`, `.secret_access_key`, `.endpoint`, and `.region`. Store secrets
128
+ at creation. Their repr omits secrets, but explicit serialization includes them.
129
+
130
+ ## Streaming and async
131
+
132
+ ```python
133
+ with client.chat.stream_text(model=model, prompt="Hello") as stream:
134
+ for text in stream:
135
+ print(text, end="", flush=True)
136
+ ```
137
+
138
+ Use the stream context manager when iteration might end early. `break` alone does
139
+ not guarantee cancellation in Python. A stream timeout covers its entire RPC.
140
+
141
+ ```python
142
+ import asyncio
143
+ import os
144
+ from tarka import TarkaAsyncClient
145
+
146
+ async def main() -> None:
147
+ async with TarkaAsyncClient(os.environ["TARKA_API_KEY"], timeout=30) as client:
148
+ models = await client.models.list()
149
+ print([model.id for model in models])
150
+ async with client.chat.stream_text(
151
+ model=os.environ["TARKA_MODEL"], prompt="Hello"
152
+ ) as stream:
153
+ async for text in stream:
154
+ print(text, end="", flush=True)
155
+
156
+ asyncio.run(main())
157
+ ```
158
+
159
+ Await unary methods; do not await the method that creates a stream. Async clients
160
+ use native `grpc.aio`, without blocking wrappers or private event-loop bridges.
161
+
162
+ ## Organization resources
163
+
164
+ Bind the organization once:
165
+
166
+ ```python
167
+ org = client.org(org_id)
168
+ keys = org.api_keys.list()
169
+ usage = org.usage.summary()
170
+ bucket = org.storage.buckets.create(name="example")
171
+ resource = org.compute.jobs.create(name="example", image="example/image:tag")
172
+ ```
173
+
174
+ The scope also provides `members`, `access_requests`, `invitations`, `quotas`,
175
+ `inference_capture`, `repositories`, and `sandboxes`. Root resources include
176
+ `user`, `organizations`, `invitations`, `git`, `models`, `catalog`, `chat`,
177
+ `responses`, `ocr`, `document_layout`, and `audio`.
178
+ [Control API examples](docs/control-api.md) include private GHCR agent hosts.
179
+
180
+ ## Sandbox recovery
181
+
182
+ ```python
183
+ from tarka import ExecutionOperationError
184
+
185
+ sandbox = client.org(org_id).sandboxes.get(sandbox_id)
186
+ try:
187
+ execution = sandbox.run('print("hello")', timeout_seconds=30, timeout=60)
188
+ except ExecutionOperationError as error:
189
+ execution = error.resume(timeout=60)
190
+ print(execution.status, execution.exit_code, execution.stdout)
191
+ ```
192
+
193
+ `run()` waits for readiness, submits code, and waits for completion within one
194
+ budget. Known executions resume by polling their ID. Unacknowledged mutations
195
+ retain their original input and idempotency key for explicit replay within the
196
+ API's 24-hour deduplication window. Nothing is retried automatically by the SDK.
197
+ A timeout does not prove that remote execution stopped. A completed code failure
198
+ returns an execution with `status="failed"`; inspect its status and exit code.
199
+
200
+ Async recoverable operations raise `AsyncExecutionOperationError` (or the matching
201
+ sandbox/template error); use `await error.resume(...)`. Native task cancellation
202
+ remains an `asyncio.CancelledError` and retains the same recovery context.
203
+ See [sandboxes](docs/sandboxes.md) and [errors](docs/errors.md).
204
+
205
+ ## Advanced native gRPC
206
+
207
+ ```python
208
+ from tarka.inference.v1 import inference_pb2
209
+
210
+ response = client.grpc.inference.ListModels(inference_pb2.ListModelsRequest(), timeout=10)
211
+ ```
212
+
213
+ Raw stubs retain protobuf messages, native options and `grpc.RpcError`. Generated
214
+ module paths and the pinned wire contract are unchanged. Normal resource methods
215
+ raise `TarkaError` with readable codes such as `permission_denied`.
216
+
217
+ ## Development
218
+
219
+ ```sh
220
+ uv sync --all-groups
221
+ make verify
222
+ ```
223
+
224
+ `make verify` checks formatting, generation consistency, strict types, examples,
225
+ local TLS/gRPC behavior and distribution builds. Runtime dependencies are unchanged.
226
+ [Development](docs/development.md) explains protobuf generation, the shared sync/async
227
+ implementation, package checks, and the Python version matrix.
228
+
229
+ Apache-2.0. See [LICENSE](LICENSE). Report security issues through the
230
+ [Tarka API security policy](https://github.com/TarkaHQ/api/blob/main/SECURITY.md).
231
+
232
+ ## Gateway connection settings
233
+
234
+ Gateway create, update, get and list responses expose `endpoints` when routing
235
+ is configured. `api_base_url` accepts published operation paths;
236
+ `api_audience` is the exact OAuth resource without `/api`. `mcp_url` and
237
+ `mcp_audience` are the same MCP endpoint. `issuer` identifies the environment's
238
+ OAuth issuer. Use these server-provided settings instead of constructing URLs.
239
+ They are available for setup before publication and do not grant access.
240
+
241
+ `gateway.list_private_services()` lists controller-observed services in the
242
+ bound organization and realm. Set a target's `service_id` and `service_path`
243
+ instead of `url` for a private destination. Only a `ready` service can be
244
+ published; a redeployment requires a new gateway publication. Its exact
245
+ credential scope is `tarka-service://<service_id>` in `allowed_origins`.
246
+
247
+ ## Trusted agent harness
248
+
249
+ Use `RuntimeClient` in the trusted server-side harness. Supply an OAuth token
250
+ provider for the realm's exact runtime resource and `runtime.execute`; the
251
+ server derives the user, bound agent and consent. Platform API keys cannot start
252
+ customer runs.
253
+
254
+ ```python
255
+ from tarka import RuntimeClient, RuntimePermission
256
+
257
+ with RuntimeClient(
258
+ origin=gateway_origin,
259
+ realm_id=realm_id,
260
+ token_provider=current_runtime_oauth_token,
261
+ ) as runtime:
262
+ with runtime.run(
263
+ gateway_id=gateway_id,
264
+ transport="api",
265
+ permissions=[RuntimePermission(capability_id, "invoke")],
266
+ ) as run:
267
+ response = run.api("GET", "/records")
268
+ try:
269
+ tool_result = response.read()
270
+ finally:
271
+ response.close()
272
+ ```
273
+
274
+ `AsyncRuntimeClient` offers the same lifecycle with `async with` and awaited
275
+ methods. For MCP, create a run with `transport="mcp"`, then give its
276
+ `mcp_transport()` to a dedicated `httpx.Client` or `httpx.AsyncClient` and use
277
+ `run.audience` as the MCP endpoint. The adapter rejects every other destination.
278
+
279
+ Only register specific tool closures and their results with the model. Keep
280
+ runtime clients, handles and token providers out of prompts, tool arguments,
281
+ agent workspaces and logs. Runtime metadata is safe to inspect; credentials are
282
+ kept internally and omitted from repr. The SDK does not sandbox hostile code
283
+ running in the same process.
284
+
285
+ The harness renews a lease near expiry when making a request; concurrent use is
286
+ serialized. A failed or uncertain renewal disables further tool calls. Issuance,
287
+ renewal and tool actions are never retried automatically. `run.finish()` revokes
288
+ access; context managers complete on success and attempt cancellation on error.
289
+ A cleanup failure does not replace the original exception. Read and close
290
+ streamed responses promptly. Renewing while an earlier stream is still being
291
+ read may cause its server authorization check to terminate that stream.
292
+
293
+ ### Independent messaging consumers
294
+
295
+ After a customer links their provider account and approves the channel's tool
296
+ scope, an assigned agent worker can consume messages with its autonomous Ory
297
+ token for the same runtime audience. Both customer and agent need channel
298
+ `use` permission. The gateway derives customer identity and tool scope.
299
+
300
+ ```python
301
+ from contextlib import aclosing
302
+ from tarka import AsyncRuntimeClient
303
+
304
+ async with AsyncRuntimeClient(
305
+ origin=gateway_origin, realm_id=realm_id,
306
+ token_provider=current_worker_oauth_token,
307
+ ) as runtime:
308
+ async with aclosing(runtime.messages(channel_id)) as messages:
309
+ async for message in messages:
310
+ # Pass only the prompt as user input. Build tool closures around
311
+ # message.api(...) or message.mcp_transport() inside your harness.
312
+ result = await execute_agent_turn(message.prompt, message)
313
+ await message.reply(result)
314
+ ```
315
+
316
+ `claim_message(channel_id)` returns one message or `None`. `RuntimeClient`
317
+ provides synchronous equivalents; use `contextlib.closing` for its iterator.
318
+ The iterator polls empty queues every five seconds and cancels an unfinished
319
+ run when advancing or closing. A private `reply()` finishes the run and accepts
320
+ at most 2,000 Unicode characters. Recipients are never caller-selected.
321
+ Failures propagate; uncertain claims and replies are never retried. Keep the
322
+ message handle in trusted harness code. Its repr omits both prompt and secrets.
323
+
324
+ ## Publishing
325
+
326
+ The `SDK release` workflow builds and tests both distributions, saves their
327
+ SHA-256 checksums, and uploads a reviewable release artifact. A dry run is the
328
+ default. Publishing requires running `release.yml` on `main` with `publish=true`;
329
+ it publishes those exact tested files and attaches them to a GitHub release.
330
+
331
+ Configure PyPI's trusted publisher for project `tarka-sdk`, owner `TarkaHQ`,
332
+ repository `sdk-python`, workflow `release.yml`, and environment `pypi`. For an
333
+ unpublished project, use a pending publisher. No PyPI token belongs in this repo.
334
+ See [uv trusted publishing](https://docs.astral.sh/uv/guides/package/).