dataenginex.ml
Classical ML — training, registry, drift, serving, metrics.
LLM / vectorstore / scheduling live in dataenginex.ai and
dataenginex.orchestration respectively.
Public API::
from dataenginex.ml import (
BaseTrainer, SklearnTrainer, TrainingResult,
ModelRegistry, ModelArtifact, ModelStage,
MLflowModelRegistry, MLflowRegistryError,
DriftDetector, DriftReport,
ModelServer, PredictionRequest, PredictionResponse,
model_prediction_total, model_prediction_latency_seconds,
model_drift_psi, model_drift_alerts_total,
)
DriftDetector
Detect distribution drift between a reference and current dataset.
PSI thresholds (industry standard): < 0.10 — no significant drift 0.10-0.25 — moderate drift > 0.25 — significant drift
Parameters
psi_threshold: PSI value above which drift is flagged (default 0.20). n_bins: Number of histogram bins for PSI calculation (default 10).
Source code in src/dataenginex/ml/drift.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | |
check_feature(feature_name, reference, current)
Check drift for a single numeric feature.
Source code in src/dataenginex/ml/drift.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | |
check_dataset(reference, current)
Check drift across all shared features in two datasets.
Parameters
reference:
Mapping of feature_name → values for the reference period.
current:
Mapping of feature_name → values for the current period.
Source code in src/dataenginex/ml/drift.py
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | |
DriftReport
dataclass
Outcome of a drift check for a single feature.
Attributes:
| Name | Type | Description |
|---|---|---|
feature_name |
str
|
Name of the feature that was checked. |
psi |
float
|
Population Stability Index value. |
drift_detected |
bool
|
Whether drift exceeds the configured threshold. |
severity |
str
|
Drift severity — |
reference_mean |
float | None
|
Mean of the reference distribution. |
current_mean |
float | None
|
Mean of the current distribution. |
reference_std |
float | None
|
Standard deviation of reference distribution. |
current_std |
float | None
|
Standard deviation of current distribution. |
details |
dict[str, Any]
|
Extra context (bins, threshold, etc.). |
checked_at |
datetime
|
Timestamp of the drift check. |
Source code in src/dataenginex/ml/drift.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | |
to_dict()
Serialize the drift report to a plain dictionary.
Source code in src/dataenginex/ml/drift.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 | |
MLflowModelRegistry
MLflow-backed model registry compatible with ModelRegistry.
Parameters
tracking_uri:
MLflow tracking server URI. Defaults to MLFLOW_TRACKING_URI
env var or http://localhost:5000.
Source code in src/dataenginex/ml/mlflow_registry.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 | |
register(artifact)
Register a model version in MLflow and log its run metadata.
Source code in src/dataenginex/ml/mlflow_registry.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | |
get(name, version)
Fetch a model version from MLflow.
Source code in src/dataenginex/ml/mlflow_registry.py
117 118 119 120 121 122 123 124 | |
get_latest(name)
Return the highest version number for name regardless of stage.
Source code in src/dataenginex/ml/mlflow_registry.py
126 127 128 129 130 131 132 133 134 135 136 137 | |
get_production(name)
Return the model currently aliased as production.
Source code in src/dataenginex/ml/mlflow_registry.py
139 140 141 142 143 144 145 146 | |
list_models()
Return all registered model names.
Source code in src/dataenginex/ml/mlflow_registry.py
148 149 150 151 152 153 154 | |
list_versions(name)
Return all version strings for name.
Source code in src/dataenginex/ml/mlflow_registry.py
156 157 158 159 160 161 162 | |
promote(name, version, target_stage)
Transition a model version to the target stage via MLflow aliases.
Source code in src/dataenginex/ml/mlflow_registry.py
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 | |
MLflowRegistryError
Bases: RuntimeError
Raised when the MLflow server is unreachable or returns an error.
Source code in src/dataenginex/ml/mlflow_registry.py
45 46 | |
ModelArtifact
dataclass
Registry entry for a model version.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Model name (e.g. |
version |
str
|
Semantic version string. |
stage |
ModelStage
|
Current lifecycle stage. |
artifact_path |
str
|
File path to the serialised model. |
metrics |
dict[str, float]
|
Training/evaluation metrics. |
parameters |
dict[str, Any]
|
Hyper-parameters used for training. |
description |
str
|
Free-text description. |
created_at |
datetime
|
When the artifact was registered. |
promoted_at |
datetime | None
|
When the artifact was last promoted. |
tags |
list[str]
|
Arbitrary labels for filtering. |
Source code in src/dataenginex/ml/registry.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | |
to_dict()
Serialize the model artifact metadata to a plain dictionary.
Source code in src/dataenginex/ml/registry.py
65 66 67 68 69 70 71 | |
ModelRegistry
JSON-file-backed model registry.
Parameters
persist_path: Path to a JSON file for persistence (optional).
Source code in src/dataenginex/ml/registry.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | |
register(artifact)
Register a new model version.
Source code in src/dataenginex/ml/registry.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | |
get(name, version)
Return the artifact for name at version, or None.
Source code in src/dataenginex/ml/registry.py
113 114 115 | |
get_latest(name)
Return the most recently registered version of name.
Source code in src/dataenginex/ml/registry.py
117 118 119 120 121 122 | |
get_production(name)
Return the model currently in production stage.
Source code in src/dataenginex/ml/registry.py
124 125 126 127 128 129 | |
list_models()
Return all registered model names.
Source code in src/dataenginex/ml/registry.py
131 132 133 | |
list_versions(name)
Return all version strings registered for name.
Source code in src/dataenginex/ml/registry.py
135 136 137 | |
promote(name, version, target_stage)
Promote a model version to a new stage.
If promoting to production, any existing production model is
automatically archived.
Source code in src/dataenginex/ml/registry.py
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | |
ModelStage
Bases: StrEnum
Model lifecycle stages.
Source code in src/dataenginex/ml/registry.py
28 29 30 31 32 33 34 | |
ModelServer
Registry-aware model server.
Loads a model from the ModelRegistry and serves predictions via
the predict method.
Parameters
registry:
A ModelRegistry instance (from dataenginex.ml.registry).
Source code in src/dataenginex/ml/serving.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | |
load_model(name, version, model)
Register a model object for serving.
Parameters
name:
Model name matching registry entries.
version:
Model version.
model:
Any object with a predict(X) method.
Source code in src/dataenginex/ml/serving.py
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | |
predict(request)
Run inference for request.
Source code in src/dataenginex/ml/serving.py
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | |
list_loaded()
Return keys of all loaded models.
Source code in src/dataenginex/ml/serving.py
139 140 141 | |
PredictionRequest
dataclass
Input to the serving layer.
Attributes:
| Name | Type | Description |
|---|---|---|
model_name |
str
|
Name of the model to invoke. |
version |
str | None
|
Model version ( |
features |
list[dict[str, Any]]
|
List of feature dicts — each dict is one sample. |
request_id |
str
|
Caller-provided request ID for tracing. |
Source code in src/dataenginex/ml/serving.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | |
PredictionResponse
dataclass
Output from the serving layer.
Attributes:
| Name | Type | Description |
|---|---|---|
model_name |
str
|
Name of the model that produced predictions. |
version |
str
|
Version of the model used. |
predictions |
list[Any]
|
List of prediction values. |
latency_ms |
float
|
Inference latency in milliseconds. |
request_id |
str
|
Echoed request ID for tracing. |
served_at |
datetime
|
Timestamp of the prediction. |
Source code in src/dataenginex/ml/serving.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | |
to_dict()
Serialize the prediction response to a plain dictionary.
Source code in src/dataenginex/ml/serving.py
62 63 64 65 66 67 68 69 70 71 | |
BaseTrainer
Bases: ABC
Abstract base class for model trainers.
Source code in src/dataenginex/ml/training.py
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | |
train(X_train, y_train, **params)
abstractmethod
Train the model and return metrics.
Source code in src/dataenginex/ml/training.py
131 132 133 134 135 136 137 138 139 | |
evaluate(X_test, y_test)
abstractmethod
Evaluate the model on test data.
Source code in src/dataenginex/ml/training.py
141 142 143 144 | |
predict(X)
abstractmethod
Generate predictions.
Source code in src/dataenginex/ml/training.py
146 147 148 149 | |
save(path)
abstractmethod
Persist the model to path and return the artifact path.
Source code in src/dataenginex/ml/training.py
151 152 153 154 | |
load(path, *, extra_modules=None)
abstractmethod
Load a previously saved model from path.
Source code in src/dataenginex/ml/training.py
156 157 158 159 160 161 162 163 164 | |
SklearnTrainer
Bases: BaseTrainer
scikit-learn model trainer.
Works with any sklearn estimator (or pipeline) that implements
fit, predict, and score.
Parameters
model_name:
Name used in model registry.
version:
Semantic version string.
estimator:
An sklearn estimator instance (e.g. RandomForestClassifier()).
Source code in src/dataenginex/ml/training.py
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 | |
train(X_train, y_train, **params)
Fit the estimator on X_train/y_train and return metrics.
Source code in src/dataenginex/ml/training.py
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 | |
evaluate(X_test, y_test)
Score the fitted model on X_test/y_test and return metrics.
Source code in src/dataenginex/ml/training.py
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 | |
predict(X)
Generate predictions for X using the fitted estimator.
Source code in src/dataenginex/ml/training.py
290 291 292 293 294 | |
save(path)
Pickle the fitted model, write an HMAC signature, and metadata.
Source code in src/dataenginex/ml/training.py
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
load(path, *, extra_modules=None)
Load a pickled model with HMAC verification and safe unpickling.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Filesystem path to the |
required |
extra_modules
|
frozenset[str] | None
|
Additional top-level module names to allow
during unpickling (e.g. |
None
|
Source code in src/dataenginex/ml/training.py
326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 | |
TrainingResult
dataclass
Outcome of a model training run.
Attributes:
| Name | Type | Description |
|---|---|---|
model_name |
str
|
Name of the trained model. |
version |
str
|
Semantic version of this training run. |
metrics |
dict[str, float]
|
Training metrics (e.g. |
parameters |
dict[str, Any]
|
Hyper-parameters used for training. |
duration_seconds |
float
|
Wall-clock training time. |
artifact_path |
str | None
|
Path where the model artifact is saved. |
trained_at |
datetime
|
Timestamp of training completion. |
Source code in src/dataenginex/ml/training.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | |
to_dict()
Serialize the training result to a plain dictionary.
Source code in src/dataenginex/ml/training.py
111 112 113 114 115 116 117 118 119 120 121 | |