Skip to content

Quick start

This walkthrough uses scikit-learn. Install mlbundle[sklearn,schema] on Python 3.14 as described in Installation.

train.py
from sklearn.tree import DecisionTreeClassifier
from mlbundle import export
rows = [[0.0, 1.0], [1.0, 0.0], [0.1, 0.9], [0.9, 0.1]]
model = DecisionTreeClassifier(random_state=7).fit(rows, ["cold", "warm"] * 2)
view = export(model, "trained.mlbundle", feature_names=["temperature", "humidity"])
print([member.value for member in view.members])
# ['manifest.json', 'model.skops', 'schema.json', 'structure.json']

export serializes the model with skops, loads it back, recomputes its claims and structure, and only then publishes the file. A model with types outside mlbundle’s allowlist fails here, on the training machine, not after upload. An existing destination needs overwrite=True.

The model was fitted on plain lists, so it has no native feature names: the names you pass are recorded as declared. No training data was given, so the schema comes from one synthetic row.

from mlbundle import inspect
view = inspect("trained.mlbundle")
print(view.manifest.model.library, view.manifest.model.estimator_class)
# sklearn DecisionTreeClassifier
print(view.manifest.features.names, view.manifest.features.origin)
# ['temperature', 'humidity'] declared
print(view.schema["reports"][0]["labels"]) # ['cold', 'warm']

inspect validates the archive, the manifest, every non-manifest member’s hash and the schema, without importing scikit-learn or deserializing anything. It therefore cannot tell you whether the metadata describes the model. The command line does the same:

Terminal window
mlbundle inspect trained.mlbundle
from mlbundle import load
bundle = load("trained.mlbundle")
print(bundle.kind, bundle.class_name, bundle.class_labels)
# classifier DecisionTreeClassifier [['cold', 'warm']]
print(bundle.predict_proba([[0.0, 1.0]])) # [[1.0, 0.0]]

load performs every inspect check, deserializes through the scikit-learn adapter, recomputes the hyperparameters, counts, labels and tree, and raises ClaimMismatchError if any of them differs from the manifest or structure.json. Classifiers use predict_proba, regressors predict; both return plain lists. Probabilities are output-major: one matrix per output, which for a single output is the matrix itself.

bundle.native_model is the real DecisionTreeClassifier, for native inference or explanations. Mutating it invalidates what was verified.

Forms and APIs send values keyed by name. Records use the schema’s mappings: positions for this model, because its names were declared rather than native.

result = bundle.predict_record({"0": "0.0", "1": "true"})[0]
print(result.labels, result.probabilities, result.predicted_label)
# ('cold', 'warm') (1.0, 0.0) cold

Strings are parsed strictly, every feature is required, and predicted_label is the model’s own class decision. See Records and predictions.

Terminal window
mlbundle verify trained.mlbundle
Valid bundle: sklearn "DecisionTreeClassifier"; verified format, integrity, schema/samples and native model claims/structure.