Skip to main content

A Python client to interact with the KappaML platform

Project description

PyPI version PyPI downloads License

KappaML Python Client

Python client to interact with the KappaML platform 🐍

This SDK provides a simple interface for creating, training, and managing online machine learning models.

Platform: https://kappaml.com API Keys: https://app.kappaml.com/api-keys API Documentation: https://api.kappaml.com/docs OpenAPI Schema: https://api.kappaml.com/openapi.json

Installation

pip install kappaml

Quick Start

from kappaml import KappaML

# Initialize the client
client = KappaML(api_key="your_api_key")  # Or set KAPPAML_API_KEY env variable

# Create a new model
model_id = client.create_model(
    name="my-regression-model",
    ml_type="regression"
)

# Train the model with a single data point
client.learn(
    model_id=model_id,
    features={"x1": 1.0, "x2": 2.0},
    target=3.0
)

# Make predictions
prediction = client.predict(
    model_id=model_id,
    features={"x1": 1.5, "x2": 2.5}
)

# Get model metrics
metrics = client.get_metrics(model_id)

# Clean up
client.delete_model(model_id)

API Reference

KappaML Class

Constructor

client = KappaML(api_key: Optional[str] = None)
  • api_key: Your KappaML API key. If not provided, will look for KAPPAML_API_KEY environment variable.

Methods

create_model
def create_model(
    name: str,
    ml_type: str,
    wait_for_deployment: bool = True,
    timeout: int = 60
) -> str

Creates a new model on KappaML.

  • name: Name of the model
  • ml_type: Type of ML task ('regression' or 'classification')
  • wait_for_deployment: Whether to wait for model deployment to complete
  • timeout: Maximum time to wait for deployment in seconds
  • Returns: The model ID
learn
def learn(
    model_id: str,
    features: Dict[str, Any],
    target: Union[float, int, str]
) -> Dict[str, Any]

Train the model with a single data point.

  • model_id: The model ID
  • features: Dictionary of feature names and values
  • target: The target value to learn from
  • Returns: Response from the learning API
predict
def predict(
    model_id: str,
    features: Dict[str, Any]
) -> Dict[str, Any]

Make predictions using a model.

  • model_id: The model ID
  • features: Dictionary of feature names and values
  • Returns: Model predictions
get_metrics
def get_metrics(model_id: str) -> Dict[str, Any]

Get current metrics for a model.

  • model_id: The model ID
  • Returns: Model metrics
delete_model
def delete_model(model_id: str) -> None

Delete a model.

  • model_id: The model ID to delete

Error Handling

The SDK defines several exception classes for handling errors:

  • KappaMLError: Base exception for all SDK errors
  • ModelNotFoundError: Raised when a model is not found
  • ModelDeploymentError: Raised when model deployment fails or times out

Example error handling:

from kappaml import KappaML, ModelNotFoundError

client = KappaML()

try:
    metrics = client.get_metrics("non-existent-model")
except ModelNotFoundError:
    print("Model not found!")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kappaml-1.1.0.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kappaml-1.1.0-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file kappaml-1.1.0.tar.gz.

File metadata

  • Download URL: kappaml-1.1.0.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.12

File hashes

Hashes for kappaml-1.1.0.tar.gz
Algorithm Hash digest
SHA256 0480f6d6782bde26d4d8232a0352fc83cf2a9b26a0925fcc72a9607a53a1b5bc
MD5 d8eda1587b4cbdaa6a4171e7018bcf0c
BLAKE2b-256 0edf4bc30471e8479afc5b53f29632fdb62808ac5c9b9be6b281faacaea3b608

See more details on using hashes here.

File details

Details for the file kappaml-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: kappaml-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.12

File hashes

Hashes for kappaml-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e825d01d2b868aedef6bf33adf0fb3b03447f5bae9063fb19209e80806457376
MD5 6fbce769aaef294d5ef24e56b16217b9
BLAKE2b-256 2a368d1ab1a4bb81d5c68ad5c4ab8f0b4ae053dcfcb2161ba9038687a568dda8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page