Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

kainguru-sdk

Python SDK for the Kainguru ML platform — run models and fine-tune them from any Python application.

  • Python 3.10+
  • Sync and async clients with an identical surface (KainguruClient, AsyncKainguruClient)
  • Typed pydantic v2 models
  • Built-in polling with configurable timeout and backoff
  • Automatic retry on 429 / 5xx with exponential backoff (honors Retry-After)

Covers /v1/executions and /v1/fine-tuning.


Installation

pip install kainguru-sdk

Import name is kainguru:

from kainguru import KainguruClient

Authentication

You must pass both an API key and the base URL explicitly. The API key is issued from the Kainguru Dashboard (it begins with kg_); the base URL is the full host including the /api context path:

from kainguru import KainguruClient

client = KainguruClient(
    api_key="kg_your_api_key",
    base_url="https://your-host/api",
)

Both fields are required. If either is missing or blank, the constructor raises KainguruConfigError (fail fast). There are no defaults, environment presets, or environment-variable fallbacks.

KainguruClient is a context manager — use with to close the HTTP pool automatically.


Quick start (sync)

from kainguru import KainguruClient

with KainguruClient(
    api_key="kg_your_api_key",
    base_url="https://your-host/api",
) as client:
    submitted = client.executions.execute(
        "my-mlflow-id",
        {"prompt": "hello world"},
        output_format="json",
    )

    done = client.executions.await_completion(submitted.id)

    print(done.status)              # ModelStatus.COMPLETED / FAILED
    print(done.execution.output)    # model output

ml_flow_id (first positional arg) is the model's MLflow id — the identifier the Dashboard shows for the model.

Quick start (async)

import asyncio
from kainguru import AsyncKainguruClient


async def main():
    async with AsyncKainguruClient(
        api_key="kg_your_api_key", base_url="https://your-host/api"
    ) as client:
        submitted = await client.executions.execute(
            "my-mlflow-id", {"prompt": "hello world"}, output_format="json"
        )
        done = await client.executions.await_completion(submitted.id)
        print(done.status)


asyncio.run(main())

Executions API

exec = client.executions

# Run a model (returns immediately, typically PENDING)
pending = exec.execute(ml_flow_id, input, output_format=None, exec_id=None)

# Poll the current status once
current = exec.get(id)

# Block until COMPLETED or FAILED (default: 2 s interval, 5 min timeout)
done = exec.await_completion(id)

# Block with custom poll options
done = exec.await_completion(id, poll_interval=1.0, timeout=60.0)

Terminal statuses: COMPLETED, FAILED. REGISTERED is treated as non-terminal. A FAILED job returns from await_completion — inspect dto.status; it is not raised.


Fine-Tuning API

ft = client.fine_tuning

# Start fine-tuning
pending = ft.execute(model_id, "my-fine-tuned-variant", input)

# Get status / poll until done
current = ft.get_status(id)
done = ft.await_completion(id)

(The async client exposes the same methods with await.)


Polling options

client.executions.await_completion(
    id,
    poll_interval=2.0,   # base interval between polls in s (default 2.0)
    timeout=300.0,       # total wall-clock timeout in s (default 300.0)
    backoff=1.5,         # multiply interval each attempt (default 1.0 = fixed)
    max_interval=30.0,   # cap on interval after backoff (default 30.0)
)

On timeout, await_completion raises KainguruTimeoutError, which carries the last DTO seen via err.last_dto.


Configuration

client = KainguruClient(
    api_key="kg_...",                    # required, explicit key
    base_url="https://your-host/api",    # required, full host incl. /api context path
    timeout=30.0,                        # per-request timeout in s
    max_retries=3,                       # retries on 429 / 5xx / network
    debug=True,                          # verbose request/response logging (default False)
)

Both api_key and base_url are required and must be passed explicitly — there are no defaults or environment-variable fallbacks. The base URL must be the full host including the dashboard's /api context path.

Every method also accepts a per-request api_key= to override the client key for one call.

Debug logging

Pass debug=True to trace every request and response on the kainguru logger (the X-API-Key header is redacted). If your app hasn't configured that logger, the SDK attaches a stderr handler at DEBUG level so the traces are visible out of the box. Keep it off in production — request and response bodies are logged in full.


Error handling

All errors extend KainguruError.

Error When
KainguruConfigError Missing/invalid configuration (e.g. no API key)
KainguruAPIError Non-2xx HTTP response, or success=false in the body. Has status_code, body, api_code
KainguruAuthError 401 / 403 (subclass of KainguruAPIError)
KainguruNotFoundError 404 (subclass of KainguruAPIError)
KainguruRateLimitError 429 (subclass of KainguruAPIError); exposes retry_after
KainguruTimeoutError await_completion exceeded timeout; carries last_dto
KainguruConnectionError Network / transport failure; chained via from
from kainguru import (
    KainguruAPIError,
    KainguruNotFoundError,
    KainguruTimeoutError,
)

try:
    result = client.executions.await_completion(id)
    if result.status.value == "FAILED":
        ...  # FAILED is returned, not raised — inspect the result
except KainguruNotFoundError as e:
    print("not found:", e.status_code)
except KainguruAPIError as e:
    print(f"HTTP {e.status_code}: {e.body}")
except KainguruTimeoutError as e:
    print("timed out; last:", e.last_dto)

The SDK automatically retries 429 and 5xx responses up to 3 times with exponential backoff (base 1 s, doubling per attempt); Retry-After headers are respected.


Limitations (v0.1.0)

  • Cancel endpoints are not exposed yet (they require JWT/Keycloak auth, not an API key).
  • input parameters are untyped (dict[str, Any]).
  • output_format is a free str; allowed values are not yet enumerated by the backend.

Building or publishing the SDK yourself? See MAINTAINERS.md.

Metadata

Release files for kainguru-sdk 0.2.14.dev0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for kainguru-sdk 0.2.14.dev0
File Size Uploaded Provenance
kainguru_sdk-0.2.14.dev0.tar.gz 22.3 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for kainguru-sdk 0.2.14.dev0
File Interpreter ABI Platform
kainguru_sdk-0.2.14.dev0-py3-none-any.whl Python 3 none any Details

Total release size: 42.6 kB

Release files / kainguru_sdk-0.2.14.dev0.tar.gz

Download URL kainguru_sdk-0.2.14.dev0.tar.gz
Size 22.3 kB
Tags Source
SHA-256 checksum
How to use checksums
2125fbdbcc350b99fbd78f5e0576fdfac1ee0ebe12c5491189910ed610e94597
BLAKE2b-256 checksum
How to use checksums
5e2f8704f3b8bac5bc0780d3f15e87fe5935f284f6f3abf8eb85055243b2404c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 16, 2026.

Transparency log

Release files / kainguru_sdk-0.2.14.dev0-py3-none-any.whl

Download URL kainguru_sdk-0.2.14.dev0-py3-none-any.whl
Size 20.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0eca9b809d9ba19672b607b5cfe4da69a6de37e6510bd9538cbb0a4fd7254a5a
BLAKE2b-256 checksum
How to use checksums
35e57623940332eacdc9d1cee768727b59a091b49702e266e74851837be06231
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 16, 2026.

Transparency log

Security for kainguru-sdk 0.2.14.dev0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for kainguru_sdk-0.2.14.dev0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 16, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page