Skip to content
DocsAll docs
Console

SDKs

Lists the methods of the Python, TypeScript, Go, Ruby, and Java clients.

Last updated

On this page

Install and import

LanguageInstall from the registryOr copy the sourceRequiresImportConstruct
Pythonpip install kode-sdkpython/kloudlite.py, one filePython 3.9 or laterfrom kloudlite import Kode, ApiErrorKloudlite()
TypeScriptnpm install @kloudlite/sdktypescript/index.ts, no build stepNode 20.16 or later, or Bun; ESMimport { Kode } from "@kloudlite/sdk"new Kloudlite()
Gogo get github.com/kloudlite/sdk/gosourceGo 1.24 or laterimport kloudlite "github.com/kloudlite/sdk/go"kloudlite.New(kloudlite.Options{})
Rubygem install kode-sdkruby/kloudlite.rb, one fileRuby 3.0 or laterrequire "kode"Kloudlite::Client.new
JavaMaven dependency io.kloudlite:kode-sdk:0.2.2java/Kloudlite.java, one fileJava 11 or laterimport io.kloudlite.Kode;new Kloudlite()

A copied TypeScript file is imported as ./index.ts, and a copied Ruby file as require_relative "kloudlite".

The distribution of the Python package is kode-sdk, and its import name is kode. The command pip install kloudlite installs a different package, the client of the model and dataset hub.

Secret references

An environment value refers to a secret of the owner as ${{ secrets.NAME }}. With the team as the owner, the secrets calls work on your own secrets in that team; give the scope team for the secrets of the team. The secrets API lists the routes that take a reference.

Pipeline definitions

The definition of pipelines.create and pipelines.update is plain data in the shape of Pipeline definition. Python takes a dict, Ruby a hash, and TypeScript an object. Go takes PipelineDefinition, which is raw JSON bytes, and Java takes a JSON string.

The order of jobs, inputs, and each matrix is part of the definition. Python, Ruby, and TypeScript keep the order that you write. Go and Java send the bytes that you give, so write the keys in the order that you want.

A save returns the pipeline with its version. rotate_webhook returns the new URL, which no later call shows.

Authentication and base URL

The SDK uses the login of kode, so a client needs no arguments. It takes the API origin and the token from the first source that has each, adds /v1 to the origin, and sends the token as Authorization: Bearer.

OrderSourceOriginToken
1The argument in codebase_url (baseUrl, BaseURL)token (Token)
2The environmentKODE_URLKODE_TOKEN
3The kode loginapi in config.jsontoken in config.json

config.json is in KODE_CONFIG_DIR, or in ~/.config/kode. For a CI job or a server with no kode, set KODE_URL and KODE_TOKEN. The token is a CLI login or an API token. An API token opens only the routes within its reach and grants. A pipeline run or a capsule that it starts is recorded under the name of the token.

With no token, the SDK stops with no Kode login: pass token=, set KODE_TOKEN, or run kode login. With a token and no origin, the sentence is no Kode API URL: …. The error type differs by language:

  • Python: RuntimeError, raised by Kloudlite().
  • TypeScript: Error, thrown by new Kloudlite().
  • Go: kloudlite.New returns no error. The first call returns it, and Client.Err() returns it at once.
  • Ruby: RuntimeError, raised by Kloudlite::Client.new.
  • Java: IllegalStateException, thrown by new Kloudlite().

Every request times out after 30 seconds. Set the limit with timeout (Python, Ruby), timeoutMs (TypeScript), or Options.Timeout (Go). Java has no setting for it.

Inputs, results, and errors

Every input is named. Python takes keyword-only arguments, Ruby keywords, TypeScript one options object, Go one request struct (kloudlite.CreateWorkspace{Workspace: …}), and Java a nested params class (new Kloudlite.CreateWorkspace().workspace(…)).

A workspace, environment, or desk is "name" for your own or "team/name" for a team's, or its id. Something new made from an existing one is to.

Every method returns the decoded JSON of the route, except the capsule and pipeline handles below. Java returns the raw JSON string from every method, except those two.

