cordium-sdk 0.2.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 (40) hide show
  1. cordium_sdk-0.2.0/LICENSE +202 -0
  2. cordium_sdk-0.2.0/MANIFEST.in +4 -0
  3. cordium_sdk-0.2.0/PKG-INFO +271 -0
  4. cordium_sdk-0.2.0/README.md +249 -0
  5. cordium_sdk-0.2.0/docs/api.md +2855 -0
  6. cordium_sdk-0.2.0/docs/development.md +57 -0
  7. cordium_sdk-0.2.0/examples/async_commands.py +33 -0
  8. cordium_sdk-0.2.0/examples/quickstart.py +23 -0
  9. cordium_sdk-0.2.0/examples/template_build.py +22 -0
  10. cordium_sdk-0.2.0/examples/terminal.py +28 -0
  11. cordium_sdk-0.2.0/pyproject.toml +24 -0
  12. cordium_sdk-0.2.0/setup.cfg +4 -0
  13. cordium_sdk-0.2.0/src/cordium/__init__.py +140 -0
  14. cordium_sdk-0.2.0/src/cordium/_engine.py +147 -0
  15. cordium_sdk-0.2.0/src/cordium/_portal.py +93 -0
  16. cordium_sdk-0.2.0/src/cordium/auth.py +162 -0
  17. cordium_sdk-0.2.0/src/cordium/client.py +253 -0
  18. cordium_sdk-0.2.0/src/cordium/errors.py +55 -0
  19. cordium_sdk-0.2.0/src/cordium/exec.py +270 -0
  20. cordium_sdk-0.2.0/src/cordium/files.py +240 -0
  21. cordium_sdk-0.2.0/src/cordium/models.py +100 -0
  22. cordium_sdk-0.2.0/src/cordium/py.typed +0 -0
  23. cordium_sdk-0.2.0/src/cordium/resources.py +1379 -0
  24. cordium_sdk-0.2.0/src/cordium/spec.py +256 -0
  25. cordium_sdk-0.2.0/src/cordium/streams.py +136 -0
  26. cordium_sdk-0.2.0/src/cordium/sync.py +1741 -0
  27. cordium_sdk-0.2.0/src/cordium/terminals.py +161 -0
  28. cordium_sdk-0.2.0/src/cordium/workspaces.py +532 -0
  29. cordium_sdk-0.2.0/src/cordium_sdk.egg-info/PKG-INFO +271 -0
  30. cordium_sdk-0.2.0/src/cordium_sdk.egg-info/SOURCES.txt +38 -0
  31. cordium_sdk-0.2.0/src/cordium_sdk.egg-info/dependency_links.txt +1 -0
  32. cordium_sdk-0.2.0/src/cordium_sdk.egg-info/requires.txt +4 -0
  33. cordium_sdk-0.2.0/src/cordium_sdk.egg-info/top_level.txt +1 -0
  34. cordium_sdk-0.2.0/tests/conftest.py +270 -0
  35. cordium_sdk-0.2.0/tests/test_auth_http.py +216 -0
  36. cordium_sdk-0.2.0/tests/test_contracts.py +77 -0
  37. cordium_sdk-0.2.0/tests/test_exec_files.py +107 -0
  38. cordium_sdk-0.2.0/tests/test_resources.py +331 -0
  39. cordium_sdk-0.2.0/tests/test_sync.py +101 -0
  40. cordium_sdk-0.2.0/tests/test_workspaces.py +143 -0
