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
Using uv (recommended):
uv add chapkit
Or using pip:
pip install chapkit
Chapkit automatically installs servicekit as a dependency.
CLI Usage
Quickly scaffold a new ML service project using uvx:
uvx chapkit init <project-name>
Example:
uvx 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 management with Pydantic validation
├── artifact/ # Hierarchical storage for models and data
├── task/ # Reusable task templates (Python functions, shell commands)
├── ml/ # ML train/predict workflows
├── cli/ # CLI scaffolding tools
├── scheduler.py # Job scheduling integration
└── api/ # ServiceBuilder with ML integration
└── service_builder.py # .with_config(), .with_artifacts(), .with_ml()
Chapkit extends servicekit's BaseServiceBuilder with ML-specific features and domain modules for configuration, artifacts, tasks, and ML workflows.
Examples
See the examples/ directory for complete working examples:
quickstart/- Complete ML service with config, artifacts, and ML endpointsconfig_artifact/- Config with artifact linkingml_functional/,ml_class/,ml_shell/- ML workflow patterns (functional, class-based, shell-based)ml_pipeline/- Multi-stage ML pipeline with hierarchical artifactsartifact/- Read-only artifact API with hierarchical storagetask_execution/- Task execution with Python functions and shell commandsfull_featured/- Comprehensive example with monitoring, custom routers, and hookslibrary_usage/- Using chapkit as a library with custom modelscustom_migrations/- Database migrations with custom models
Documentation
See docs/guides/ for comprehensive guides:
- ML Workflows - Train/predict patterns and model runners
- Configuration Management - Config schemas and validation
- Artifact Storage - Hierarchical data storage for ML artifacts
- Task Execution - Python functions and shell command templates
- CLI Scaffolding - Project scaffolding with
chapkit init - Database Migrations - Custom models and Alembic migrations
Full documentation: https://dhis2-chap.github.io/chapkit/
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.5.2.tar.gz.
File metadata
- Download URL: chapkit-0.5.2.tar.gz
- Upload date:
- Size: 50.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cbf373aecc6b5c8aaa9dffdf357c3051910df1b504817af7d319de87ce4fec4d
|
|
| MD5 |
0f307f536cc1204e410fb80142f3454a
|
|
| BLAKE2b-256 |
2f32288a639c824d1b99d9053d9eef0826bfed52897ca3bf0f79b369829f2cd8
|
File details
Details for the file chapkit-0.5.2-py3-none-any.whl.
File metadata
- Download URL: chapkit-0.5.2-py3-none-any.whl
- Upload date:
- Size: 70.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d9b4705ba1a56e84a13ed045c93a05f1c7bc9910560d8a3f729cfba09a924f89
|
|
| MD5 |
b8cd4013dff79683eddebad22b14bd96
|
|
| BLAKE2b-256 |
36a8209065c74cd84d79108e71c43e72d0dad7f31b29e5bcf5b2fea0057bbfb9
|