Metadata-Version: 2.4
Name: shako-sdk
Version: 0.1.0
Summary: The Shako API for Python: VMs, ports, backups, secrets and credit, with an API key.
Project-URL: Homepage, https://shako.dev
Project-URL: Documentation, https://shako.dev/api
License-Expression: MIT
License-File: LICENSE
Keywords: api,cloud,sdk,shako,vm
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Typing :: Typed
Requires-Python: >=3.9
Description-Content-Type: text/markdown

# shako-sdk

The Shako API for Python: VMs, ports, backups, secrets, devices, credit and tenants, with an API key.

Each method is one endpoint of the REST API. `shako.vms.create(...)` is https://shako.dev/api/vms/create, and that
page has each field, its default and the answer.

## Install

```sh
pip install shako-sdk
```

Python 3.9 or newer. The package needs no other packages.

## API key

Make a key with the CLI, or in the workspace (https://workspace.shako.dev, Account settings › API keys). Shako shows
the key only once.

```sh
shako api-key create ci --role contributor --tenant acme --days 90
export SHAKO_API_KEY=shk_k_...
```

## Use

```python
from shako_sdk import Shako

shako = Shako()  # the key from SHAKO_API_KEY

for vm in shako.vms.list():
    print(vm["name"], vm["state"])

shako.vms.create(name="web1", size="small")
print(shako.ports.create("web1", port=8000)["url"])
print(shako.billing.usage()["total_cost"])
shako.vms.delete("web1")
```

- `shako.<resource>.<endpoint>`: the resources and the endpoints of https://shako.dev/api, with `_` in place of `-`
  (`shako.screen_links.create`, `shako.billing.top_up`).
- The args of the path are positional: `shako.vms.get("web1")`, `shako.ports.delete("web1", 8000)`.
- The fields of the query or the body are keyword args: `shako.vms.update("web1", sleep="never")`.
- An answer is a `dict`, and a list is a `list`. The types are in `shako_sdk.types` (for example `VmView`).

## Tenant

A key for one tenant needs no tenant: the client reads it from `GET /v1/whoami` once. A key for your account
(`shako api-key create ops --role owner --account`) needs the tenant:

```python
shako = Shako(tenant="acme")     # each request
shako.vms.list(tenant="other")   # one request
```

## Errors

An error answer raises `ShakoError`:

```python
from shako_sdk import ShakoError

try:
    shako.billing.top_up(amount=5)
except ShakoError as err:
    print(err.code, err.status, err.message)
    # forbidden 403 API key ci needs the role owner on acme for credit-add. See shako access ls, ...
```

The codes: https://shako.dev/api/errors. When no answer comes, the code is `unreachable` and the status is 0.

## An endpoint with no method

`shako.request("GET", "/v1/tenants/{tenant}/vms/{name}", {"name": "web1"})` sends any request, and returns the JSON
answer.

## Options

`Shako(api_key=None, *, tenant=None, base_url=None, timeout=900)`

| Option | When it is missing |
|---|---|
| `api_key` | The environment variable `SHAKO_API_KEY`. |
| `tenant` | The tenant of the key, when the key has only one. |
| `base_url` | The environment variable `SHAKO_API`, then `https://api.shako.dev`. |
| `timeout` | 900 seconds for one request. A create waits until the VM boots. |

## License

MIT