Errors, one per SDK:

  • Python: ApiError with status and message; CapsuleTerminated, a subclass, when a capsule that you wait for has ended.
  • TypeScript: ApiError with status and message; TimeoutError when a client-side wait runs out. A terminated capsule is an ApiError with status 409.
  • Go: *ApiError with Status and Message; ErrTimeout, tested with errors.Is, when a wait runs out. A terminated capsule is an *ApiError with status 409.
  • Ruby: Kode::ApiError with status and message; CapsuleTerminated < ApiError; TimeoutError when a wait runs out.
  • Java: Kode.ApiException, an IOException, with public status and message.

A missing required field is refused before anything is sent: ValueError in Python, an IllegalArgumentException in Java.

Methods

Resources hang off the client under these names: workspaces, environments, desks, volumes, secrets, connectors, capsules, and pipelines. Java reaches them as a call, kl.workspaces() and Go as the field kl.Workspaces. The ide, capsule, process, and run rows are on objects that those methods return. workspaces.ide returns the tool-server client. capsules.create, get, and list return capsule handles. pipelines.run and get_run return a run handle.

Python also has an .aio form of its calls for asyncio. Every cell is the method name in that language.

The tool-server rows call the tool server directly with the workspace's token, so they take the tool's own arguments. The SDKs have no method for these resources: teams, invites, keys, tokens, container images, requests, and regions.

