canyonos-api-interface 1.0.1__tar.gz → 1.0.3__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.
- {canyonos_api_interface-1.0.1 → canyonos_api_interface-1.0.3}/PKG-INFO +5 -5
- {canyonos_api_interface-1.0.1 → canyonos_api_interface-1.0.3}/README.md +4 -4
- canyonos_api_interface-1.0.3/canyonos_api_interface/client.py +178 -0
- {canyonos_api_interface-1.0.1 → canyonos_api_interface-1.0.3}/canyonos_api_interface/models.py +45 -24
- {canyonos_api_interface-1.0.1 → canyonos_api_interface-1.0.3}/canyonos_api_interface.egg-info/PKG-INFO +5 -5
- {canyonos_api_interface-1.0.1 → canyonos_api_interface-1.0.3}/pyproject.toml +1 -1
- canyonos_api_interface-1.0.1/canyonos_api_interface/client.py +0 -161
- {canyonos_api_interface-1.0.1 → canyonos_api_interface-1.0.3}/canyonos_api_interface/__init__.py +0 -0
- {canyonos_api_interface-1.0.1 → canyonos_api_interface-1.0.3}/canyonos_api_interface/py.typed +0 -0
- {canyonos_api_interface-1.0.1 → canyonos_api_interface-1.0.3}/canyonos_api_interface.egg-info/SOURCES.txt +0 -0
- {canyonos_api_interface-1.0.1 → canyonos_api_interface-1.0.3}/canyonos_api_interface.egg-info/dependency_links.txt +0 -0
- {canyonos_api_interface-1.0.1 → canyonos_api_interface-1.0.3}/canyonos_api_interface.egg-info/requires.txt +0 -0
- {canyonos_api_interface-1.0.1 → canyonos_api_interface-1.0.3}/canyonos_api_interface.egg-info/top_level.txt +0 -0
- {canyonos_api_interface-1.0.1 → canyonos_api_interface-1.0.3}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: canyonos-api-interface
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.3
|
|
4
4
|
Summary: Typed client for the CanyonOS REST API
|
|
5
5
|
License-Expression: AGPL-3.0-only
|
|
6
6
|
Project-URL: Homepage, https://canyonos.ai
|
|
@@ -13,7 +13,7 @@ Requires-Dist: pydantic>=2.4
|
|
|
13
13
|
|
|
14
14
|
Typed clients for the CanyonOS REST API (`/v1`), for TypeScript and Python.
|
|
15
15
|
|
|
16
|
-
A deploy's address and headers are in `~/.canyonos/deployments/<
|
|
16
|
+
A deploy's address and headers are in `~/.canyonos/deployments/<workflow group>/state.json`: the API is on `http://127.0.0.1:<port>`, and every request sends its `headers`.
|
|
17
17
|
|
|
18
18
|
## TypeScript
|
|
19
19
|
|
|
@@ -25,8 +25,8 @@ npm install @canyoncode/canyonos-api-interface
|
|
|
25
25
|
import { createClient } from '@canyoncode/canyonos-api-interface';
|
|
26
26
|
|
|
27
27
|
const api = createClient('http://127.0.0.1:8000', { Authorization: 'Bearer <secret>' });
|
|
28
|
-
const { data, error } = await api.GET('/v1/
|
|
29
|
-
params: { path: {
|
|
28
|
+
const { data, error } = await api.GET('/v1/workflow-groups/{workflow_group_id}', {
|
|
29
|
+
params: { path: { workflow_group_id: '<workflow_group_id>' } },
|
|
30
30
|
});
|
|
31
31
|
```
|
|
32
32
|
|
|
@@ -40,7 +40,7 @@ pip install canyonos-api-interface
|
|
|
40
40
|
from canyonos_api_interface.client import Client
|
|
41
41
|
|
|
42
42
|
api = Client("http://127.0.0.1:8000", {"Authorization": "Bearer <secret>"})
|
|
43
|
-
status = api.status("<
|
|
43
|
+
status = api.status("<workflow_group_id>")
|
|
44
44
|
print(status.phase)
|
|
45
45
|
```
|
|
46
46
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Typed clients for the CanyonOS REST API (`/v1`), for TypeScript and Python.
|
|
4
4
|
|
|
5
|
-
A deploy's address and headers are in `~/.canyonos/deployments/<
|
|
5
|
+
A deploy's address and headers are in `~/.canyonos/deployments/<workflow group>/state.json`: the API is on `http://127.0.0.1:<port>`, and every request sends its `headers`.
|
|
6
6
|
|
|
7
7
|
## TypeScript
|
|
8
8
|
|
|
@@ -14,8 +14,8 @@ npm install @canyoncode/canyonos-api-interface
|
|
|
14
14
|
import { createClient } from '@canyoncode/canyonos-api-interface';
|
|
15
15
|
|
|
16
16
|
const api = createClient('http://127.0.0.1:8000', { Authorization: 'Bearer <secret>' });
|
|
17
|
-
const { data, error } = await api.GET('/v1/
|
|
18
|
-
params: { path: {
|
|
17
|
+
const { data, error } = await api.GET('/v1/workflow-groups/{workflow_group_id}', {
|
|
18
|
+
params: { path: { workflow_group_id: '<workflow_group_id>' } },
|
|
19
19
|
});
|
|
20
20
|
```
|
|
21
21
|
|
|
@@ -29,7 +29,7 @@ pip install canyonos-api-interface
|
|
|
29
29
|
from canyonos_api_interface.client import Client
|
|
30
30
|
|
|
31
31
|
api = Client("http://127.0.0.1:8000", {"Authorization": "Bearer <secret>"})
|
|
32
|
-
status = api.status("<
|
|
32
|
+
status = api.status("<workflow_group_id>")
|
|
33
33
|
print(status.phase)
|
|
34
34
|
```
|
|
35
35
|
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 Canyon Code, Inc.
|
|
2
|
+
# SPDX-License-Identifier: AGPL-3.0-only
|
|
3
|
+
|
|
4
|
+
"""Calls each CanyonOS API route with the standard library and returns its answer as
|
|
5
|
+
the matching model from `models`."""
|
|
6
|
+
|
|
7
|
+
import os
|
|
8
|
+
import urllib.request
|
|
9
|
+
from collections.abc import Iterator
|
|
10
|
+
from typing import BinaryIO, TypeVar
|
|
11
|
+
from urllib.parse import quote, urlencode
|
|
12
|
+
|
|
13
|
+
from pydantic import BaseModel
|
|
14
|
+
|
|
15
|
+
from canyonos_api_interface.models import (
|
|
16
|
+
DashboardBody,
|
|
17
|
+
DashboardWorkflows,
|
|
18
|
+
Generation,
|
|
19
|
+
Health,
|
|
20
|
+
ReplicaLogs,
|
|
21
|
+
Status,
|
|
22
|
+
Uploaded,
|
|
23
|
+
Workflow,
|
|
24
|
+
WorkflowGroupBody,
|
|
25
|
+
WorkflowGroups,
|
|
26
|
+
Workflows,
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
Answer = TypeVar("Answer", bound=BaseModel)
|
|
30
|
+
JSON = {"Content-Type": "application/json"}
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class Client:
|
|
34
|
+
"""Calls the API at `base_url`, such as `http://127.0.0.1:8000`, sending `headers`
|
|
35
|
+
with every request and waiting up to `timeout` seconds (None: no limit). An error
|
|
36
|
+
answer raises urllib's `HTTPError`, its body an `Error`; an answer that isn't its
|
|
37
|
+
route's model raises pydantic's `ValidationError`."""
|
|
38
|
+
|
|
39
|
+
def __init__(
|
|
40
|
+
self,
|
|
41
|
+
base_url: str,
|
|
42
|
+
headers: dict[str, str] | None = None,
|
|
43
|
+
timeout: float | None = 60,
|
|
44
|
+
):
|
|
45
|
+
self.base_url = base_url
|
|
46
|
+
self.headers = headers or {}
|
|
47
|
+
self.timeout = timeout
|
|
48
|
+
|
|
49
|
+
def _open(self, method, path, data=None, headers=None):
|
|
50
|
+
"""Send `method` to `path` with body `data` and return the open response."""
|
|
51
|
+
request = urllib.request.Request(
|
|
52
|
+
self.base_url + path,
|
|
53
|
+
data=data,
|
|
54
|
+
headers={**self.headers, **(headers or {})},
|
|
55
|
+
method=method,
|
|
56
|
+
)
|
|
57
|
+
return urllib.request.urlopen(request, timeout=self.timeout)
|
|
58
|
+
|
|
59
|
+
def _call(
|
|
60
|
+
self, answer: type[Answer], method, path, data=None, headers=None
|
|
61
|
+
) -> Answer:
|
|
62
|
+
"""Send `method` to `path` with body `data` and return the answer as `answer`."""
|
|
63
|
+
with self._open(method, path, data, headers) as response:
|
|
64
|
+
return answer.model_validate_json(response.read())
|
|
65
|
+
|
|
66
|
+
def list_workflow_groups(self) -> WorkflowGroups:
|
|
67
|
+
"""GET /v1/workflow-groups: the workflow groups the server holds."""
|
|
68
|
+
return self._call(WorkflowGroups, "GET", "/v1/workflow-groups")
|
|
69
|
+
|
|
70
|
+
def status(self, workflow_group_id: str) -> Status:
|
|
71
|
+
"""GET /v1/workflow-groups/{workflow_group_id}: the workflow group's status."""
|
|
72
|
+
return self._call(Status, "GET", f"/v1/workflow-groups/{workflow_group_id}")
|
|
73
|
+
|
|
74
|
+
def put_workflow_group(
|
|
75
|
+
self, workflow_group_id: str, body: WorkflowGroupBody
|
|
76
|
+
) -> Uploaded:
|
|
77
|
+
"""PUT /v1/workflow-groups/{workflow_group_id}: upload workflow_group.yaml and
|
|
78
|
+
its .env."""
|
|
79
|
+
return self._call(
|
|
80
|
+
Uploaded,
|
|
81
|
+
"PUT",
|
|
82
|
+
f"/v1/workflow-groups/{workflow_group_id}",
|
|
83
|
+
body.model_dump_json().encode(),
|
|
84
|
+
JSON,
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
def delete_workflow_group(self, workflow_group_id: str) -> Generation:
|
|
88
|
+
"""DELETE /v1/workflow-groups/{workflow_group_id}: stop the deploy and remove
|
|
89
|
+
the upload."""
|
|
90
|
+
return self._call(
|
|
91
|
+
Generation, "DELETE", f"/v1/workflow-groups/{workflow_group_id}"
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
def list_workflows(self, workflow_group_id: str) -> Workflows:
|
|
95
|
+
"""GET /v1/workflow-groups/{workflow_group_id}/workflows: the uploaded
|
|
96
|
+
workflows."""
|
|
97
|
+
return self._call(
|
|
98
|
+
Workflows, "GET", f"/v1/workflow-groups/{workflow_group_id}/workflows"
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
def get_workflow(self, workflow_group_id: str, name: str) -> Workflow:
|
|
102
|
+
"""GET /v1/workflow-groups/{workflow_group_id}/workflows/{name}: one uploaded
|
|
103
|
+
workflow."""
|
|
104
|
+
return self._call(
|
|
105
|
+
Workflow,
|
|
106
|
+
"GET",
|
|
107
|
+
f"/v1/workflow-groups/{workflow_group_id}/workflows/{quote(name)}",
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
def put_workflow(
|
|
111
|
+
self, workflow_group_id: str, name: str, archive: BinaryIO
|
|
112
|
+
) -> Uploaded:
|
|
113
|
+
"""PUT /v1/workflow-groups/{workflow_group_id}/workflows/{name}: upload
|
|
114
|
+
`archive`, an open gzip tar file of the workflow's folder."""
|
|
115
|
+
return self._call(
|
|
116
|
+
Uploaded,
|
|
117
|
+
"PUT",
|
|
118
|
+
f"/v1/workflow-groups/{workflow_group_id}/workflows/{quote(name)}",
|
|
119
|
+
archive,
|
|
120
|
+
# Without a length, urllib sends a file chunked.
|
|
121
|
+
{
|
|
122
|
+
"Content-Type": "application/gzip",
|
|
123
|
+
"Content-Length": str(os.fstat(archive.fileno()).st_size),
|
|
124
|
+
},
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
def delete_workflow(self, workflow_group_id: str, name: str) -> Generation:
|
|
128
|
+
"""DELETE /v1/workflow-groups/{workflow_group_id}/workflows/{name}: remove a
|
|
129
|
+
workflow."""
|
|
130
|
+
return self._call(
|
|
131
|
+
Generation,
|
|
132
|
+
"DELETE",
|
|
133
|
+
f"/v1/workflow-groups/{workflow_group_id}/workflows/{quote(name)}",
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
def controller_log(
|
|
137
|
+
self, workflow_group_id: str, tail: str | int = "all", follow: bool = False
|
|
138
|
+
) -> Iterator[str]:
|
|
139
|
+
"""GET /v1/workflow-groups/{workflow_group_id}/logs/controller: yield the deploy
|
|
140
|
+
process's last `tail` lines, then with `follow` each new one until it exits."""
|
|
141
|
+
query = urlencode({"tail": tail, "follow": str(follow).lower()})
|
|
142
|
+
with self._open(
|
|
143
|
+
"GET", f"/v1/workflow-groups/{workflow_group_id}/logs/controller?{query}"
|
|
144
|
+
) as response:
|
|
145
|
+
for line in response:
|
|
146
|
+
yield line.decode(errors="replace")
|
|
147
|
+
|
|
148
|
+
def health(self, workflow_group_id: str) -> Health:
|
|
149
|
+
"""GET /v1/workflow-groups/{workflow_group_id}/health: check the running
|
|
150
|
+
deploy."""
|
|
151
|
+
return self._call(
|
|
152
|
+
Health, "GET", f"/v1/workflow-groups/{workflow_group_id}/health"
|
|
153
|
+
)
|
|
154
|
+
|
|
155
|
+
def agent_logs(
|
|
156
|
+
self, workflow_group_id: str, name: str, tail: str | int = "all"
|
|
157
|
+
) -> ReplicaLogs:
|
|
158
|
+
"""GET /v1/workflow-groups/{workflow_group_id}/logs/agents/{name}: the last
|
|
159
|
+
`tail` lines of each replica of agent `name`, or of the replica with that ID."""
|
|
160
|
+
return self._call(
|
|
161
|
+
ReplicaLogs,
|
|
162
|
+
"GET",
|
|
163
|
+
f"/v1/workflow-groups/{workflow_group_id}/logs/agents/{quote(name)}"
|
|
164
|
+
f"?{urlencode({'tail': tail})}",
|
|
165
|
+
)
|
|
166
|
+
|
|
167
|
+
def put_dashboard(
|
|
168
|
+
self, workflow_group_id: str, body: DashboardBody
|
|
169
|
+
) -> DashboardWorkflows:
|
|
170
|
+
"""PUT /v1/workflow-groups/{workflow_group_id}/dashboard: register the workflow
|
|
171
|
+
group's Redis with the dashboard api at `body.url`."""
|
|
172
|
+
return self._call(
|
|
173
|
+
DashboardWorkflows,
|
|
174
|
+
"PUT",
|
|
175
|
+
f"/v1/workflow-groups/{workflow_group_id}/dashboard",
|
|
176
|
+
body.model_dump_json().encode(),
|
|
177
|
+
JSON,
|
|
178
|
+
)
|
{canyonos_api_interface-1.0.1 → canyonos_api_interface-1.0.3}/canyonos_api_interface/models.py
RENAMED
|
@@ -10,21 +10,37 @@ from pydantic import BaseModel, Field
|
|
|
10
10
|
|
|
11
11
|
class Error(BaseModel):
|
|
12
12
|
"""
|
|
13
|
-
Every error answer; `findings` and `warnings` only come with
|
|
13
|
+
Every error answer; `findings` and `warnings` only come with
|
|
14
|
+
`workflow_invalid`.
|
|
14
15
|
"""
|
|
15
16
|
|
|
16
17
|
error: str = Field(..., title="Error")
|
|
17
|
-
code:
|
|
18
|
+
code: Literal[
|
|
19
|
+
"bad_request",
|
|
20
|
+
"bad_archive",
|
|
21
|
+
"workflow_invalid",
|
|
22
|
+
"unauthenticated",
|
|
23
|
+
"forbidden",
|
|
24
|
+
"unknown_workflow_group",
|
|
25
|
+
"unknown_workflow",
|
|
26
|
+
"unknown_agent",
|
|
27
|
+
"not_running",
|
|
28
|
+
"replicas_unreadable",
|
|
29
|
+
"stop_timeout",
|
|
30
|
+
"stop_failed",
|
|
31
|
+
"dashboard_unreachable",
|
|
32
|
+
"dashboard_refused",
|
|
33
|
+
] = Field(..., title="Code")
|
|
18
34
|
findings: list[str] | None = Field(None, title="Findings")
|
|
19
35
|
warnings: list[str] | None = Field(None, title="Warnings")
|
|
20
36
|
|
|
21
37
|
|
|
22
|
-
class
|
|
38
|
+
class WorkflowGroup(BaseModel):
|
|
23
39
|
"""
|
|
24
|
-
`name` is what the
|
|
40
|
+
`name` is what the workflow group's `PUT` last sent, empty before one.
|
|
25
41
|
"""
|
|
26
42
|
|
|
27
|
-
|
|
43
|
+
workflow_group_id: str = Field(..., title="Workflow Group Id")
|
|
28
44
|
name: str = Field(..., title="Name")
|
|
29
45
|
|
|
30
46
|
|
|
@@ -37,19 +53,19 @@ class Uploaded(BaseModel):
|
|
|
37
53
|
warnings: list[str] = Field(..., title="Warnings")
|
|
38
54
|
|
|
39
55
|
|
|
40
|
-
class
|
|
56
|
+
class WorkflowGroupBody(BaseModel):
|
|
41
57
|
"""
|
|
42
|
-
`config` is `
|
|
43
|
-
none. `
|
|
44
|
-
|
|
45
|
-
deploy's API key, "" for none, used only on Kubernetes, where a
|
|
46
|
-
deploy.
|
|
58
|
+
`config` is `workflow_group.yaml`'s text and `env` the `.env` beside it, null for
|
|
59
|
+
none. `workflows`, when given, is every workflow the workflow group has; the
|
|
60
|
+
uploaded workflows it leaves out are removed. `api_key_hash`, when given, is the
|
|
61
|
+
SHA-256 of the deploy's API key, "" for none, used only on Kubernetes, where a
|
|
62
|
+
change restarts the deploy.
|
|
47
63
|
"""
|
|
48
64
|
|
|
49
65
|
name: str = Field(..., title="Name")
|
|
50
66
|
config: str = Field(..., title="Config")
|
|
51
67
|
env: str | None = Field(..., title="Env")
|
|
52
|
-
|
|
68
|
+
workflows: list[str] | None = Field(None, title="Workflows")
|
|
53
69
|
api_key_hash: str | None = Field(None, title="Api Key Hash")
|
|
54
70
|
|
|
55
71
|
|
|
@@ -87,7 +103,8 @@ class LastApply(BaseModel):
|
|
|
87
103
|
|
|
88
104
|
|
|
89
105
|
class Route(BaseModel):
|
|
90
|
-
|
|
106
|
+
workflow: str = Field(..., title="Workflow")
|
|
107
|
+
workflow_id: str | None = Field(..., title="Workflow Id")
|
|
91
108
|
agent: str = Field(..., title="Agent")
|
|
92
109
|
method: str = Field(..., title="Method")
|
|
93
110
|
arguments: list[str] = Field(..., title="Arguments")
|
|
@@ -108,7 +125,7 @@ class Check(BaseModel):
|
|
|
108
125
|
|
|
109
126
|
class Fingerprints(BaseModel):
|
|
110
127
|
"""
|
|
111
|
-
Digests over a
|
|
128
|
+
Digests over a workflow's uploaded files: `config` over its `config/` files and
|
|
112
129
|
`.env`, which a reload applies, and `code` over the rest.
|
|
113
130
|
"""
|
|
114
131
|
|
|
@@ -116,7 +133,7 @@ class Fingerprints(BaseModel):
|
|
|
116
133
|
config: str = Field(..., title="Config")
|
|
117
134
|
|
|
118
135
|
|
|
119
|
-
class
|
|
136
|
+
class Workflow(BaseModel):
|
|
120
137
|
"""
|
|
121
138
|
`test_query` is its `config/test_query.txt`, null when it has none.
|
|
122
139
|
"""
|
|
@@ -130,8 +147,8 @@ class ReplicaLogs(BaseModel):
|
|
|
130
147
|
logs: dict[str, list[str]] = Field(..., title="Logs")
|
|
131
148
|
|
|
132
149
|
|
|
133
|
-
class
|
|
134
|
-
|
|
150
|
+
class DashboardWorkflow(BaseModel):
|
|
151
|
+
workflow_id: str = Field(..., title="Workflow Id")
|
|
135
152
|
name: str = Field(..., title="Name")
|
|
136
153
|
|
|
137
154
|
|
|
@@ -143,8 +160,8 @@ class DashboardBody(BaseModel):
|
|
|
143
160
|
url: str = Field(..., title="Url")
|
|
144
161
|
|
|
145
162
|
|
|
146
|
-
class
|
|
147
|
-
|
|
163
|
+
class WorkflowGroups(BaseModel):
|
|
164
|
+
workflow_groups: list[WorkflowGroup] = Field(..., title="Workflow Groups")
|
|
148
165
|
|
|
149
166
|
|
|
150
167
|
class Endpoint(BaseModel):
|
|
@@ -158,15 +175,19 @@ class Health(BaseModel):
|
|
|
158
175
|
checks: list[Check] = Field(..., title="Checks")
|
|
159
176
|
|
|
160
177
|
|
|
161
|
-
class
|
|
162
|
-
|
|
178
|
+
class Workflows(BaseModel):
|
|
179
|
+
workflows: list[Workflow] = Field(..., title="Workflows")
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
class DashboardWorkflows(BaseModel):
|
|
183
|
+
workflows: list[DashboardWorkflow] = Field(..., title="Workflows")
|
|
163
184
|
|
|
164
185
|
|
|
165
186
|
class Status(BaseModel):
|
|
166
187
|
"""
|
|
167
|
-
`name` and `config` are what the
|
|
168
|
-
`running` is whether the deploy process is alive, so a failed deploy can
|
|
169
|
-
running while it stops itself.
|
|
188
|
+
`name` and `config` are what the workflow group's `PUT` last sent, without the
|
|
189
|
+
`.env`; `running` is whether the deploy process is alive, so a failed deploy can
|
|
190
|
+
still be running while it stops itself.
|
|
170
191
|
"""
|
|
171
192
|
|
|
172
193
|
version: str = Field(..., title="Version")
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: canyonos-api-interface
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.3
|
|
4
4
|
Summary: Typed client for the CanyonOS REST API
|
|
5
5
|
License-Expression: AGPL-3.0-only
|
|
6
6
|
Project-URL: Homepage, https://canyonos.ai
|
|
@@ -13,7 +13,7 @@ Requires-Dist: pydantic>=2.4
|
|
|
13
13
|
|
|
14
14
|
Typed clients for the CanyonOS REST API (`/v1`), for TypeScript and Python.
|
|
15
15
|
|
|
16
|
-
A deploy's address and headers are in `~/.canyonos/deployments/<
|
|
16
|
+
A deploy's address and headers are in `~/.canyonos/deployments/<workflow group>/state.json`: the API is on `http://127.0.0.1:<port>`, and every request sends its `headers`.
|
|
17
17
|
|
|
18
18
|
## TypeScript
|
|
19
19
|
|
|
@@ -25,8 +25,8 @@ npm install @canyoncode/canyonos-api-interface
|
|
|
25
25
|
import { createClient } from '@canyoncode/canyonos-api-interface';
|
|
26
26
|
|
|
27
27
|
const api = createClient('http://127.0.0.1:8000', { Authorization: 'Bearer <secret>' });
|
|
28
|
-
const { data, error } = await api.GET('/v1/
|
|
29
|
-
params: { path: {
|
|
28
|
+
const { data, error } = await api.GET('/v1/workflow-groups/{workflow_group_id}', {
|
|
29
|
+
params: { path: { workflow_group_id: '<workflow_group_id>' } },
|
|
30
30
|
});
|
|
31
31
|
```
|
|
32
32
|
|
|
@@ -40,7 +40,7 @@ pip install canyonos-api-interface
|
|
|
40
40
|
from canyonos_api_interface.client import Client
|
|
41
41
|
|
|
42
42
|
api = Client("http://127.0.0.1:8000", {"Authorization": "Bearer <secret>"})
|
|
43
|
-
status = api.status("<
|
|
43
|
+
status = api.status("<workflow_group_id>")
|
|
44
44
|
print(status.phase)
|
|
45
45
|
```
|
|
46
46
|
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
[project]
|
|
5
5
|
name = "canyonos-api-interface"
|
|
6
6
|
# The release workflow sets the patch from the commits that changed this folder.
|
|
7
|
-
version = "1.0.
|
|
7
|
+
version = "1.0.3"
|
|
8
8
|
description = "Typed client for the CanyonOS REST API"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = "AGPL-3.0-only"
|
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
# SPDX-FileCopyrightText: 2026 Canyon Code, Inc.
|
|
2
|
-
# SPDX-License-Identifier: AGPL-3.0-only
|
|
3
|
-
|
|
4
|
-
"""Calls each CanyonOS API route with the standard library and returns its answer as
|
|
5
|
-
the matching model from `models`."""
|
|
6
|
-
|
|
7
|
-
import os
|
|
8
|
-
import urllib.request
|
|
9
|
-
from collections.abc import Iterator
|
|
10
|
-
from typing import BinaryIO, TypeVar
|
|
11
|
-
from urllib.parse import quote, urlencode
|
|
12
|
-
|
|
13
|
-
from pydantic import BaseModel
|
|
14
|
-
|
|
15
|
-
from canyonos_api_interface.models import (
|
|
16
|
-
DashboardBody,
|
|
17
|
-
DashboardProject,
|
|
18
|
-
DeploymentBody,
|
|
19
|
-
Deployments,
|
|
20
|
-
Generation,
|
|
21
|
-
Health,
|
|
22
|
-
Project,
|
|
23
|
-
Projects,
|
|
24
|
-
ReplicaLogs,
|
|
25
|
-
Status,
|
|
26
|
-
Uploaded,
|
|
27
|
-
)
|
|
28
|
-
|
|
29
|
-
Answer = TypeVar("Answer", bound=BaseModel)
|
|
30
|
-
JSON = {"Content-Type": "application/json"}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
class Client:
|
|
34
|
-
"""Calls the API at `base_url`, such as `http://127.0.0.1:8000`, sending `headers`
|
|
35
|
-
with every request and waiting up to `timeout` seconds (None: no limit). An error
|
|
36
|
-
answer raises urllib's `HTTPError`, its body an `Error`; an answer that isn't its
|
|
37
|
-
route's model raises pydantic's `ValidationError`."""
|
|
38
|
-
|
|
39
|
-
def __init__(
|
|
40
|
-
self,
|
|
41
|
-
base_url: str,
|
|
42
|
-
headers: dict[str, str] | None = None,
|
|
43
|
-
timeout: float | None = 60,
|
|
44
|
-
):
|
|
45
|
-
self.base_url = base_url
|
|
46
|
-
self.headers = headers or {}
|
|
47
|
-
self.timeout = timeout
|
|
48
|
-
|
|
49
|
-
def _open(self, method, path, data=None, headers=None):
|
|
50
|
-
"""Send `method` to `path` with body `data` and return the open response."""
|
|
51
|
-
request = urllib.request.Request(
|
|
52
|
-
self.base_url + path,
|
|
53
|
-
data=data,
|
|
54
|
-
headers={**self.headers, **(headers or {})},
|
|
55
|
-
method=method,
|
|
56
|
-
)
|
|
57
|
-
return urllib.request.urlopen(request, timeout=self.timeout)
|
|
58
|
-
|
|
59
|
-
def _call(
|
|
60
|
-
self, answer: type[Answer], method, path, data=None, headers=None
|
|
61
|
-
) -> Answer:
|
|
62
|
-
"""Send `method` to `path` with body `data` and return the answer as `answer`."""
|
|
63
|
-
with self._open(method, path, data, headers) as response:
|
|
64
|
-
return answer.model_validate_json(response.read())
|
|
65
|
-
|
|
66
|
-
def list_deployments(self) -> Deployments:
|
|
67
|
-
"""GET /v1/deployments: the deployments the server holds."""
|
|
68
|
-
return self._call(Deployments, "GET", "/v1/deployments")
|
|
69
|
-
|
|
70
|
-
def status(self, deployment_id: str) -> Status:
|
|
71
|
-
"""GET /v1/deployments/{deployment_id}: the deployment's status."""
|
|
72
|
-
return self._call(Status, "GET", f"/v1/deployments/{deployment_id}")
|
|
73
|
-
|
|
74
|
-
def put_deployment(self, deployment_id: str, body: DeploymentBody) -> Uploaded:
|
|
75
|
-
"""PUT /v1/deployments/{deployment_id}: upload deployment.yaml and its .env."""
|
|
76
|
-
return self._call(
|
|
77
|
-
Uploaded,
|
|
78
|
-
"PUT",
|
|
79
|
-
f"/v1/deployments/{deployment_id}",
|
|
80
|
-
body.model_dump_json().encode(),
|
|
81
|
-
JSON,
|
|
82
|
-
)
|
|
83
|
-
|
|
84
|
-
def delete_deployment(self, deployment_id: str) -> Generation:
|
|
85
|
-
"""DELETE /v1/deployments/{deployment_id}: stop the deploy and remove the
|
|
86
|
-
upload."""
|
|
87
|
-
return self._call(Generation, "DELETE", f"/v1/deployments/{deployment_id}")
|
|
88
|
-
|
|
89
|
-
def list_projects(self, deployment_id: str) -> Projects:
|
|
90
|
-
"""GET /v1/deployments/{deployment_id}/projects: the uploaded projects."""
|
|
91
|
-
return self._call(Projects, "GET", f"/v1/deployments/{deployment_id}/projects")
|
|
92
|
-
|
|
93
|
-
def get_project(self, deployment_id: str, name: str) -> Project:
|
|
94
|
-
"""GET /v1/deployments/{deployment_id}/projects/{name}: one uploaded project."""
|
|
95
|
-
return self._call(
|
|
96
|
-
Project, "GET", f"/v1/deployments/{deployment_id}/projects/{quote(name)}"
|
|
97
|
-
)
|
|
98
|
-
|
|
99
|
-
def put_project(self, deployment_id: str, name: str, archive: BinaryIO) -> Uploaded:
|
|
100
|
-
"""PUT /v1/deployments/{deployment_id}/projects/{name}: upload `archive`, an
|
|
101
|
-
open gzip tar file of the project's folder."""
|
|
102
|
-
return self._call(
|
|
103
|
-
Uploaded,
|
|
104
|
-
"PUT",
|
|
105
|
-
f"/v1/deployments/{deployment_id}/projects/{quote(name)}",
|
|
106
|
-
archive,
|
|
107
|
-
# Without a length, urllib sends a file chunked.
|
|
108
|
-
{
|
|
109
|
-
"Content-Type": "application/gzip",
|
|
110
|
-
"Content-Length": str(os.fstat(archive.fileno()).st_size),
|
|
111
|
-
},
|
|
112
|
-
)
|
|
113
|
-
|
|
114
|
-
def delete_project(self, deployment_id: str, name: str) -> Generation:
|
|
115
|
-
"""DELETE /v1/deployments/{deployment_id}/projects/{name}: remove a project."""
|
|
116
|
-
return self._call(
|
|
117
|
-
Generation,
|
|
118
|
-
"DELETE",
|
|
119
|
-
f"/v1/deployments/{deployment_id}/projects/{quote(name)}",
|
|
120
|
-
)
|
|
121
|
-
|
|
122
|
-
def controller_log(
|
|
123
|
-
self, deployment_id: str, tail: str | int = "all", follow: bool = False
|
|
124
|
-
) -> Iterator[str]:
|
|
125
|
-
"""GET /v1/deployments/{deployment_id}/logs/controller: yield the deploy
|
|
126
|
-
process's last `tail` lines, then with `follow` each new one until it exits."""
|
|
127
|
-
query = urlencode({"tail": tail, "follow": str(follow).lower()})
|
|
128
|
-
with self._open(
|
|
129
|
-
"GET", f"/v1/deployments/{deployment_id}/logs/controller?{query}"
|
|
130
|
-
) as response:
|
|
131
|
-
for line in response:
|
|
132
|
-
yield line.decode(errors="replace")
|
|
133
|
-
|
|
134
|
-
def health(self, deployment_id: str) -> Health:
|
|
135
|
-
"""GET /v1/deployments/{deployment_id}/health: check the running deploy."""
|
|
136
|
-
return self._call(Health, "GET", f"/v1/deployments/{deployment_id}/health")
|
|
137
|
-
|
|
138
|
-
def agent_logs(
|
|
139
|
-
self, deployment_id: str, name: str, tail: str | int = "all"
|
|
140
|
-
) -> ReplicaLogs:
|
|
141
|
-
"""GET /v1/deployments/{deployment_id}/logs/agents/{name}: the last `tail`
|
|
142
|
-
lines of each replica of agent `name`, or of the replica with that ID."""
|
|
143
|
-
return self._call(
|
|
144
|
-
ReplicaLogs,
|
|
145
|
-
"GET",
|
|
146
|
-
f"/v1/deployments/{deployment_id}/logs/agents/{quote(name)}"
|
|
147
|
-
f"?{urlencode({'tail': tail})}",
|
|
148
|
-
)
|
|
149
|
-
|
|
150
|
-
def put_dashboard(
|
|
151
|
-
self, deployment_id: str, body: DashboardBody
|
|
152
|
-
) -> DashboardProject:
|
|
153
|
-
"""PUT /v1/deployments/{deployment_id}/dashboard: register the deployment's
|
|
154
|
-
Redis with the dashboard api at `body.url`."""
|
|
155
|
-
return self._call(
|
|
156
|
-
DashboardProject,
|
|
157
|
-
"PUT",
|
|
158
|
-
f"/v1/deployments/{deployment_id}/dashboard",
|
|
159
|
-
body.model_dump_json().encode(),
|
|
160
|
-
JSON,
|
|
161
|
-
)
|
{canyonos_api_interface-1.0.1 → canyonos_api_interface-1.0.3}/canyonos_api_interface/__init__.py
RENAMED
|
File without changes
|
{canyonos_api_interface-1.0.1 → canyonos_api_interface-1.0.3}/canyonos_api_interface/py.typed
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|