Skip to content

About

Kasm Workspaces SDK for Python

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

kasm-sdk (Python)

Python client for the Kasm Workspaces API, generated from the official OpenAPI spec.

pip install kasm-sdk
from kasm_sdk import Kasm, NotFoundError

kasm = Kasm("https://kasm.example.com", api_key=key, api_secret=secret)
img = kasm.admin.catalog.images.get(image_id)
kasm.admin.catalog.file_mappings.update(file_map_id, description=None)   # None clears it
for zone in kasm.admin.infrastructure.zones.iter():
    print(zone.zone_name)

The client's attributes follow kcli's command tree (kcli admin catalog images get is kasm.admin.catalog.images.get). Path parameters are positional; the request body's fields and the query parameters are keyword arguments. The whole body can also be passed, as a model from kasm_sdk.models or a dict, with keyword arguments over it. A method returns the success reply as its Pydantic model, or None for an operation that replies with none. Paged lists also have iter, which walks every page, numbered from 0 as in the API.

A keyword argument left out leaves the field out; None sends null, and is refused before sending where the API does not take null. The models check their constraints before sending too (pydantic.ValidationError). A multipart body takes bytes, a path, a binary file, or (filename, content) for its file fields.

Every non-2xx reply raises a KasmError subclass by status (NotFoundError, ConflictError, ValidationError, ForbiddenError, ServerError, ...) carrying the problem+json fields, field-level errors from a 422, and the response headers. A problem type whose schema adds fields has a class of its own under its status's (NoResourcesError is a ConflictError), with problem its model. A failure before any reply raises KasmConnectionError, and a 2xx reply that is not the JSON the spec declares, including null, raises KasmResponseError. A reply field the models do not know is kept, in model_extra. Printing a model masks its secret fields (api_key_secret, password, ...); the values themselves are plain strings.

Kasm.from_profile("staging") uses a profile kcli is set up with, through kcli config credentials: kcli supplies the URL, timeout and TLS setting and the credential, and renews a password profile's session token. Kasm() with no arguments is the environment's (KASM_URL, KASM_API_KEY, KASM_API_KEY_SECRET) when it gives all three, otherwise the active profile.

AsyncKasm has the same methods, awaited, with async for over iter; both clients are context managers. token= authenticates with a session token, and token_source= with an object whose token() is asked for a fresh token once after a 401. Kasm.login(base_url, username, password) signs in and returns a client acting as that user, which the self-service operations need. kasm.request sends any operation by method and path. retries=N sends a GET, PUT or DELETE refused with 429 or 503 again, up to N times, after the server's Retry-After.

kasm_sdk/_services.py (the methods), kasm_sdk/_schema.py, kasm_sdk/_problems.py (the problem types' classes) and kasm_sdk/models.py (from datamodel-code-generator) are generated and never hand-edited. The tests are pytest in this directory.

About this repository

This package is generated from the Kasm Workspaces OpenAPI spec, in the same run as the TypeScript and Go SDKs, and published here from Kasm's kcli repository: one commit and one vX.Y.Z tag per release, and anything changed here directly is overwritten by the next. kcli and the three SDKs share a version number. They are 0.x: no compatibility promise until the API surface settles.

Licensed under the Apache License 2.0.

About

Kasm Workspaces SDK for Python

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages