shako-sdk 0.1.0__py3-none-any.whl

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.
shako_sdk/__init__.py ADDED
@@ -0,0 +1,7 @@
1
+ """The Shako API for Python (https://shako.dev/api): shako.vms, shako.ports, shako.secrets, ..., with an API key."""
2
+
3
+ from . import types
4
+ from ._client import Shako, ShakoError
5
+ from ._version import __version__
6
+
7
+ __all__ = ["Shako", "ShakoError", "__version__", "types"]
shako_sdk/_base.py ADDED
@@ -0,0 +1,22 @@
1
+ """The base of each resource of the API (_resources.py)."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Any, Dict, Optional, Protocol
6
+
7
+
8
+ class Client(Protocol):
9
+ def request(self, method: str, path: str, params: Optional[Dict[str, Any]] = None,
10
+ fields: Optional[Dict[str, Any]] = None, tenant: Optional[str] = None) -> Any: ...
11
+
12
+
13
+ class Resource:
14
+ """A resource of the API. Each method sends the request of its endpoint through the client."""
15
+
16
+ def __init__(self, client: Client) -> None:
17
+ self._client = client
18
+
19
+ def _call(self, method: str, path: str, params: Dict[str, Any], fields: Optional[Dict[str, Any]],
20
+ tenant: Optional[str], data: bool = False) -> Any:
21
+ answer = self._client.request(method, path, params, fields, tenant)
22
+ return answer["data"] if data else answer
shako_sdk/_client.py ADDED
@@ -0,0 +1,118 @@
1
+ """The client: each method of a resource is one HTTPS request of the REST API (https://shako.dev/api)."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import json
6
+ import os
7
+ import re
8
+ import urllib.error
9
+ import urllib.request
10
+ from typing import Any, Dict, Optional
11
+ from urllib.parse import quote, urlencode
12
+
13
+ from ._resources import Resources
14
+ from ._version import __version__
15
+
16
+ DEFAULT_URL = "https://api.shako.dev"
17
+ # The seconds for one request. A create waits until the VM boots, as the shako CLI does.
18
+ TIMEOUT = 15 * 60
19
+ # The HTTP status of a proxy in front of Shako when Shako does not answer.
20
+ NO_ANSWER = (502, 503, 504)
21
+
22
+
23
+ class ShakoError(Exception):
24
+ """An error answer, or no answer.
25
+
26
+ code: the code of the error (https://shako.dev/api/errors). It is unreachable when Shako did not answer.
27
+ message: the text of the error, for people.
28
+ status: the HTTP status. It is 0 when no answer came.
29
+ """
30
+
31
+ def __init__(self, code: str, message: str, status: int) -> None:
32
+ super().__init__(message)
33
+ self.code = code
34
+ self.message = message
35
+ self.status = status
36
+
37
+ def __repr__(self) -> str:
38
+ return f"ShakoError(code={self.code!r}, status={self.status}, message={self.message!r})"
39
+
40
+
41
+ class Shako(Resources):
42
+ """A client of the Shako API (https://shako.dev/api): shako.vms, shako.ports, shako.secrets, ...
43
+
44
+ api_key: an API key (shako api-key create). If it is missing, the environment variable SHAKO_API_KEY.
45
+ tenant: the tenant of each request. If it is missing, the tenant of the key, when the key has only one.
46
+ base_url: if it is missing, the environment variable SHAKO_API, then https://api.shako.dev.
47
+ timeout: the seconds for one request.
48
+ """
49
+
50
+ def __init__(self, api_key: Optional[str] = None, *, tenant: Optional[str] = None,
51
+ base_url: Optional[str] = None, timeout: float = TIMEOUT) -> None:
52
+ key = api_key or os.environ.get("SHAKO_API_KEY")
53
+ if not key:
54
+ raise ValueError("no API key: give Shako(api_key=...) or set SHAKO_API_KEY (https://shako.dev/api)")
55
+ self._api_key = key
56
+ self.tenant = tenant
57
+ self.base_url = (base_url or os.environ.get("SHAKO_API") or DEFAULT_URL).rstrip("/")
58
+ self.timeout = timeout
59
+ self._key_tenant: Optional[str] = None
60
+ self._attach(self)
61
+
62
+ def __repr__(self) -> str:
63
+ return f"Shako(base_url={self.base_url!r}, tenant={self.tenant!r})"
64
+
65
+ def request(self, method: str, path: str, params: Optional[Dict[str, Any]] = None,
66
+ fields: Optional[Dict[str, Any]] = None, tenant: Optional[str] = None) -> Any:
67
+ """One request: the path with the values of params (and the tenant), and the fields in the query of a GET or
68
+ in the JSON body. A field that is None is not sent. Returns the JSON answer. Raises ShakoError."""
69
+ values = {k: str(v) for k, v in (params or {}).items()}
70
+ if "{tenant}" in path:
71
+ values["tenant"] = tenant or self.tenant or self._tenant_of_key()
72
+
73
+ def value(match: "re.Match[str]") -> str:
74
+ return quote(values[match.group(1)], safe="")
75
+
76
+ url = self.base_url + re.sub(r"\{(\w+)\}", value, path)
77
+ sent = {k: v for k, v in (fields or {}).items() if v is not None}
78
+ headers = {"Authorization": f"Bearer {self._api_key}", "Accept": "application/json",
79
+ "User-Agent": f"shako-sdk-python/{__version__}"}
80
+ data = None
81
+ if method == "GET":
82
+ if sent:
83
+ url += "?" + urlencode({k: str(v).lower() if isinstance(v, bool) else v for k, v in sent.items()})
84
+ elif fields is not None:
85
+ data = json.dumps(sent).encode()
86
+ headers["Content-Type"] = "application/json"
87
+ try:
88
+ with urllib.request.urlopen(urllib.request.Request(url, data=data, method=method, headers=headers),
89
+ timeout=self.timeout) as response:
90
+ status, raw = response.status, response.read()
91
+ except urllib.error.HTTPError as err:
92
+ status, raw = err.code, err.read()
93
+ except OSError as err: # URLError, a refused connection, a timeout
94
+ reason = getattr(err, "reason", None) or err
95
+ raise ShakoError("unreachable", f"no answer from {self.base_url}: {reason}", 0) from err
96
+ try:
97
+ answer = json.loads(raw)
98
+ except ValueError:
99
+ code = "unreachable" if status in NO_ANSWER else "internal"
100
+ raise ShakoError(code, f"HTTP {status} with no JSON answer from {self.base_url}", status) from None
101
+ if 200 <= status < 300:
102
+ return answer
103
+ error = answer.get("error") if isinstance(answer, dict) else None
104
+ if isinstance(error, dict):
105
+ raise ShakoError(str(error.get("code") or "internal"), str(error.get("message") or f"HTTP {status}"),
106
+ status)
107
+ raise ShakoError("unreachable" if status in NO_ANSWER else "internal", f"HTTP {status} from {self.base_url}",
108
+ status)
109
+
110
+ def _tenant_of_key(self) -> str:
111
+ """The tenant of a key for one tenant, from GET /v1/whoami, once."""
112
+ if self._key_tenant is None:
113
+ tenant = self.request("GET", "/v1/whoami").get("tenant")
114
+ if not tenant:
115
+ raise ValueError("the API key has more than one tenant: give Shako(tenant=...), or tenant=... to the "
116
+ "method")
117
+ self._key_tenant = tenant
118
+ return self._key_tenant
@@ -0,0 +1,592 @@
1
+ # Made by `python3 -m shako_common.sdkgen write` from shako/common/shako_common/reference.py. Do not edit.
2
+ """The resources of the Shako API, and a method for each endpoint."""
3
+
4
+ from __future__ import annotations
5
+
6
+ from typing import List, Literal, Optional, Union, cast
7
+
8
+ from ._base import Client, Resource
9
+ from .types import (
10
+ AccessView,
11
+ AfterDelete,
12
+ AgentId,
13
+ AgentMemory,
14
+ BackupJob,
15
+ Credit,
16
+ CreditTopUp,
17
+ Deleted,
18
+ DeletedPort,
19
+ DeviceAdded,
20
+ DeviceView,
21
+ Exposed,
22
+ InvoiceFile,
23
+ KeyView,
24
+ Ports,
25
+ ScreenLink,
26
+ SecretView,
27
+ SizeName,
28
+ SleepPolicy,
29
+ Tenant,
30
+ TenantView,
31
+ UnreachableVm,
32
+ Usage,
33
+ VmBackups,
34
+ VmCrons,
35
+ VmInfo,
36
+ VmRole,
37
+ VmView,
38
+ WakeView,
39
+ Whoami,
40
+ )
41
+
42
+
43
+ class VmsResource(Resource):
44
+ """VMs: A VM is a Linux computer of its own. It sleeps when it is quiet, and it wakes on the next SSH login,
45
+ request or cron job. https://shako.dev/api/vms"""
46
+
47
+ def create(
48
+ self,
49
+ *,
50
+ name: str,
51
+ size: Optional[SizeName] = None,
52
+ cpus: Optional[int] = None,
53
+ memory: Optional[str] = None,
54
+ image: Optional[str] = None,
55
+ sleep: Optional[SleepPolicy] = None,
56
+ idle: Optional[str] = None,
57
+ no_wait: Optional[bool] = None,
58
+ agents: Optional[List[AgentId]] = None,
59
+ desktop: Optional[bool] = None,
60
+ role: Optional[VmRole] = None,
61
+ tenant: Optional[str] = None,
62
+ ) -> VmView:
63
+ """Create a VM: Create a VM and boot it. Every field but name is optional.
64
+
65
+ https://shako.dev/api/vms/create
66
+ """
67
+ return cast('VmView', self._call(
68
+ 'POST', '/v1/tenants/{tenant}/vms', {},
69
+ {
70
+ 'name': name,
71
+ 'size': size,
72
+ 'cpus': cpus,
73
+ 'memory': memory,
74
+ 'image': image,
75
+ 'sleep': sleep,
76
+ 'idle': idle,
77
+ 'no_wait': no_wait,
78
+ 'agents': agents,
79
+ 'desktop': desktop,
80
+ 'role': role,
81
+ }, tenant))
82
+
83
+ def list(self, *, tenant: Optional[str] = None) -> List[Union[VmView, UnreachableVm]]:
84
+ """List VMs: The VMs of the tenant.
85
+
86
+ https://shako.dev/api/vms/list
87
+ """
88
+ return cast('List[Union[VmView, UnreachableVm]]', self._call(
89
+ 'GET', '/v1/tenants/{tenant}/vms', {},
90
+ None, tenant, data=True))
91
+
92
+ def get(self, name: str, *, tenant: Optional[str] = None) -> VmInfo:
93
+ """Get a VM: One VM, with its last events.
94
+
95
+ https://shako.dev/api/vms/get
96
+ """
97
+ return cast('VmInfo', self._call('GET', '/v1/tenants/{tenant}/vms/{name}', {'name': name}, None, tenant))
98
+
99
+ def update(
100
+ self,
101
+ name: str,
102
+ *,
103
+ sleep: Optional[SleepPolicy] = None,
104
+ idle: Optional[str] = None,
105
+ wake_on_cron: Optional[bool] = None,
106
+ wake_on_chat: Optional[bool] = None,
107
+ backup: Optional[bool] = None,
108
+ after_delete: Optional[AfterDelete] = None,
109
+ tenant: Optional[str] = None,
110
+ ) -> VmView:
111
+ """Update a VM: Change the sleep policy of a VM, its wakes and its backups. A field that you do not send
112
+ keeps its value.
113
+
114
+ https://shako.dev/api/vms/update
115
+ """
116
+ return cast('VmView', self._call(
117
+ 'PATCH', '/v1/tenants/{tenant}/vms/{name}', {'name': name},
118
+ {
119
+ 'sleep': sleep,
120
+ 'idle': idle,
121
+ 'wake_on_cron': wake_on_cron,
122
+ 'wake_on_chat': wake_on_chat,
123
+ 'backup': backup,
124
+ 'after_delete': after_delete,
125
+ }, tenant))
126
+
127
+ def delete(self, name: str, *, tenant: Optional[str] = None) -> Deleted:
128
+ """Delete a VM: Delete a VM and its disk. You cannot undo this.
129
+
130
+ https://shako.dev/api/vms/delete
131
+ """
132
+ return cast('Deleted', self._call('DELETE', '/v1/tenants/{tenant}/vms/{name}', {'name': name}, None, tenant))
133
+
134
+ def sleep(self, name: str, *, tenant: Optional[str] = None) -> VmView:
135
+ """Put a VM to sleep: Put a VM to sleep now. Its programs stay in memory, saved on its disk.
136
+
137
+ https://shako.dev/api/vms/sleep
138
+ """
139
+ return cast('VmView', self._call('POST', '/v1/tenants/{tenant}/vms/{name}/sleep', {'name': name}, None, tenant))
140
+
141
+ def wake(self, name: str, *, tenant: Optional[str] = None) -> WakeView:
142
+ """Wake a VM: Wake a VM now. An SSH login or a request to a public port also wakes it.
143
+
144
+ https://shako.dev/api/vms/wake
145
+ """
146
+ return cast('WakeView', self._call(
147
+ 'POST', '/v1/tenants/{tenant}/vms/{name}/wake', {'name': name},
148
+ None, tenant))
149
+
150
+ def restart(self, name: str, *, tenant: Optional[str] = None) -> VmView:
151
+ """Restart a VM: A clean shutdown, then a boot from the disk. The running programs stop, and the files
152
+ stay.
153
+
154
+ https://shako.dev/api/vms/restart
155
+ """
156
+ return cast('VmView', self._call(
157
+ 'POST', '/v1/tenants/{tenant}/vms/{name}/restart', {'name': name},
158
+ None, tenant))
159
+
160
+ def resize(
161
+ self,
162
+ name: str,
163
+ *,
164
+ size: Optional[SizeName] = None,
165
+ cpus: Optional[int] = None,
166
+ memory: Optional[str] = None,
167
+ restart: Optional[bool] = None,
168
+ tenant: Optional[str] = None,
169
+ ) -> VmView:
170
+ """Resize a VM: Change the size of a VM. The disk follows the new memory.
171
+
172
+ https://shako.dev/api/vms/resize
173
+ """
174
+ return cast('VmView', self._call(
175
+ 'POST', '/v1/tenants/{tenant}/vms/{name}/resize', {'name': name},
176
+ {
177
+ 'size': size,
178
+ 'cpus': cpus,
179
+ 'memory': memory,
180
+ 'restart': restart,
181
+ }, tenant))
182
+
183
+ def rename(self, name: str, *, new_name: str, tenant: Optional[str] = None) -> VmView:
184
+ """Rename a VM: Give a VM a new name. Its SSH name and the URLs of its public ports change, and the old
185
+ ones stop.
186
+
187
+ https://shako.dev/api/vms/rename
188
+ """
189
+ return cast('VmView', self._call(
190
+ 'POST', '/v1/tenants/{tenant}/vms/{name}/rename', {'name': name},
191
+ {
192
+ 'new_name': new_name,
193
+ }, tenant))
194
+
195
+ def copy(
196
+ self,
197
+ source: str,
198
+ *,
199
+ name: str,
200
+ sleep: Optional[SleepPolicy] = None,
201
+ idle: Optional[str] = None,
202
+ no_wait: Optional[bool] = None,
203
+ tenant: Optional[str] = None,
204
+ ) -> VmView:
205
+ """Copy a VM: A new VM whose disk starts as a copy of the source VM's disk.
206
+
207
+ https://shako.dev/api/vms/copy
208
+ """
209
+ return cast('VmView', self._call(
210
+ 'POST', '/v1/tenants/{tenant}/vms/{source}/copy', {'source': source},
211
+ {
212
+ 'name': name,
213
+ 'sleep': sleep,
214
+ 'idle': idle,
215
+ 'no_wait': no_wait,
216
+ }, tenant))
217
+
218
+ def logs(self, name: str, *, lines: Optional[int] = None, tenant: Optional[str] = None) -> str:
219
+ """Read the console: The last lines of the VM's console output, as one string.
220
+
221
+ https://shako.dev/api/vms/logs
222
+ """
223
+ return cast('str', self._call(
224
+ 'GET', '/v1/tenants/{tenant}/vms/{name}/logs', {'name': name},
225
+ {
226
+ 'lines': lines,
227
+ }, tenant))
228
+
229
+ def crons(self, name: str, *, tenant: Optional[str] = None) -> VmCrons:
230
+ """List the crons: The crons in a VM (cron and the schedulers of its agents) and its next wake.
231
+
232
+ https://shako.dev/api/vms/crons
233
+ """
234
+ return cast('VmCrons', self._call('GET', '/v1/tenants/{tenant}/vms/{name}/crons', {'name': name}, None, tenant))
235
+
236
+
237
+ class PortsResource(Resource):
238
+ """Ports: A shared port of a VM has its own HTTPS URL. A public URL opens for anyone; a private URL opens only
239
+ on the devices of the tenant. https://shako.dev/api/ports"""
240
+
241
+ def list(self, name: str, *, port: Optional[int] = None, tenant: Optional[str] = None) -> Ports:
242
+ """List ports: The shared ports of a VM, and the common ports that listen.
243
+
244
+ https://shako.dev/api/ports/list
245
+ """
246
+ return cast('Ports', self._call(
247
+ 'GET', '/v1/tenants/{tenant}/vms/{name}/ports', {'name': name},
248
+ {
249
+ 'port': port,
250
+ }, tenant))
251
+
252
+ def create(
253
+ self,
254
+ name: str,
255
+ *,
256
+ port: int,
257
+ access: Optional[Literal['public', 'private']] = None,
258
+ tenant: Optional[str] = None,
259
+ ) -> Exposed:
260
+ """Share a port: Give a port of the VM a URL, for the internet or for the devices of the tenant.
261
+
262
+ https://shako.dev/api/ports/create
263
+ """
264
+ return cast('Exposed', self._call(
265
+ 'POST', '/v1/tenants/{tenant}/vms/{name}/ports', {'name': name},
266
+ {
267
+ 'port': port,
268
+ 'access': access,
269
+ }, tenant))
270
+
271
+ def delete(self, name: str, port: int, *, tenant: Optional[str] = None) -> DeletedPort:
272
+ """Stop sharing a port: Stop sharing a port. Its URL stops at once.
273
+
274
+ https://shako.dev/api/ports/delete
275
+ """
276
+ return cast('DeletedPort', self._call(
277
+ 'DELETE', '/v1/tenants/{tenant}/vms/{name}/ports/{port}', {'name': name, 'port': port},
278
+ None, tenant))
279
+
280
+
281
+ class BackupsResource(Resource):
282
+ """Backups: A backup is a copy of a VM's disk, kept outside its host. Shako backs up each VM every night if its
283
+ disk changed. https://shako.dev/api/backups"""
284
+
285
+ def list(self, name: str, *, tenant: Optional[str] = None) -> VmBackups:
286
+ """List backups: A VM's backups, newest first, and its last jobs.
287
+
288
+ https://shako.dev/api/backups/list
289
+ """
290
+ return cast('VmBackups', self._call(
291
+ 'GET', '/v1/tenants/{tenant}/vms/{name}/backups', {'name': name},
292
+ None, tenant))
293
+
294
+ def create(self, name: str, *, tenant: Optional[str] = None) -> BackupJob:
295
+ """Back up now: Start a backup of the VM now. The VM keeps running.
296
+
297
+ https://shako.dev/api/backups/create
298
+ """
299
+ return cast('BackupJob', self._call(
300
+ 'POST', '/v1/tenants/{tenant}/vms/{name}/backups', {'name': name},
301
+ None, tenant))
302
+
303
+ def restore(self, name: str, id: str, *, tenant: Optional[str] = None) -> BackupJob:
304
+ """Restore a backup: Put a VM's disk back to one of its backups. The VM restarts.
305
+
306
+ https://shako.dev/api/backups/restore
307
+ """
308
+ return cast('BackupJob', self._call(
309
+ 'POST', '/v1/tenants/{tenant}/vms/{name}/backups/{id}/restore', {'name': name, 'id': id},
310
+ None, tenant))
311
+
312
+ def delete(self, name: str, *, tenant: Optional[str] = None) -> Deleted:
313
+ """Erase the backups: Delete every backup of a VM now. You cannot undo this.
314
+
315
+ https://shako.dev/api/backups/delete
316
+ """
317
+ return cast('Deleted', self._call(
318
+ 'DELETE', '/v1/tenants/{tenant}/vms/{name}/backups', {'name': name},
319
+ None, tenant))
320
+
321
+
322
+ class ScreenLinksResource(Resource):
323
+ """Screen links: A link to the screen of a VM with the desktop, for people with no account, for example your
324
+ customers. https://shako.dev/api/screen-links"""
325
+
326
+ def create(self, name: str, *, expires: Optional[int] = None, tenant: Optional[str] = None) -> ScreenLink:
327
+ """Create a screen link: A link to the VM's screen. Who has the link watches, and can take over the screen,
328
+ until it expires.
329
+
330
+ https://shako.dev/api/screen-links/create
331
+ """
332
+ return cast('ScreenLink', self._call(
333
+ 'POST', '/v1/tenants/{tenant}/vms/{name}/screen-links', {'name': name},
334
+ {
335
+ 'expires': expires,
336
+ }, tenant))
337
+
338
+ def delete(self, name: str, *, tenant: Optional[str] = None) -> Deleted:
339
+ """Stop the screen links: Stop every link to the VM's screen. Their open views close within 10 seconds.
340
+
341
+ https://shako.dev/api/screen-links/delete
342
+ """
343
+ return cast('Deleted', self._call(
344
+ 'DELETE', '/v1/tenants/{tenant}/vms/{name}/screen-links', {'name': name},
345
+ None, tenant))
346
+
347
+
348
+ class SecretsResource(Resource):
349
+ """Secrets: A secret, such as a GitHub token, that the VMs use but cannot read. Each VM gets the variable
350
+ NAME=shako-secret-NAME, and Shako puts the value in its place in the requests to the secret's hosts.
351
+ https://shako.dev/api/secrets"""
352
+
353
+ def list(self, *, tenant: Optional[str] = None) -> List[SecretView]:
354
+ """List secrets: The secrets of the tenant. No endpoint gives a value back.
355
+
356
+ https://shako.dev/api/secrets/list
357
+ """
358
+ return cast('List[SecretView]', self._call('GET', '/v1/tenants/{tenant}/secrets', {}, None, tenant, data=True))
359
+
360
+ def set(self, name: str, *, value: str, hosts: List[str], tenant: Optional[str] = None) -> SecretView:
361
+ """Set a secret: Add a secret, or replace it.
362
+
363
+ https://shako.dev/api/secrets/set
364
+ """
365
+ return cast('SecretView', self._call(
366
+ 'PUT', '/v1/tenants/{tenant}/secrets/{name}', {'name': name},
367
+ {
368
+ 'value': value,
369
+ 'hosts': hosts,
370
+ }, tenant))
371
+
372
+ def delete(self, name: str, *, tenant: Optional[str] = None) -> Deleted:
373
+ """Delete a secret: Remove a secret. Shako stops putting its value in the requests of the VMs.
374
+
375
+ https://shako.dev/api/secrets/delete
376
+ """
377
+ return cast('Deleted', self._call(
378
+ 'DELETE', '/v1/tenants/{tenant}/secrets/{name}', {'name': name},
379
+ None, tenant))
380
+
381
+
382
+ class DevicesResource(Resource):
383
+ """Devices: A device, such as a laptop, reaches the private ports of the tenant through its WireGuard tunnel.
384
+ https://shako.dev/api/devices"""
385
+
386
+ def list(self, *, tenant: Optional[str] = None) -> List[DeviceView]:
387
+ """List devices: The devices of the tenant.
388
+
389
+ https://shako.dev/api/devices/list
390
+ """
391
+ return cast('List[DeviceView]', self._call('GET', '/v1/tenants/{tenant}/devices', {}, None, tenant, data=True))
392
+
393
+ def create(self, *, name: str, public_key: str, tenant: Optional[str] = None) -> DeviceAdded:
394
+ """Add a device: Add a device to the private network of the tenant.
395
+
396
+ https://shako.dev/api/devices/create
397
+ """
398
+ return cast('DeviceAdded', self._call(
399
+ 'POST', '/v1/tenants/{tenant}/devices', {},
400
+ {
401
+ 'name': name,
402
+ 'public_key': public_key,
403
+ }, tenant))
404
+
405
+ def delete(self, name: str, *, tenant: Optional[str] = None) -> Deleted:
406
+ """Remove a device: Remove a device. Its tunnel stops at once.
407
+
408
+ https://shako.dev/api/devices/delete
409
+ """
410
+ return cast('Deleted', self._call(
411
+ 'DELETE', '/v1/tenants/{tenant}/devices/{name}', {'name': name},
412
+ None, tenant))
413
+
414
+
415
+ class MemoryResource(Resource):
416
+ """Agent memory: Notes of up to 2000 tokens that Shako adds to each LLM request from the VMs of the tenant, for
417
+ every agent. https://shako.dev/api/memory"""
418
+
419
+ def get(self, *, tenant: Optional[str] = None) -> AgentMemory:
420
+ """Get the agent memory: The notes, and if they are on.
421
+
422
+ https://shako.dev/api/memory/get
423
+ """
424
+ return cast('AgentMemory', self._call('GET', '/v1/tenants/{tenant}/memory', {}, None, tenant))
425
+
426
+ def update(
427
+ self,
428
+ *,
429
+ text: Optional[str] = None,
430
+ enabled: Optional[bool] = None,
431
+ tenant: Optional[str] = None,
432
+ ) -> AgentMemory:
433
+ """Update the agent memory: Replace the notes, turn them on or off, or both. The last save wins.
434
+
435
+ https://shako.dev/api/memory/update
436
+ """
437
+ return cast('AgentMemory', self._call(
438
+ 'PATCH', '/v1/tenants/{tenant}/memory', {},
439
+ {
440
+ 'text': text,
441
+ 'enabled': enabled,
442
+ }, tenant))
443
+
444
+
445
+ class BillingResource(Resource):
446
+ """Billing: The VMs of a tenant use its prepaid credit. Awake, a VM pays for its memory and its disk. Asleep, it
447
+ pays for its disk only. https://shako.dev/api/billing"""
448
+
449
+ def usage(
450
+ self,
451
+ *,
452
+ since: Optional[int] = None,
453
+ days: Optional[bool] = None,
454
+ utc_offset: Optional[int] = None,
455
+ tenant: Optional[str] = None,
456
+ ) -> Usage:
457
+ """Read the usage: The hours and the cost of each VM of the tenant, and the totals.
458
+
459
+ https://shako.dev/api/billing/usage
460
+ """
461
+ return cast('Usage', self._call(
462
+ 'GET', '/v1/tenants/{tenant}/usage', {},
463
+ {
464
+ 'since': since,
465
+ 'days': days,
466
+ 'utc_offset': utc_offset,
467
+ }, tenant))
468
+
469
+ def credit(self, *, tenant: Optional[str] = None) -> Credit:
470
+ """Read the credit: What is left of the credit, and what the VMs used.
471
+
472
+ https://shako.dev/api/billing/credit
473
+ """
474
+ return cast('Credit', self._call('GET', '/v1/tenants/{tenant}/credit', {}, None, tenant))
475
+
476
+ def top_up(self, *, amount: int, tenant: Optional[str] = None) -> CreditTopUp:
477
+ """Top up the credit: A Stripe payment page for a top-up. The credit goes up when Stripe tells Shako that
478
+ it is paid.
479
+
480
+ https://shako.dev/api/billing/top-up
481
+ """
482
+ return cast('CreditTopUp', self._call(
483
+ 'POST', '/v1/tenants/{tenant}/credit/top-up', {},
484
+ {
485
+ 'amount': amount,
486
+ }, tenant))
487
+
488
+ def invoice(self, month: str, *, utc_offset: Optional[int] = None, tenant: Optional[str] = None) -> InvoiceFile:
489
+ """Get an invoice: The PDF invoice of one month: the usage and the cost of each VM.
490
+
491
+ https://shako.dev/api/billing/invoice
492
+ """
493
+ return cast('InvoiceFile', self._call(
494
+ 'GET', '/v1/tenants/{tenant}/invoices/{month}', {'month': month},
495
+ {
496
+ 'utc_offset': utc_offset,
497
+ }, tenant))
498
+
499
+
500
+ class AccessResource(Resource):
501
+ """Access: Who has a role in the tenant: the owner, the members, the invites and the VMs.
502
+ https://shako.dev/docs/access-control.md has the roles. https://shako.dev/api/access"""
503
+
504
+ def list(self, *, tenant: Optional[str] = None) -> List[AccessView]:
505
+ """List access: Each account and VM with its role in the tenant. API keys are not in it.
506
+
507
+ https://shako.dev/api/access/list
508
+ """
509
+ return cast('List[AccessView]', self._call('GET', '/v1/tenants/{tenant}/access', {}, None, tenant, data=True))
510
+
511
+ def revoke_vm(self, name: str, *, tenant: Optional[str] = None) -> Deleted:
512
+ """Take a VM's access away: The VM gets the role none at once: from the VM, the shako commands and SSH to
513
+ the other VMs stop.
514
+
515
+ https://shako.dev/api/access/revoke-vm
516
+ """
517
+ return cast('Deleted', self._call(
518
+ 'DELETE', '/v1/tenants/{tenant}/vms/{name}/access', {'name': name},
519
+ None, tenant))
520
+
521
+
522
+ class TenantsResource(Resource):
523
+ """Tenants: A tenant has its own VMs, credit and invoices. Each path of a VM names its tenant.
524
+ https://shako.dev/api/tenants"""
525
+
526
+ def list(self) -> List[TenantView]:
527
+ """List tenants: The tenants of the key, the oldest first, with the role of the key in each.
528
+
529
+ https://shako.dev/api/tenants/list
530
+ """
531
+ return cast('List[TenantView]', self._call('GET', '/v1/tenants', {}, None, None, data=True))
532
+
533
+ def create(self, *, name: str) -> Tenant:
534
+ """Create a tenant: Create a tenant that the account of the key owns.
535
+
536
+ https://shako.dev/api/tenants/create
537
+ """
538
+ return cast('Tenant', self._call('POST', '/v1/tenants', {}, {'name': name}, None))
539
+
540
+ def delete(self, name: str) -> Deleted:
541
+ """Delete a tenant: Delete a tenant. It must have no VMs, and no other members or invites.
542
+
543
+ https://shako.dev/api/tenants/delete
544
+ """
545
+ return cast('Deleted', self._call('DELETE', '/v1/tenants/{name}', {'name': name}, None, None))
546
+
547
+
548
+ class CallerResource(Resource):
549
+ """Caller: Who calls, and the SSH keys that it can see. https://shako.dev/api/caller"""
550
+
551
+ def whoami(self) -> Whoami:
552
+ """Who am I: The key, its tenants, and the domains and sizes of Shako.
553
+
554
+ https://shako.dev/api/caller/whoami
555
+ """
556
+ return cast('Whoami', self._call('GET', '/v1/whoami', {}, None, None))
557
+
558
+ def ssh_keys(self) -> List[KeyView]:
559
+ """List SSH keys: The SSH keys of the account of the key, then the keys of the VMs of its tenants.
560
+
561
+ https://shako.dev/api/caller/ssh-keys
562
+ """
563
+ return cast('List[KeyView]', self._call('GET', '/v1/ssh-keys', {}, None, None, data=True))
564
+
565
+
566
+ class Resources:
567
+ """The resources of the API, one attribute each: shako.vms, shako.ports, ..."""
568
+
569
+ vms: VmsResource
570
+ ports: PortsResource
571
+ backups: BackupsResource
572
+ screen_links: ScreenLinksResource
573
+ secrets: SecretsResource
574
+ devices: DevicesResource
575
+ memory: MemoryResource
576
+ billing: BillingResource
577
+ access: AccessResource
578
+ tenants: TenantsResource
579
+ caller: CallerResource
580
+
581
+ def _attach(self, client: Client) -> None:
582
+ self.vms = VmsResource(client)
583
+ self.ports = PortsResource(client)
584
+ self.backups = BackupsResource(client)
585
+ self.screen_links = ScreenLinksResource(client)
586
+ self.secrets = SecretsResource(client)
587
+ self.devices = DevicesResource(client)
588
+ self.memory = MemoryResource(client)
589
+ self.billing = BillingResource(client)
590
+ self.access = AccessResource(client)
591
+ self.tenants = TenantsResource(client)
592
+ self.caller = CallerResource(client)
shako_sdk/_version.py ADDED
@@ -0,0 +1 @@
1
+ __version__ = "0.1.0"
shako_sdk/py.typed ADDED
File without changes
shako_sdk/types.py ADDED
@@ -0,0 +1,417 @@
1
+ # Made by `python3 -m shako_common.sdkgen write` from shako/common/shako_common/reference.py. Do not edit.
2
+ """The types of the args and of the answers of the Shako API (https://shako.dev/api)."""
3
+
4
+ from __future__ import annotations
5
+
6
+ from typing import Dict, List, Literal, Optional, TypedDict, Union
7
+
8
+
9
+ SizeName = Literal['small', 'mid', 'large', 'xl']
10
+ SleepPolicy = Literal['auto', 'never']
11
+ VmState = Literal['creating', 'booting', 'awake', 'sleeping', 'asleep', 'waking', 'stopped', 'deleting', 'failed']
12
+ BackupKind = Literal['nightly', 'manual', 'pre-restore']
13
+ BackupStep = Literal[
14
+ 'queued', 'copying', 'uploading', 'downloading', 'swapping', 'booting', 'saving undo', 'done', 'failed',
15
+ ]
16
+ AfterDelete = Literal['keep-7d', 'erase']
17
+ AgentId = Literal['claude', 'codex', 'opencode', 'pi', 'kiro', 'openclaw', 'hermes']
18
+ ResourceId = Literal['ram', 'disk']
19
+ Role = Literal['owner', 'contributor']
20
+ VmRole = Literal['contributor', 'none']
21
+ PrincipalKind = Literal['account', 'vm', 'api_key']
22
+ AccessKind = Literal['vm', 'member']
23
+ AccessLevel = Literal['any', 'own', 'contributor', 'owner', 'grant', 'owner-account']
24
+
25
+
26
+ class _VmView(TypedDict):
27
+ name: str
28
+ tenant: str
29
+ id: float
30
+ vm_id: Optional[str]
31
+ state: VmState
32
+ vcpus: float
33
+ mem_mib: float
34
+ disk_gb: float
35
+ image: str
36
+ sleep_policy: SleepPolicy
37
+ idle_minutes: float
38
+ ip: str
39
+ ssh: str
40
+ created_at: float
41
+ last_active: float
42
+ last_active_reason: str
43
+ snapshot: Optional[str]
44
+ snap_at: Optional[float]
45
+ awake_hours: float
46
+ gb_hours: float
47
+ disk_gb_hours: float
48
+ last_error: Optional[str]
49
+ agents: List[AgentId]
50
+ desktop: bool
51
+ next_wake: Optional[NextWake]
52
+ wake_on_cron: bool
53
+ wake_on_chat: bool
54
+ backup: bool
55
+ after_delete: AfterDelete
56
+ resources: List[ResourceUse]
57
+
58
+
59
+ class VmView(_VmView, total=False):
60
+ """The VM object: A VM. Create, get, update, the actions and copy answer with it; list answers with a list of
61
+ it. https://shako.dev/api/objects/vm-view"""
62
+ role: VmRole
63
+
64
+
65
+ class ResourceUse(TypedDict):
66
+ """The resource use object: The use of the memory or the disk inside an awake VM.
67
+ https://shako.dev/api/objects/resource-use"""
68
+ id: ResourceId
69
+ used: float
70
+ total: float
71
+ pct: float
72
+ limit_pct: Optional[float]
73
+ over: bool
74
+
75
+
76
+ class NextWake(TypedDict):
77
+ """The next wake object: The scheduled wake of a sleeping VM. https://shako.dev/api/objects/next-wake"""
78
+ at: float
79
+ job_at: float
80
+ label: Optional[str]
81
+
82
+
83
+ class _UnreachableVm(TypedDict):
84
+ name: str
85
+ tenant: str
86
+ vm_id: str
87
+ state: Literal['unreachable']
88
+ vcpus: float
89
+ mem_mib: float
90
+ disk_gb: float
91
+ ssh: str
92
+ last_error: str
93
+
94
+
95
+ class UnreachableVm(_UnreachableVm, total=False):
96
+ """The unreachable VM object: A VM in the list whose host does not answer now. Try again later.
97
+ https://shako.dev/api/objects/unreachable-vm"""
98
+ role: VmRole
99
+
100
+
101
+ class Cron(TypedDict):
102
+ """The cron object: One cron in a VM. https://shako.dev/api/objects/cron"""
103
+ source: str
104
+ schedule: str
105
+ next_at: Optional[float]
106
+ hold_until: Optional[float]
107
+
108
+
109
+ class VmCrons(TypedDict):
110
+ """The crons object: The crons of a VM and its next wake. https://shako.dev/api/objects/vm-crons"""
111
+ state: VmState
112
+ live: bool
113
+ as_of: Optional[float]
114
+ next_wake: Optional[NextWake]
115
+ crons: List[Cron]
116
+ truncated: bool
117
+
118
+
119
+ class VmEvent(TypedDict):
120
+ """The VM event object: One event of a VM, for example a boot or a sleep. https://shako.dev/api/objects/vm-
121
+ event"""
122
+ at: float
123
+ kind: str
124
+ detail: str
125
+ ms: Optional[float]
126
+
127
+
128
+ class VmInfo(VmView):
129
+ """The VM info object: Get answers with the VM object and these fields. https://shako.dev/api/objects/vm-info"""
130
+ events: List[VmEvent]
131
+ quiet: Optional[bool]
132
+
133
+
134
+ class WakeView(VmView, total=False):
135
+ """The wake object: Wake answers with the VM object and these fields. https://shako.dev/api/objects/wake-view"""
136
+ woke_by: str
137
+ wake_ms: Optional[float]
138
+
139
+
140
+ class UsageRow(TypedDict):
141
+ """The usage row object: The usage of one VM. A cost is in US dollars. https://shako.dev/api/objects/usage-
142
+ row"""
143
+ vm_id: str
144
+ name: str
145
+ state: Union[VmState, Literal['deleted', 'unknown']]
146
+ mem_mib: float
147
+ awake_hours: float
148
+ gb_hours: float
149
+ asleep_hours: float
150
+ asleep_gb_hours: float
151
+ stopped_hours: float
152
+ stopped_gb_hours: float
153
+ subscribed_disk_gb_hours: float
154
+ awake_disk_gb_hours: float
155
+ asleep_disk_gb_hours: float
156
+ memory_cost: float
157
+ disk_cost: float
158
+ cost: float
159
+
160
+
161
+ class UsageDay(TypedDict):
162
+ """The usage day object: The usage of one VM on one day. Only a day with usage has a row.
163
+ https://shako.dev/api/objects/usage-day"""
164
+ day: str
165
+ vm_id: str
166
+ gb_hours: float
167
+ disk_gb_hours: float
168
+ memory_cost: float
169
+ disk_cost: float
170
+ cost: float
171
+
172
+
173
+ class _Usage(TypedDict):
174
+ vms: List[UsageRow]
175
+ total_awake_hours: float
176
+ total_gb_hours: float
177
+ total_asleep_hours: float
178
+ total_asleep_gb_hours: float
179
+ total_stopped_hours: float
180
+ total_stopped_gb_hours: float
181
+ total_subscribed_disk_gb_hours: float
182
+ total_awake_disk_gb_hours: float
183
+ total_asleep_disk_gb_hours: float
184
+ total_memory_cost: float
185
+ total_disk_cost: float
186
+ total_cost: float
187
+
188
+
189
+ class Usage(_Usage, total=False):
190
+ """The usage object: The usage of the VMs of the tenant, and the totals. A cost is in US dollars.
191
+ https://shako.dev/api/objects/usage"""
192
+ days: List[UsageDay]
193
+
194
+
195
+ class CreditEntry(TypedDict):
196
+ """The credit entry object: An addition to the credit. https://shako.dev/api/objects/credit-entry"""
197
+ kind: Literal['free', 'topup', 'refund', 'grant']
198
+ amount: str
199
+ at: float
200
+
201
+
202
+ class Credit(TypedDict):
203
+ """The credit object: The prepaid credit of the tenant. Each amount is a string of US dollars to the cent.
204
+ https://shako.dev/api/objects/credit"""
205
+ balance: str
206
+ credit: str
207
+ used: str
208
+ since: float
209
+ entries: List[CreditEntry]
210
+ top_up: bool
211
+ amounts: List[float]
212
+ held: bool
213
+
214
+
215
+ class InvoiceFile(TypedDict):
216
+ """The invoice object: A PDF invoice. https://shako.dev/api/objects/invoice-file"""
217
+ name: str
218
+ total: str
219
+ pdf: str
220
+
221
+
222
+ class CreditTopUp(TypedDict):
223
+ """The top-up object: A Stripe payment page. https://shako.dev/api/objects/credit-top-up"""
224
+ url: str
225
+ amount: str
226
+
227
+
228
+ class Backup(TypedDict):
229
+ """The backup object: One backup of a VM. https://shako.dev/api/objects/backup"""
230
+ id: str
231
+ taken_at: float
232
+ kind: BackupKind
233
+ added_bytes: Optional[float]
234
+
235
+
236
+ class BackupJob(TypedDict):
237
+ """The backup job object: A backup or a restore of one VM. https://shako.dev/api/objects/backup-job"""
238
+ id: float
239
+ kind: Literal['backup', 'restore']
240
+ tag: Optional[BackupKind]
241
+ backup: Optional[str]
242
+ undo: Optional[str]
243
+ step: BackupStep
244
+ started_at: float
245
+ ended_at: Optional[float]
246
+ error: Optional[str]
247
+
248
+
249
+ class VmBackups(TypedDict):
250
+ """The backups object: The backups of a VM and its last jobs. https://shako.dev/api/objects/vm-backups"""
251
+ name: str
252
+ enabled: bool
253
+ backup: bool
254
+ backups: List[Backup]
255
+ jobs: List[BackupJob]
256
+
257
+
258
+ class PublicPort(TypedDict):
259
+ """The public port object: A port that anyone can open. https://shako.dev/api/objects/public-port"""
260
+ port: float
261
+ url: str
262
+ tcp: Optional[str]
263
+
264
+
265
+ class PrivatePort(TypedDict):
266
+ """The private port object: A port that only the devices of the tenant can open.
267
+ https://shako.dev/api/objects/private-port"""
268
+ port: float
269
+ url: str
270
+
271
+
272
+ class Ports(TypedDict):
273
+ """The ports object: The shared ports of a VM. https://shako.dev/api/objects/ports"""
274
+ name: str
275
+ state: VmState
276
+ edge: bool
277
+ public: List[PublicPort]
278
+ private: List[PrivatePort]
279
+ listening: Optional[List[float]]
280
+
281
+
282
+ class Exposed(TypedDict):
283
+ """The shared port object: The answer of a share of a port. https://shako.dev/api/objects/exposed"""
284
+ name: str
285
+ port: float
286
+ url: str
287
+ tcp: Optional[str]
288
+ warnings: List[str]
289
+
290
+
291
+ class DeviceView(TypedDict):
292
+ """The device object: A device of the private network. https://shako.dev/api/objects/device-view"""
293
+ name: str
294
+ address: str
295
+ created: float
296
+ last_seen: Optional[float]
297
+ email: Optional[str]
298
+
299
+
300
+ class DeviceAdded(TypedDict):
301
+ """The added device object: What the device's WireGuard config needs. https://shako.dev/api/objects/device-
302
+ added"""
303
+ name: str
304
+ address: str
305
+ gateway: str
306
+ endpoint: str
307
+ public_key: str
308
+
309
+
310
+ class SizeSpec(TypedDict):
311
+ """The size object: A size of a VM. A price is a string of US dollars. https://shako.dev/api/objects/size-
312
+ spec"""
313
+ title: str
314
+ vcpus: float
315
+ mem_mib: float
316
+ disk_gb: float
317
+ awake_per_hour: str
318
+ asleep_per_hour: str
319
+ awake_per_month: str
320
+
321
+
322
+ class Sizes(TypedDict):
323
+ """The sizes object: The sizes of a VM. https://shako.dev/api/objects/sizes"""
324
+ sizes: Dict[SizeName, SizeSpec]
325
+ default: SizeName
326
+
327
+
328
+ class Whoami(TypedDict):
329
+ """The whoami object: The key and its tenants, and the names of Shako. https://shako.dev/api/objects/whoami"""
330
+ tenant: Optional[str]
331
+ email: Optional[str]
332
+ vms: float
333
+ keys: float
334
+ tenants: List[TenantView]
335
+ domain: str
336
+ apps_domain: str
337
+ ssh_gateway: str
338
+ workspace: str
339
+ sizes: Sizes
340
+ principal: Principal
341
+
342
+
343
+ class Principal(TypedDict):
344
+ """The principal object: Who calls. https://shako.dev/api/objects/principal"""
345
+ kind: PrincipalKind
346
+ name: str
347
+
348
+
349
+ class TenantView(TypedDict):
350
+ """The tenant object: A tenant of the key, and the role of the key there. https://shako.dev/api/objects/tenant-
351
+ view"""
352
+ name: str
353
+ role: Role
354
+ default: bool
355
+
356
+
357
+ class AccessView(TypedDict):
358
+ """The access object: An account or a VM with its role in the tenant. https://shako.dev/api/objects/access-
359
+ view"""
360
+ tenant: str
361
+ kind: Literal['account', 'vm']
362
+ name: str
363
+ email: Optional[str]
364
+ role: Union[Role, Literal['invited', 'none']]
365
+
366
+
367
+ class Tenant(TypedDict):
368
+ """The new tenant object: A tenant that was created or deleted. https://shako.dev/api/objects/tenant"""
369
+ name: str
370
+
371
+
372
+ class AgentMemory(TypedDict):
373
+ """The agent memory object: The notes of the tenant's agents. https://shako.dev/api/objects/agent-memory"""
374
+ enabled: bool
375
+ text: str
376
+ tokens: float
377
+ updated: Optional[float]
378
+
379
+
380
+ class SecretView(TypedDict):
381
+ """The secret object: A secret, with no value. https://shako.dev/api/objects/secret-view"""
382
+ name: str
383
+ hosts: List[str]
384
+ hint: str
385
+ updated: float
386
+
387
+
388
+ class KeyView(TypedDict):
389
+ """The SSH key object: An SSH key that the key can see. https://shako.dev/api/objects/key-view"""
390
+ name: str
391
+ fingerprint: str
392
+ key: str
393
+ scope: Literal['account', 'tenant', 'none']
394
+ tenant: Optional[str]
395
+ vm: Optional[str]
396
+ email: Optional[str]
397
+ mine: bool
398
+
399
+
400
+ class ScreenLink(TypedDict):
401
+ """The screen link object: A link to the screen of a VM. https://shako.dev/api/objects/screen-link"""
402
+ name: str
403
+ url: str
404
+ expires: float
405
+
406
+
407
+ class Deleted(TypedDict):
408
+ """The answer of a delete: the names of its path."""
409
+ name: str
410
+ deleted: Literal[True]
411
+
412
+
413
+ class DeletedPort(TypedDict):
414
+ """The answer of a delete: the names of its path."""
415
+ name: str
416
+ port: float
417
+ deleted: Literal[True]
@@ -0,0 +1,109 @@
1
+ Metadata-Version: 2.4
2
+ Name: shako-sdk
3
+ Version: 0.1.0
4
+ Summary: The Shako API for Python: VMs, ports, backups, secrets and credit, with an API key.
5
+ Project-URL: Homepage, https://shako.dev
6
+ Project-URL: Documentation, https://shako.dev/api
7
+ License-Expression: MIT
8
+ License-File: LICENSE
9
+ Keywords: api,cloud,sdk,shako,vm
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Typing :: Typed
15
+ Requires-Python: >=3.9
16
+ Description-Content-Type: text/markdown
17
+
18
+ # shako-sdk
19
+
20
+ The Shako API for Python: VMs, ports, backups, secrets, devices, credit and tenants, with an API key.
21
+
22
+ Each method is one endpoint of the REST API. `shako.vms.create(...)` is https://shako.dev/api/vms/create, and that
23
+ page has each field, its default and the answer.
24
+
25
+ ## Install
26
+
27
+ ```sh
28
+ pip install shako-sdk
29
+ ```
30
+
31
+ Python 3.9 or newer. The package needs no other packages.
32
+
33
+ ## API key
34
+
35
+ Make a key with the CLI, or in the workspace (https://workspace.shako.dev, Account settings › API keys). Shako shows
36
+ the key only once.
37
+
38
+ ```sh
39
+ shako api-key create ci --role contributor --tenant acme --days 90
40
+ export SHAKO_API_KEY=shk_k_...
41
+ ```
42
+
43
+ ## Use
44
+
45
+ ```python
46
+ from shako_sdk import Shako
47
+
48
+ shako = Shako() # the key from SHAKO_API_KEY
49
+
50
+ for vm in shako.vms.list():
51
+ print(vm["name"], vm["state"])
52
+
53
+ shako.vms.create(name="web1", size="small")
54
+ print(shako.ports.create("web1", port=8000)["url"])
55
+ print(shako.billing.usage()["total_cost"])
56
+ shako.vms.delete("web1")
57
+ ```
58
+
59
+ - `shako.<resource>.<endpoint>`: the resources and the endpoints of https://shako.dev/api, with `_` in place of `-`
60
+ (`shako.screen_links.create`, `shako.billing.top_up`).
61
+ - The args of the path are positional: `shako.vms.get("web1")`, `shako.ports.delete("web1", 8000)`.
62
+ - The fields of the query or the body are keyword args: `shako.vms.update("web1", sleep="never")`.
63
+ - An answer is a `dict`, and a list is a `list`. The types are in `shako_sdk.types` (for example `VmView`).
64
+
65
+ ## Tenant
66
+
67
+ A key for one tenant needs no tenant: the client reads it from `GET /v1/whoami` once. A key for your account
68
+ (`shako api-key create ops --role owner --account`) needs the tenant:
69
+
70
+ ```python
71
+ shako = Shako(tenant="acme") # each request
72
+ shako.vms.list(tenant="other") # one request
73
+ ```
74
+
75
+ ## Errors
76
+
77
+ An error answer raises `ShakoError`:
78
+
79
+ ```python
80
+ from shako_sdk import ShakoError
81
+
82
+ try:
83
+ shako.billing.top_up(amount=5)
84
+ except ShakoError as err:
85
+ print(err.code, err.status, err.message)
86
+ # forbidden 403 API key ci needs the role owner on acme for credit-add. See shako access ls, ...
87
+ ```
88
+
89
+ The codes: https://shako.dev/api/errors. When no answer comes, the code is `unreachable` and the status is 0.
90
+
91
+ ## An endpoint with no method
92
+
93
+ `shako.request("GET", "/v1/tenants/{tenant}/vms/{name}", {"name": "web1"})` sends any request, and returns the JSON
94
+ answer.
95
+
96
+ ## Options
97
+
98
+ `Shako(api_key=None, *, tenant=None, base_url=None, timeout=900)`
99
+
100
+ | Option | When it is missing |
101
+ |---|---|
102
+ | `api_key` | The environment variable `SHAKO_API_KEY`. |
103
+ | `tenant` | The tenant of the key, when the key has only one. |
104
+ | `base_url` | The environment variable `SHAKO_API`, then `https://api.shako.dev`. |
105
+ | `timeout` | 900 seconds for one request. A create waits until the VM boots. |
106
+
107
+ ## License
108
+
109
+ MIT
@@ -0,0 +1,11 @@
1
+ shako_sdk/__init__.py,sha256=-d-0r3RtUttR18QMbpAVpniUpS_PIS4U68V3LRDRwDk,270
2
+ shako_sdk/_base.py,sha256=Xm6IaFwWd6H4h9aGPKQ-Ocq3L33q6TPei9ibjiYGRL0,848
3
+ shako_sdk/_client.py,sha256=z3mya4a12O9BG9e_x6bGIy3iZ7TX7SssBZU_m09SvJY,5550
4
+ shako_sdk/_resources.py,sha256=PAlCuQpZ7ZAh4zpfK4ePknzq71rkGApZcfCHDuZiEfQ,21745
5
+ shako_sdk/_version.py,sha256=kUR5RAFc7HCeiqdlX36dZOHkUI5wI6V_43RpEcD8b-0,22
6
+ shako_sdk/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
+ shako_sdk/types.py,sha256=c8_V705HC3uDS50CVjyWQYCU6l2fe4d5NzF4YALYcZw,11371
8
+ shako_sdk-0.1.0.dist-info/METADATA,sha256=Jk5Rnb4MI-0ccqPIYrIAhQro832rcYYuNGFyH0g8h1E,3347
9
+ shako_sdk-0.1.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
10
+ shako_sdk-0.1.0.dist-info/licenses/LICENSE,sha256=CiS9-_-CD6IZnEpUBkG-KAZ4YADHp_Rxe5tU3PGR0Bo,1070
11
+ shako_sdk-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.27.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ShakoAI, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.