Skip to content

Python API

The package root exports the supported API. Everything else, including adapters and container internals, is private and can change without notice.

from mlbundle import (
FORMAT_NAME, # "mlbundle"
FORMAT_VERSION, # "1"
ArchiveLimits,
LoadedBundle,
Manifest,
MetadataView,
OutputPrediction,
export,
inspect,
load,
)

Model records are strict, frozen Pydantic models: they reject unknown fields and type coercion.

def export(
model: object,
destination: str | PathLike[str],
*,
training_data: object | None = None,
feature_names: Sequence[str] | None = None,
class_labels: Sequence[Sequence[Label]] | None = None,
target_names: Sequence[str] | None = None,
sample_rows: int | None = None,
onehot_separator: str = "__",
metadata: Mapping[str, JsonValue] | None = None,
overwrite: bool = False,
limits: ArchiveLimits | None = None,
) -> MetadataView

Publishes a bundle only after its claims survive a native serialization round trip and the reader validates it. Requires the schema extra. Label is a JSON scalar class label. Every argument is described in Export a bundle.

def inspect(source: BundleSource, *, limits: ArchiveLimits | None = None) -> MetadataView

Validates the container, manifest, JSON bounds, hashes, schema and samples without importing a model library. It cannot attest model-derived claims.

def load(source: BundleSource, *, limits: ArchiveLimits | None = None) -> LoadedBundle

Everything inspect does, then deserializes through the closed adapter and verifies recomputed claims and structure. BundleSource is str | PathLike[str] | bytes | BinaryIO.

Frozen dataclass returned by export and inspect.

Field Type
manifest Manifest
members tuple[MemberName, ...], in canonical order
schema dict[str, JsonValue] | None
samples list[dict[str, JsonValue]] | None

Frozen dataclass returned by load, constructed only after verification.

Member Type / behaviour
manifest, members, schema, samples As in MetadataView.
structure dict[str, JsonValue] | None
native_model The native model object.
predictor The adapter’s uniform predictor.
kind ModelKind
library Library
class_name str, the estimator class
feature_names tuple[str, ...]
feature_origin FeatureOrigin
class_labels list[list[Label]] | None, output-major
predict_proba(data) list, classifiers only; otherwise ValueError
predict(data) list[float] or rows of floats, regressors only; otherwise ValueError
row_from_record(record) list[float] in feature order
predict_record(record) tuple[OutputPrediction, ...], one per output

Frozen dataclass with output, kind, labels, probabilities, value and predicted_label. See Records and predictions.

Class Fields
Manifest format_name, format_version, bundle_id, created_at, writer_version, model, features, target, environment, integrity, references, user_metadata
ModelInfo estimator_class, kind, hyperparameters, n_features, n_classes, n_outputs, library, serialization, pipeline and state fields
FeatureInfo names, dtypes (training), model_dtypes (verified), origin
TargetInfo class_labels, names
TrainingEnvironment python_version, python_implementation, os, os_version, architecture, packages, onnx
OnnxInfo, Opset ONNX opsets, IR version and producer
IntegrityRecord sha256, size
MemberReferences schema, structure, samples
ModelClaims The model-derived claims the reader recomputes

Field types and verification rules are normative in Format 1.

All are StrEnums whose values appear in the manifest.

Enum Values
Library sklearn, xgboost, catboost, onnx
ModelKind classifier, regressor
SerializationFormat skops, ubjson, cbm, onnx, pipeline
FeatureOrigin model, dataframe, declared, generated
MemberName manifest.json, model.skops, model.ubj, model.cbm, model.onnx, schema.json, structure.json, samples.json

ArchiveLimits lowers the safety ceilings. Every exception mlbundle raises for a bundle or model derives from MLBundleError; see Errors.

mlbundle.__version__ is the installed package version.