ML and data service modules built on servicekit - config, artifacts, tasks, and ML workflows
Project description
Chapkit
ML service modules built on servicekit - config, artifact, task, and ML workflows
Chapkit provides domain-specific modules for building machine learning services on top of servicekit's core framework. Includes artifact storage, task execution, configuration management, and ML train/predict workflows.
Features
- Artifact Module: Hierarchical storage for models, data, and experiment tracking with parent-child relationships
- Task Module: Reusable command templates for shell and Python task execution with parameter injection
- Config Module: Key-value configuration with JSON data and Pydantic validation
- ML Module: Train/predict workflows with artifact-based model storage and timing metadata
- Config-Artifact Linking: Connect configurations to artifact hierarchies for experiment tracking
Installation
pip install chapkit
Chapkit automatically installs servicekit as a dependency.
CLI Usage
Quickly scaffold a new ML service project using uvx:
uvx chapkit@git+https://github.com/dhis2-chap/chapkit init <project-name>
Example:
uvx chapkit@git+https://github.com/dhis2-chap/chapkit init my-ml-service
Options:
--path <directory>- Target directory (default: current directory)--monitoring- Include Prometheus and Grafana monitoring stack
This creates a ready-to-run ML service with configuration, artifacts, and ML endpoints pre-configured.
Quick Start
from chapkit import ArtifactHierarchy, BaseConfig
from chapkit.api import ServiceBuilder, ServiceInfo
class MyConfig(BaseConfig):
model_name: str
threshold: float
app = (
ServiceBuilder(info=ServiceInfo(display_name="ML Service"))
.with_health()
.with_config(MyConfig)
.with_artifacts(hierarchy=ArtifactHierarchy(name="ml", level_labels={0: "model"}))
.with_jobs()
.build()
)
Modules
Config
Key-value configuration storage with Pydantic schema validation:
from chapkit import BaseConfig, ConfigManager
class AppConfig(BaseConfig):
api_url: str
timeout: int = 30
# Automatic validation and CRUD endpoints
app.with_config(AppConfig)
Artifacts
Hierarchical storage for models, data, and experiment tracking:
from chapkit import ArtifactHierarchy, ArtifactManager, ArtifactIn
hierarchy = ArtifactHierarchy(
name="ml_pipeline",
level_labels={0: "experiment", 1: "model", 2: "evaluation"}
)
# Store pandas DataFrames, models, any Python object
artifact = await artifact_manager.save(
ArtifactIn(data=trained_model, parent_id=experiment_id)
)
ML
Train and predict workflows with automatic model storage:
from chapkit.ml import FunctionalModelRunner
import pandas as pd
async def train_model(config: MyConfig, data: pd.DataFrame, geo=None):
"""Train your model - returns trained model object."""
from sklearn.linear_model import LinearRegression
model = LinearRegression()
model.fit(data[["feature1", "feature2"]], data["target"])
return model
async def predict(config: MyConfig, model, historic: pd.DataFrame, future: pd.DataFrame, geo=None):
"""Make predictions - returns DataFrame with predictions."""
predictions = model.predict(future[["feature1", "feature2"]])
future["predictions"] = predictions
return future
# Wrap functions in runner
runner = FunctionalModelRunner(on_train=train_model, on_predict=predict)
app.with_ml(runner=runner)
Architecture
chapkit/
├── config/ # Configuration module
├── ml/ # ML train/predict workflows
└── api/ # ServiceBuilder with ML integration
└── service_builder.py # .with_config(), .with_ml()
Chapkit extends servicekit's BaseServiceBuilder with ML-specific features and uses servicekit's artifact and task modules.
Examples
See the examples/ directory:
quickstart.py- Complete ML serviceconfig_artifact_api.py- Config with artifact linkingml_basic.py,ml_class.py- ML workflow patterns
Documentation
See docs/ for comprehensive guides:
- ML workflow guide
Testing
make test # Run tests
make lint # Run linter
make coverage # Test coverage
License
AGPL-3.0-or-later
Related Projects
- servicekit - Core framework foundation (FastAPI, SQLAlchemy, CRUD, auth, etc.) (docs)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file chapkit-0.4.5.tar.gz.
File metadata
- Download URL: chapkit-0.4.5.tar.gz
- Upload date:
- Size: 38.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b7fb13fd23136fef68fa82409247dd846efa0e035abb40733e3db6064d0ae43e
|
|
| MD5 |
54f8f831f67bbf3f9591ea8ea0907c2f
|
|
| BLAKE2b-256 |
6c8aa1676cb70fbf1a2d21637918810bcea5d1c61c535cdf042f091e5c09eab3
|
File details
Details for the file chapkit-0.4.5-py3-none-any.whl.
File metadata
- Download URL: chapkit-0.4.5-py3-none-any.whl
- Upload date:
- Size: 56.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cb25098e808eb928201fcdc22283f36ae43d729537b58c329c448cfdd92cd2ef
|
|
| MD5 |
6f2d5c1f2c9887fdb7d516e4a78b71d9
|
|
| BLAKE2b-256 |
249312af16241a4cd8c53f973deb792be460302bda64859d5a35250381785c7b
|