@@ -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,4 @@
1
+ include LICENSE README.md
2
+ recursive-include docs *.md
3
+ recursive-include examples *.py
4
+ recursive-include tests *.py
@@ -0,0 +1,271 @@
1
+ Metadata-Version: 2.4
2
+ Name: cordium-sdk
3
+ Version: 0.2.0
4
+ Summary: The synchronous and asynchronous Python SDK for Cordium workspaces
5
+ Author-email: Octelium <contact@octelium.com>
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Repository, https://github.com/octelium/sdk-python
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Programming Language :: Python :: 3.11
10
+ Classifier: Programming Language :: Python :: 3.12
11
+ Classifier: Programming Language :: Python :: 3.13
12
+ Classifier: Programming Language :: Python :: 3.14
13
+ Classifier: Typing :: Typed
14
+ Requires-Python: >=3.11
15
+ Description-Content-Type: text/markdown
16
+ License-File: LICENSE
17
+ Requires-Dist: octelium-apis<2,>=1.0.3
18
+ Requires-Dist: betterproto==2.0.0b7
19
+ Requires-Dist: grpclib<0.5,>=0.4.8
20
+ Requires-Dist: httpx<1,>=0.27
21
+ Dynamic: license-file
22
+
23
+ # Cordium Python SDK
24
+
25
+ Typed synchronous and native `asyncio` clients for [Cordium](https://github.com/octelium/cordium) workspaces. Python 3.11+.
26
+
27
+ The SDK covers workspaces, execution, files, persistent terminals, logs, events, templates and builds, snapshots, volumes, Spaces, Secrets, Git providers, memberships, regions, and configuration. Generated protobuf messages remain available for the full API.
28
+
29
+ ## Installation
30
+
31
+ From this checkout:
32
+
33
+ ```bash
34
+ python -m pip install ./packages/apis ./packages/cordium
35
+ ```
36
+
37
+ The distribution is `cordium-sdk`; the import is `cordium`. It requires the accompanying `octelium-apis>=1.0.3` bindings. Both packages must be released before a registry-only install of this version will work.
38
+
39
+ ```bash
40
+ export CORDIUM_DOMAIN=example.com
41
+ export OCTELIUM_AUTH_TOKEN='<your authentication token>'
42
+ ```
43
+
44
+ The client connects to `octelium-api.<domain>:443` with verified TLS. Construction is lazy; the first request authenticates.
45
+
46
+ ## Start with the blocking client
47
+
48
+ ```python
49
+ from cordium import Cordium, Resources
50
+
51
+ with Cordium() as client:
52
+ workspace = client.workspaces.run(
53
+ image="python:3.13",
54
+ resources=Resources(cpu=1000, memory=1024),
55
+ ephemeral=True,
56
+ timeout=300,
57
+ )
58
+ try:
59
+ result = workspace.exec(["python", "-c", "print('Hello from Cordium')"])
60
+ print(result.stdout)
61
+ workspace.files.write_text("/workspace/hello.txt", "Hello!\n")
62
+ finally:
63
+ workspace.stop().wait_until_stopped()
64
+ workspace.delete()
65
+ ```
66
+
67
+ `create()` returns a stopped workspace. `run()` creates, starts, and waits for `RUNNING` under one total deadline. A failed `run()` leaves the workspace for diagnosis. A `WorkspaceFailureError` carries its resource in `.workspace`; other SDK errors expose `.code`, `.details`, and their underlying `__cause__` when available.
68
+
69
+ **Client context exit closes connections and cancels operations; it does not stop or delete workspaces.** Ephemeral workspaces discard storage on stop but retain their resource object until explicitly deleted.
70
+
71
+ All examples assume access to an existing Cordium Cluster and permission for the requested operations. No Cluster is provisioned by the SDK.
72
+
73
+ ## Native async
74
+
75
+ ```python
76
+ import asyncio
77
+ from cordium import AsyncCordium
78
+
79
+ async def main() -> None:
80
+ async with AsyncCordium() as client:
81
+ workspace = await client.workspaces.run(image="python:3.13")
82
+ try:
83
+ async with asyncio.TaskGroup() as group:
84
+ version = group.create_task(workspace.exec(["python", "--version"]))
85
+ platform = group.create_task(workspace.exec(["uname", "-a"]))
86
+ print(version.result().stdout, platform.result().stdout)
87
+ finally:
88
+ await workspace.stop()
89
+ await workspace.wait_until_stopped()
90
+ await workspace.delete()
91
+
92
+ asyncio.run(main())
93
+ ```
94
+
95
+ Async methods and their blocking counterparts use the same names, arguments, and result types. Async streams use `async for`, `async with`, and `aclose()`; blocking streams use `for`, `with`, and `close()`. `AsyncCordium` belongs to one event loop. `Cordium` owns one event-loop thread and supports calls from multiple threads. Create a new client after `fork`; do not share a client across processes. Use `AsyncCordium` in async applications so the application loop remains responsive.
96
+
97
+ ## Configuration and references
98
+
99
+ ```python
100
+ from cordium import Application, Ref, Resources, SecretRef, Task, VolumeMount
101
+
102
+ workspace = client.workspaces.create(
103
+ template="python.team.cordium",
104
+ display_name="data processing",
105
+ env={"MODE": "development", "API_KEY": SecretRef("api-key")},
106
+ vars={"branch": "main"},
107
+ resources=Resources(cpu=2000, memory=2048, storage=10000),
108
+ applications=[Application("api", 8000, default=True)],
109
+ tasks=[Task(name="setup", command="python -m pip install -r requirements.txt")],
110
+ volumes=[VolumeMount("data.team.cordium", "/data")],
111
+ )
112
+ workspace.start(region=Ref(uid="region-uid"), vars={"branch": "release"})
113
+ workspace.wait_until_running()
114
+ ```
115
+
116
+ CPU uses **millicores**; memory and storage use **megabytes**, following the protobuf API. Omitted values inherit Cluster/template/Space policy. `SecretRef` resolves a Space Secret without exposing its value locally. Start-time variables and region selection apply only to that run.
117
+
118
+ Methods accepting a reference take a name string or `Ref(uid="...")`. Space-scoped resource names may be qualified, such as `python.team.cordium`. Workspace names are assigned by the Cluster. `template` and `snapshot` are exclusive; a snapshot restore cannot be ephemeral. Templates cannot declare workspace applications or ephemeral storage.
119
+
120
+ Convenience fields replace the corresponding fields of a copied `spec=` message. Lists replace, rather than append. `create_workspace_spec(...)` builds the same validated spec without network I/O. For advanced image sources, repository authentication, networking, capabilities, filesystem policy, devcontainer features, and additional repositories, supply generated messages through `spec=`. Source template/snapshot references are creation options, not persisted spec fields.
121
+
122
+ Workspace properties (`name`, `uid`, `state`, `hostname`, `url`, `spec`, `status`, `proto`, etc.) read a local cache. `refresh()`, lifecycle methods, and waits refresh it. Protobuf properties return deep copies. `wait_until_ready()` accepts `PREPARING`, when exec is available but setup is still running; `wait_until_running()` waits for setup to finish. Watch events do not silently mutate existing handles.
123
+
124
+ ## Commands and streaming
125
+
126
+ A command string runs as a shell expression. A sequence of strings is safely quoted as literal argv. `argv(...)` and `shell_quote(...)` are available for composing commands. NUL bytes in shell arguments are rejected. `cwd=`, `env=`, and `root=True` configure execution.
127
+
128
+ ```python
129
+ from cordium import ExecError
130
+
131
+ try:
132
+ result = workspace.exec(["python", "script.py"], timeout=60)
133
+ except ExecError as error:
134
+ print(error.result.exit_code, error.result.stderr)
135
+
136
+ with workspace.exec_stream("python -u server.py", timeout=60) as command:
137
+ for event in command:
138
+ print(event.stream, event.data) # bytes; chunk boundaries need not be UTF-8 boundaries
139
+ result = command.wait()
140
+ ```
141
+
142
+ `exec()` defaults to `check=True`, raising `ExecError` for nonzero exit. `exec_stream()` defaults to `check=False`, allowing inspection of the exit status after streaming. `ExecResult` includes `exit_code`, `stdout_bytes`, `stderr_bytes`, `success`, `truncated`, and `killed`. Its `.stdout`/`.stderr` properties decode UTF-8 with replacement; use bytes for exact data.
143
+
144
+ Captures are limited to 1 MiB **per output stream** by default. Excess capture sets `truncated`; it does not stop output iteration. Stream queues default to 8 MiB and also have an event-count limit; a stalled consumer gets `RESOURCE_EXHAUSTED` instead of unbounded memory growth. Configure `max_capture_bytes` and `max_buffer_bytes` as needed. Calling `wait()` before output iteration selects drain-only mode. After iteration begins, continue consuming output while waiting for completion.
145
+
146
+ For interactive input, use `command.write(str_or_bytes)` and `command.kill()`. `stdin=` sends initial data. **The Exec protocol has no independent stdin EOF message.** A command reading until EOF can remain blocked; use explicit framing such as `head -c 4` when sending four bytes. The file helpers handle this framing automatically. Cancelling/closing an exec session cancels the remote command; `kill()` explicitly signals its process group.
147
+
148
+ Python does not close a custom iterator on `break`. Use a context manager around command, watch, log, and terminal streams whenever iteration can end early. A stream is single-consumer; concurrent reads are rejected. No background reconnect or replay is performed.
149
+
150
+ ## Files
151
+
152
+ ```python
153
+ workspace.files.write_bytes("/workspace/data.bin", b"\x00\xff")
154
+ text = workspace.files.read_text("/workspace/hello.txt")
155
+ workspace.files.upload("./local.zip", "/workspace/input.zip")
156
+ workspace.files.download("/workspace/output.zip", "./output.zip")
157
+ workspace.files.mkdir("/workspace/results", parents=True)
158
+ workspace.files.remove("/workspace/results", recursive=True)
159
+ ```
160
+
161
+ `read_bytes`/`read_text` default to a 16 MiB limit and fail rather than silently truncate. Text decoding defaults to strict UTF-8; configure `encoding`/`errors` if needed. `upload` and `download` use bounded chunks; they do not buffer entire files. Downloads atomically replace the destination only on success, using a private file (mode `0600` on POSIX). Existing local files survive failed downloads. Remote writes truncate their destination and may leave partial data on failure. Parent directories must exist unless explicitly created with `mkdir()`.
162
+
163
+ Paths are quoted literally, including spaces and shell metacharacters; `~` and `$HOME` are not expanded. Helpers require standard POSIX `sh`, `head`, `cat`, `base64`, `mkdir`, and `rm` in the workspace. `root=True` is available on each operation. File upload detects size changes during transfer; callers should avoid editing a source during upload.
164
+
165
+ ## Persistent terminals, logs, and events
166
+
167
+ ```python
168
+ terminal = workspace.terminals.create(cols=120, rows=40)
169
+ try:
170
+ with terminal:
171
+ terminal.write("echo hello\n")
172
+ with terminal.events as events:
173
+ for event in events:
174
+ if event.type == "output":
175
+ print(event.data)
176
+ break
177
+ finally:
178
+ terminal.remove()
179
+ ```
180
+
181
+ A terminal persists after detachment and may have multiple listeners. `close()`/`aclose()` and context exit detach locally; **only `remove()` terminates its shell**. Use `workspace.terminals.list()` and `.attach(id)` to reconnect. Output subscriptions begin lazily; creating a handle alone is not a guarantee that a listener has reached the server. Events distinguish binary output, resize, and close. `resize(cols, rows)` changes the PTY dimensions.
182
+
183
+ `workspace.logs()` streams typed initialization-stage records. `client.workspaces.watch()` observes the caller's workspaces; `workspace.watch()` restricts the subscription. They return generated messages, preserving timestamps, oneofs, and both old/new resources for updates. Watch supplies future events, not an initial list or a durable event log.
184
+
185
+ ## Resource collections
186
+
187
+ | Collection | Operations |
188
+ | --- | --- |
189
+ | `workspaces` | create/run/get/list/all/update/delete/watch |
190
+ | `spaces` | create/get/list/all/update/modify/delete/leave |
191
+ | `templates` | create/get/list/all/update/modify/delete/build/cancel_build/wait_for_build |
192
+ | `snapshots` | create/get/list/all/delete/wait_until_ready |
193
+ | `volumes` | create/get/list/all/update/modify/delete/grow/wait_until_ready |
194
+ | `secrets` | create/get/list/all/delete |
195
+ | `user_secrets` | create/create_ssh_key/get/list/all/update/modify/set/delete |
196
+ | `git_providers` | create/create_oauth/create_oauth2/get/list/all/update/modify/delete |
197
+ | `memberships` | add/mine/get/list/all/update/modify/set_role/delete |
198
+ | `regions` | list/all |
199
+ | `user_config` | get/update/modify/set_preferred_region/set_dotfiles |
200
+ | `management` | get_cluster_config/update_cluster_config/modify_cluster_config |
201
+
202
+ Resource collections return documented generated protobuf messages. List methods return `Page` with `items`, `page`, `page_size`, `total_count`, and `has_more`. Pages start at zero. `page_size=0` uses the server default; `.all()` defaults to 100 and fetches lazily. Its timeout applies per page. Use the supported `space=`, `workspace=`, or `template=` filters; mutually exclusive filters are rejected. Server permissions always apply.
203
+
204
+ ```python
205
+ with client.templates.all(space="team.cordium") as templates:
206
+ for template in templates:
207
+ print(template.metadata.name)
208
+
209
+ client.templates.create(
210
+ "python.team.cordium", image="python:3.13",
211
+ tasks=[Task(name="prepare", command="python -m pip install requests")],
212
+ )
213
+ started = client.templates.build("python.team.cordium", tags=("release",))
214
+ build_id = started.status.build_info.current_running_build_id
215
+ client.templates.wait_for_build("python.team.cordium", build_id)
216
+ ```
217
+
218
+ Build waits use an explicit build ID so a previous success cannot satisfy a new build's wait. Snapshot creation is asynchronous; wait until ready before restoring via `workspaces.run(snapshot="...")`. Snapshots of running workspaces are crash-consistent; coordinate application writes for application-level consistency. Volume size is megabytes. `grow()` rejects shrinking below requested or observed capacity; expansion support depends on the backend. Some volumes become ready only after first attachment.
219
+
220
+ Secrets accept text, bytes, or JSON attributes. Structured numbers must be finite; integers outside ±2**53 are rejected. Secret values are write-only. `user_secrets.create_ssh_key()` asks the Cluster to generate a key pair; it does not upload a private key. OAuth Git providers reference a Space Secret **name** for `client_secret`.
221
+
222
+ For updates, fetch the resource, edit its spec, then pass it to `update()`, preserving metadata/version. `modify(ref, callback)` performs this sequence under one deadline and writes only if the synchronous callback succeeds. It does not retry conflicts or repeat callbacks. In the blocking client callbacks execute on the SDK's loop thread and must not call blocking methods on that same client. `workspace.modify(callback)` also refreshes the handle.
223
+
224
+ ## Authentication, HTTP, errors, and deadlines
225
+
226
+ Explicit credentials override the environment:
227
+
228
+ ```python
229
+ from cordium import AccessToken, Assertion, AssertionFile, AuthenticationToken, Cordium
230
+
231
+ client = Cordium("example.com", auth=AuthenticationToken("one-time-token"))
232
+ # Other options:
233
+ # AccessToken("externally-managed-token")
234
+ # AccessToken(callable_returning_current_token) # sync or async callable
235
+ # Assertion(callable_returning_assertion, scopes=("scope",))
236
+ # AssertionFile("/var/run/secrets/workload/token")
237
+ ```
238
+
239
+ Close the client when finished. Authentication tokens are attempted once, then the returned session is refreshed. Assertion files are reread for reauthentication. Concurrent callers share one session refresh; cancellation of one caller does not cancel authentication needed by other callers. Refresh has a 30-second internal deadline. Access-token providers run on each request and may be async; synchronous providers should avoid blocking I/O. Do not log tokens or returned `access_token()` values.
240
+
241
+ Environment precedence: `OCTELIUM_ACCESS_TOKEN`, `OCTELIUM_ASSERTION_FILE`, `OCTELIUM_ASSERTION`, then `OCTELIUM_AUTH_TOKEN` (or `OCTELIUM_AUTHENTICATION_TOKEN`). Domain precedence is explicit argument, `CORDIUM_DOMAIN`, then `OCTELIUM_DOMAIN`.
242
+
243
+ ```python
244
+ response = client.request("GET", workspace.app_url("api") + "/health")
245
+ response.raise_for_status()
246
+ print(response.json())
247
+ ```
248
+
249
+ `request()` attaches the current token only to HTTPS Cluster-domain/subdomain destinations or `authorized_http_hosts`. It supports underscore application routes. Redirects are returned without following. Userinfo and unauthorized destinations are rejected before authentication/network I/O. HTTP non-success statuses are returned for caller handling. Responses are buffered up to `max_response_bytes` (16 MiB default); deadlines include authentication and full-body reads. `allow_insecure_http=True` and `tls=False` explicitly enable insecure local testing. `host=`, `port=`, and an `ssl.SSLContext` support custom deployments.
250
+
251
+ Timeouts are positive finite **seconds**, with `None` disabling the deadline. Unary operations default to 30 seconds, readiness/run waits to 300 seconds, and exec/event streams to no deadline. Composite operations use one total budget. Local disk completion may delay cancellation until an in-flight write finishes safely. No automatic retries are performed for resource operations or executions; this avoids duplicate side effects. Errors preserve gRPC status names in `CordiumError.code`; SDK codes include `CLIENT_CLOSED`, `PROTOCOL_ERROR`, `WORKSPACE_STOPPED`, `WORKSPACE_FAILED`, `BUILD_FAILED`, `SNAPSHOT_FAILED`, `VOLUME_FAILED`, and `COMMAND_FAILED`. Async caller cancellation remains `asyncio.CancelledError`.
252
+
253
+ ## Generated API escape hatch
254
+
255
+ ```python
256
+ from cordium import meta, proto
257
+
258
+ # Native async client, inside its owning event loop:
259
+ resource = await async_client.raw.main.get_workspace(
260
+ meta.GetOptions(name="abc"), timeout=10,
261
+ )
262
+
263
+ # Blocking client: callbacks run on its owned loop.
264
+ resource = client.call(
265
+ lambda c: c.raw.main.get_workspace(meta.GetOptions(name="abc"), timeout=10)
266
+ )
267
+ ```
268
+
269
+ `raw.main`, `raw.workspace`, and `raw.management` expose the generated stubs. Raw calls preserve native `grpclib` errors; callers own their deadlines and streaming cleanup. They share authentication with high-level methods. The async constructor accepts an already-authenticated `grpclib.Channel` or an `httpx.AsyncClient`; injected transports remain caller-owned. Token/HTTP helpers require SDK-managed credentials and cannot extract credentials from an injected gRPC channel.
270
+
271
+ See the [API reference](docs/api.md), [runnable examples](examples), and [development notes](docs/development.md). Every public method has a docstring available through `help()` and editor tooltips. Both packages carry PEP 561 typing markers.