Resource.methodpythontypescriptgorubyjavaRoute
client.quotaquotaquotaQuotaquotaquotaGET /v1/quota
client.requestrequestrequestRequestrequestrequestany route, your method and path
workspaces.createcreatecreateCreatecreatecreatePOST /v1/workspaces
workspaces.listlistlistListlistlistGET /v1/workspaces
workspaces.getgetgetGetgetgetGET /v1/workspaces/{id}
workspaces.deletedeletedeleteDeletedeletedeleteDELETE /v1/workspaces/{id}
workspaces.startstartstartStartstartstartPOST /v1/workspaces/{id}/start
workspaces.stopstopstopStopstopstopPOST /v1/workspaces/{id}/stop
workspaces.restartrestartrestartRestartrestartrestartPOST /v1/workspaces/{id}/restart
workspaces.take_snapshottake_snapshottakeSnapshotTakeSnapshottake_snapshottakeSnapshotPOST /v1/workspaces/{id}/snapshots
workspaces.cloneclonecloneClonecloneclonePOST /v1/workspaces/{id}/clone
workspaces.restorerestorerestoreRestorerestorerestorePOST /v1/workspaces/restore
workspaces.set_packagesset_packagessetPackagesSetPackagesset_packagessetPackagesPATCH /v1/workspaces/{id}
workspaces.set_ttlset_ttlsetTtlSetTTLset_ttlsetTtlPUT /v1/workspaces/{id}/ttl
workspaces.set_envset_envsetEnvSetEnvset_envsetEnvPUT /v1/workspaces/{id}/env
workspaces.update_packagesupdate_packagesupdatePackagesUpdatePackagesupdate_packagesupdatePackagesPOST /v1/workspaces/{id}/packages/update
workspaces.toolstoolstoolsToolstoolstoolsGET /v1/workspaces/{id}/tools
workspaces.ideideideIdeideideGET /v1/workspaces/{id}/tools, then a client for the tool server
ide.listlistlistListlistlistGET /tools
ide.callcallcallCallcallcallPOST /tools/{tool}
ide.readreadreadReadreadreadPOST /tools/read
ide.writewritewriteWritewritewritePOST /tools/write
ide.editediteditEditediteditPOST /tools/edit
ide.patchpatchpatchPatchpatchpatchPOST /tools/patch
ide.globglobglobGlobglobglobPOST /tools/glob
ide.grepgrepgrepGrepgrepgrepPOST /tools/grep
ide.execexecexecExecexecexecPOST /tools/exec
ide.process_listprocess_listprocessListProcessListprocess_listprocessListPOST /tools/process_list
ide.process_outputprocess_outputprocessOutputProcessOutputprocess_outputprocessOutputPOST /tools/process_output
ide.process_writeprocess_writeprocessWriteProcessWriteprocess_writeprocessWritePOST /tools/process_write
ide.process_killprocess_killprocessKillProcessKillprocess_killprocessKillPOST /tools/process_kill
ide.watchwatchwatchWatchwatchwatchPOST /tools/watch
ide.watch_pollwatch_pollwatchPollWatchPollwatch_pollwatchPollPOST /tools/watch_poll
ide.watch_stopwatch_stopwatchStopWatchStopwatch_stopwatchStopPOST /tools/watch_stop
ide.container_buildcontainer_buildcontainerBuildContainerBuildcontainer_buildcontainerBuildPOST /tools/container_build
ide.container_pushcontainer_pushcontainerPushContainerPushcontainer_pushcontainerPushPOST /tools/container_push
environments.createcreatecreateCreatecreatecreatePOST /v1/environments
environments.listlistlistListlistlistGET /v1/environments
environments.getgetgetGetgetgetGET /v1/environments/{id}
environments.set_servicesset_servicessetServicesSetServicesset_servicessetServicesPATCH /v1/environments/{id}
environments.startstartstartStartstartstartPOST /v1/environments/{id}/start
environments.stopstopstopStopstopstopPOST /v1/environments/{id}/stop
environments.restartrestartrestartRestartrestartrestartPOST /v1/environments/{id}/services/{service}/restart
environments.set_ttlset_ttlsetTtlSetTTLset_ttlsetTtlPUT /v1/environments/{id}/ttl
environments.deletedeletedeleteDeletedeletedeleteDELETE /v1/environments/{id}
environments.take_snapshottake_snapshottakeSnapshotTakeSnapshottake_snapshottakeSnapshotPOST /v1/environments/{id}/snapshots
environments.cloneclonecloneClonecloneclonePOST /v1/environments/{id}/clone
environments.restorerestorerestoreRestorerestorerestorePOST /v1/environments/{id}/restore
desks.createcreatecreateCreatecreatecreatePOST /v1/desks
desks.set_ttlset_ttlsetTtlSetTTLset_ttlsetTtlPUT /v1/desks/{id}/ttl
desks.listlistlistListlistlistGET /v1/desks
desks.getgetgetGetgetgetGET /v1/desks/{id}
desks.deletedeletedeleteDeletedeletedeleteDELETE /v1/desks/{id}
desks.stopstopstopStopstopstopPOST /v1/desks/{id}/stop
desks.startstartstartStartstartstartPOST /v1/desks/{id}/start
desks.connectconnectconnectConnectconnectconnectPUT /v1/desks/{id}/environment
desks.create_workspacecreate_workspacecreateWorkspaceCreateWorkspacecreate_workspacecreateWorkspacePOST /v1/desks/{id}/workspaces
desks.create_capsulecreate_capsulecreateCapsuleCreateCapsulecreate_capsulecreateCapsulePOST /v1/desks/{id}/capsules
desks.delete_workspacedelete_workspacedeleteWorkspaceDeleteWorkspacedelete_workspacedeleteWorkspaceDELETE /v1/desks/{id}/workspaces/{workspace}
desks.interceptinterceptinterceptInterceptinterceptinterceptPOST /v1/desks/{id}/intercepts
desks.releasereleasereleaseReleasereleasereleaseDELETE /v1/desks/{id}/intercepts/{service}
volumes.listlistlistListlistlistGET /v1/volumes
volumes.historyhistoryhistoryHistoryhistoryhistoryGET /v1/volumes/{key}/history
volumes.refsrefsrefsRefsrefsrefsGET /v1/volumes/{key}/refs
volumes.delete_snapshotdelete_snapshotdeleteSnapshotDeleteSnapshotdelete_snapshotdeleteSnapshotDELETE /v1/volumes/{key}/snapshots/{snapshot}
volumes.delete_by_iddelete_by_iddeleteByIdDeleteByIDdelete_by_iddeleteByIdDELETE /v1/volumes/{key}
volumes.getgetgetGetgetgetGET /v1/volumes/{key}/{name}
volumes.versionsversionsversionsVersionsversionsversionsGET /v1/volumes/{key}/{name}/versions
volumes.deletedeletedeleteDeletedeletedeleteDELETE /v1/volumes/{key}/{name}
volumes.delete_versiondelete_versiondeleteVersionDeleteVersiondelete_versiondeleteVersionDELETE /v1/volumes/{key}/{name}/versions/{n}
secrets.setsetsetSetsetsetPUT /v1/secrets/{owner}/mine/{name}
secrets.listlistlistListlistlistGET /v1/secrets/{owner}/mine
secrets.deletedeletedeleteDeletedeletedeleteDELETE /v1/secrets/{owner}/mine/{name}
connectors.listlistlistListlistlistGET /v1/connectors
connectors.deletedeletedeleteDeletedeletedeleteDELETE /v1/connectors/{name}
capsules.createcreatecreateCreatecreatecreatePOST /v1/capsules
capsules.getgetgetGetgetgetGET /v1/capsules/{id}
capsules.listlistlistListlistlistGET /v1/capsules; one page, limit, and cursor pick it
capsules.list_pagelist_pagelistPageListPagelist_pagelistPagethe page and the cursor of the next one
capsules.runrunrunRunrunruncreate, wait, logs, and terminate in one call; answers exit_code, stdout, stderr, and capsule
capsule handle.refreshrefreshrefreshRefreshrefreshrefreshGET /v1/capsules/{id}
capsule handle.wait_runningwait_runningwaitRunningWaitRunningwait_runningwaitRunningpolls GET /v1/capsules/{id}
capsule handle.logslogslogsLogslogslogsGET /v1/capsules/{id}/logs; follow holds until the process ends
capsule handle.exit_codeexit_codeexitCodeExitCodeexit_codeexitCodethe exit code once the command has ended; a property or field in Python, TypeScript, and Go
capsule handle.terminateterminateterminateTerminateterminateterminatePOST /v1/capsules/{id}/terminate
capsule handle.waitwaitwaitWaitwaitwaitForPOST /v1/capsules/{id}/wait; answers the exit code
capsule handle.deletedeletedeleteDeletedeletedeleteDELETE /v1/capsules/{id}
pipelines.createcreatecreateCreatecreatecreatePOST /v1/pipelines/{owner}
pipelines.updateupdateupdateUpdateupdateupdatePUT /v1/pipelines/{owner}/{name}
pipelines.listlistlistListlistlistGET /v1/pipelines/{owner}
pipelines.getgetgetGetgetgetGET /v1/pipelines/{owner}/{name}
pipelines.versionsversionsversionsVersionsversionsversionsGET /v1/pipelines/{owner}/{name}/versions
pipelines.deletedeletedeleteDeletedeletedeleteDELETE /v1/pipelines/{owner}/{name}
pipelines.runrunrunRunrunrunPOST /v1/pipelines/{owner}/{name}/runs
pipelines.rotate_webhookrotate_webhookrotateWebhookRotateWebhookrotate_webhookrotateWebhookPOST /v1/pipelines/{owner}/{name}/webhook/rotate
pipelines.runsrunsrunsRunsrunsrunsGET /v1/pipelines/{owner}/{pipeline}/runs
pipelines.get_runget_rungetRunGetRunget_rungetRunGET /v1/pipelines/{owner}/{pipeline}/runs/{run}
run handle.refreshrefreshrefreshRefreshrefreshrefreshGET /v1/pipelines/{owner}/{pipeline}/runs/{run}
run handle.cancelcancelcancelCancelcancelcancelPOST /v1/pipelines/{owner}/{pipeline}/runs/{run}/cancel
run handle.waitwaitwaitWaitwaitwaitForpolls GET /v1/pipelines/{owner}/{pipeline}/runs/{run}
run handle.logslogslogsLogslogslogsGET /v1/pipelines/{owner}/{pipeline}/runs/{run}/jobs/{index}/logs
run handle.followfollowfollowFollowfollowfollowGET /v1/pipelines/{owner}/{pipeline}/runs/{run}/jobs/{index}/logs, paged
ide.process_close_stdin—————POST /tools/process_close_stdin; reach it with call
ide.process_wait—————POST /tools/process_wait; reach it with call

Two tool-server tools have no typed method, process_close_stdin and process_wait; call reaches them in every language.

The capsule attach is a WebSocket and is not in the SDKs. attach raises an error in every language, so use kode capsules attach. The SDKs have no capsule exec, read, or write, and no process classes. capsules.run answers exit_code, stdout (stdout and stderr together), an empty stderr, and capsule.