canyonos-api-interface 1.0.1__tar.gz → 1.0.2__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.2}/PKG-INFO +5 -5
- {canyonos_api_interface-1.0.1 → canyonos_api_interface-1.0.2}/README.md +4 -4
- canyonos_api_interface-1.0.2/canyonos_api_interface/client.py +178 -0
- {canyonos_api_interface-1.0.1 → canyonos_api_interface-1.0.2}/canyonos_api_interface/models.py +29 -23
- {canyonos_api_interface-1.0.1 → canyonos_api_interface-1.0.2}/canyonos_api_interface.egg-info/PKG-INFO +5 -5
- {canyonos_api_interface-1.0.1 → canyonos_api_interface-1.0.2}/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.2}/canyonos_api_interface/__init__.py +0 -0
- {canyonos_api_interface-1.0.1 → canyonos_api_interface-1.0.2}/canyonos_api_interface/py.typed +0 -0
- {canyonos_api_interface-1.0.1 → canyonos_api_interface-1.0.2}/canyonos_api_interface.egg-info/SOURCES.txt +0 -0
- {canyonos_api_interface-1.0.1 → canyonos_api_interface-1.0.2}/canyonos_api_interface.egg-info/dependency_links.txt +0 -0
- {canyonos_api_interface-1.0.1 → canyonos_api_interface-1.0.2}/canyonos_api_interface.egg-info/requires.txt +0 -0
- {canyonos_api_interface-1.0.1 → canyonos_api_interface-1.0.2}/canyonos_api_interface.egg-info/top_level.txt +0 -0
- {canyonos_api_interface-1.0.1 → canyonos_api_interface-1.0.2}/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.2
|
|
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.2}/canyonos_api_interface/models.py
RENAMED
|
@@ -10,7 +10,8 @@ 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")
|
|
@@ -19,12 +20,12 @@ class Error(BaseModel):
|
|
|
19
20
|
warnings: list[str] | None = Field(None, title="Warnings")
|
|
20
21
|
|
|
21
22
|
|
|
22
|
-
class
|
|
23
|
+
class WorkflowGroup(BaseModel):
|
|
23
24
|
"""
|
|
24
|
-
`name` is what the
|
|
25
|
+
`name` is what the workflow group's `PUT` last sent, empty before one.
|
|
25
26
|
"""
|
|
26
27
|
|
|
27
|
-
|
|
28
|
+
workflow_group_id: str = Field(..., title="Workflow Group Id")
|
|
28
29
|
name: str = Field(..., title="Name")
|
|
29
30
|
|
|
30
31
|
|
|
@@ -37,19 +38,19 @@ class Uploaded(BaseModel):
|
|
|
37
38
|
warnings: list[str] = Field(..., title="Warnings")
|
|
38
39
|
|
|
39
40
|
|
|
40
|
-
class
|
|
41
|
+
class WorkflowGroupBody(BaseModel):
|
|
41
42
|
"""
|
|
42
|
-
`config` is `
|
|
43
|
-
none. `
|
|
44
|
-
|
|
45
|
-
deploy's API key, "" for none, used only on Kubernetes, where a
|
|
46
|
-
deploy.
|
|
43
|
+
`config` is `workflow_group.yaml`'s text and `env` the `.env` beside it, null for
|
|
44
|
+
none. `workflows`, when given, is every workflow the workflow group has; the
|
|
45
|
+
uploaded workflows it leaves out are removed. `api_key_hash`, when given, is the
|
|
46
|
+
SHA-256 of the deploy's API key, "" for none, used only on Kubernetes, where a
|
|
47
|
+
change restarts the deploy.
|
|
47
48
|
"""
|
|
48
49
|
|
|
49
50
|
name: str = Field(..., title="Name")
|
|
50
51
|
config: str = Field(..., title="Config")
|
|
51
52
|
env: str | None = Field(..., title="Env")
|
|
52
|
-
|
|
53
|
+
workflows: list[str] | None = Field(None, title="Workflows")
|
|
53
54
|
api_key_hash: str | None = Field(None, title="Api Key Hash")
|
|
54
55
|
|
|
55
56
|
|
|
@@ -87,7 +88,8 @@ class LastApply(BaseModel):
|
|
|
87
88
|
|
|
88
89
|
|
|
89
90
|
class Route(BaseModel):
|
|
90
|
-
|
|
91
|
+
workflow: str = Field(..., title="Workflow")
|
|
92
|
+
workflow_id: str | None = Field(..., title="Workflow Id")
|
|
91
93
|
agent: str = Field(..., title="Agent")
|
|
92
94
|
method: str = Field(..., title="Method")
|
|
93
95
|
arguments: list[str] = Field(..., title="Arguments")
|
|
@@ -108,7 +110,7 @@ class Check(BaseModel):
|
|
|
108
110
|
|
|
109
111
|
class Fingerprints(BaseModel):
|
|
110
112
|
"""
|
|
111
|
-
Digests over a
|
|
113
|
+
Digests over a workflow's uploaded files: `config` over its `config/` files and
|
|
112
114
|
`.env`, which a reload applies, and `code` over the rest.
|
|
113
115
|
"""
|
|
114
116
|
|
|
@@ -116,7 +118,7 @@ class Fingerprints(BaseModel):
|
|
|
116
118
|
config: str = Field(..., title="Config")
|
|
117
119
|
|
|
118
120
|
|
|
119
|
-
class
|
|
121
|
+
class Workflow(BaseModel):
|
|
120
122
|
"""
|
|
121
123
|
`test_query` is its `config/test_query.txt`, null when it has none.
|
|
122
124
|
"""
|
|
@@ -130,8 +132,8 @@ class ReplicaLogs(BaseModel):
|
|
|
130
132
|
logs: dict[str, list[str]] = Field(..., title="Logs")
|
|
131
133
|
|
|
132
134
|
|
|
133
|
-
class
|
|
134
|
-
|
|
135
|
+
class DashboardWorkflow(BaseModel):
|
|
136
|
+
workflow_id: str = Field(..., title="Workflow Id")
|
|
135
137
|
name: str = Field(..., title="Name")
|
|
136
138
|
|
|
137
139
|
|
|
@@ -143,8 +145,8 @@ class DashboardBody(BaseModel):
|
|
|
143
145
|
url: str = Field(..., title="Url")
|
|
144
146
|
|
|
145
147
|
|
|
146
|
-
class
|
|
147
|
-
|
|
148
|
+
class WorkflowGroups(BaseModel):
|
|
149
|
+
workflow_groups: list[WorkflowGroup] = Field(..., title="Workflow Groups")
|
|
148
150
|
|
|
149
151
|
|
|
150
152
|
class Endpoint(BaseModel):
|
|
@@ -158,15 +160,19 @@ class Health(BaseModel):
|
|
|
158
160
|
checks: list[Check] = Field(..., title="Checks")
|
|
159
161
|
|
|
160
162
|
|
|
161
|
-
class
|
|
162
|
-
|
|
163
|
+
class Workflows(BaseModel):
|
|
164
|
+
workflows: list[Workflow] = Field(..., title="Workflows")
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
class DashboardWorkflows(BaseModel):
|
|
168
|
+
workflows: list[DashboardWorkflow] = Field(..., title="Workflows")
|
|
163
169
|
|
|
164
170
|
|
|
165
171
|
class Status(BaseModel):
|
|
166
172
|
"""
|
|
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.
|
|
173
|
+
`name` and `config` are what the workflow group's `PUT` last sent, without the
|
|
174
|
+
`.env`; `running` is whether the deploy process is alive, so a failed deploy can
|
|
175
|
+
still be running while it stops itself.
|
|
170
176
|
"""
|
|
171
177
|
|
|
172
178
|
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.2
|
|
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.2"
|
|
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.2}/canyonos_api_interface/__init__.py
RENAMED
|
File without changes
|
{canyonos_api_interface-1.0.1 → canyonos_api_interface-1.0.2}/canyonos_api_interface/py.typed
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|