The k7-sdk PyPI package (import k7_sdk) wraps the K7 HTTP API in two clients. The legacy katakate name still installs but emits a deprecation warning.
Client — synchronous, backed by requests.
AsyncClient — asyncio-native, backed by httpx.
Install
The async client raises RuntimeError at construction time if httpx isn’t installed.
Quickstart
Discover the endpoint with k7 api endpoint and the key with k7 generate-api-key <name>. See the CLI guide for full details.
Client reference
SandboxProxy (returned by create) exposes:
exec(command: str) -> dict — {exit_code, stdout, stderr, duration_ms}
delete() -> dict — shorthand for client.delete(name, namespace)
pause / resume / fork — same as the client methods, scoped to this sandbox
snapshot(name) — named VolumeSnapshot without pausing
The proxy keeps a reference to the Client, so calling sb.exec(...) after the parent client closes will raise.
All sandbox config fields
The create() payload accepts every field from the API schema. Common ones:
See Sandboxes API for the full table.
env_file points to a path on the API node, not the client. To inject runtime env vars from the client, build them into your before_script (echo "KEY=value" > /etc/sandbox.env) or commit them to your sandbox image.
Wait until ready
The API returns immediately after creating Kubernetes objects; the pod schedules and boots in the background. A small polling helper:
Pause, resume, fork
pause, resume, and fork work on Client and on the SandboxProxy from create. Behavior depends on the backend:
kata-qemu-longhorn — fork clones the root disk via Longhorn VolumeSnapshot (the fork cold-boots, ~45 s); pause/resume scale the Deployment and the PVC survives.
k7d — fork is a warm CoW copy of the whole VM (memory + disk + processes, ~5 ms at the VMM, ~2 s end-to-end to a Ready pod); pause/resume freeze and thaw the live VM in place. Works for sandboxes on any node — the API forwards to the per-node k7-agent when needed.
See Snapshots & fork for timing notes and CLI equivalents.
Snapshots and restore
Full HTTP detail: Snapshots API.
Async client
AsyncClient mirrors the sync client surface (create, list, delete, delete_all, exec, get_metrics, aclose). Note that AsyncClient.exec is a top-level method (await k7.exec(name, command)) rather than a proxy method.
Concurrent sandbox fan-out
Errors
requests.HTTPError / httpx.HTTPStatusError are raised on non-2xx responses. The error body follows the API envelope:
Recover the structured error:
Tips
- Always pass
namespace= if you use anything other than default.
- Rotate API keys with
k7 revoke-api-key <name> and k7 generate-api-key <name>.
- The same operations are available via CLI (
k7 pause, k7 fork, k7 snapshot, k7 restore) — default CLI path is the HTTP API; use --core only on the cluster node.