API Reference
This page documents the HTTP API and provides auto-generated reference documentation for the main Python modules in the stuperml package.
HTTP API (stuperml.api)
The FastAPI application is defined in the stuperml.api module. It exposes endpoints for health checking and batch prediction.
Endpoints
GET /
- Description: Simple health check endpoint.
- Response: JSON object with keys:
message: HTTP status phrase (e.g."OK").status-code: Numeric status code (e.g.200).
Example:
curl http://127.0.0.1:8000/
POST /predict
- Description: Run batch inference on a list of input rows.
- Request body (
PredictionRequest): rows: list of objects where each object is a mapping from feature name to value (bool,int,float, orstr). Must contain at least one row.- Response body (
PredictionResponse): predictions: list of floating-point predictions, one per input row.
The request features must be compatible with the fitted preprocessor (i.e. same feature names and reasonable data types). If the data cannot be transformed, the endpoint responds with a 400 BAD REQUEST containing an error message.
On application startup, the API:
- Loads the preprocessor from
data/preprocessor.joblib(path defined inconfigs.data_config). - Infers the model input size either from
preprocessor.get_feature_names_out()or, as a fallback, fromdata/feature_names.json. - Instantiates
SimpleMLPwith the inferred input size. - Loads weights from
models/model.pth.
If any of the artifacts are missing, a FileNotFoundError or RuntimeError is raised during startup.
Python API (mkdocstrings)
The sections below are auto-generated from the docstrings in the stuperml package using mkdocstrings. They provide detailed reference information about public classes, functions, and modules.
Data
stuperml.data
MyDataset
Bases: Dataset
Source code in src/stuperml/data.py
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 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 | |
Models
stuperml.model
Training
stuperml.train
train
train(
lr: float = 0.001,
batch_size: int = 32,
epochs: int = 30,
verbose: bool = False,
) -> None
Train the model and persist artifacts.
Source code in src/stuperml/train.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 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 | |
Evaluation
stuperml.evaluate
HTTP API
stuperml.api
PredictionRequest
Bases: BaseModel
Request payload for batch prediction.
Source code in src/stuperml/api.py
42 43 44 45 | |
PredictionResponse
Bases: BaseModel
Response payload for batch prediction.
Source code in src/stuperml/api.py
48 49 50 51 | |
lifespan
async
lifespan(_: FastAPI)
Load and release model artifacts for app lifecycle.
Source code in src/stuperml/api.py
25 26 27 28 29 30 31 32 33 34 | |
predict
predict(request: PredictionRequest) -> PredictionResponse
Run batch inference on input rows.
Source code in src/stuperml/api.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | |
root
root() -> dict[str, Any]
Health check.
Source code in src/stuperml/api.py
77 78 79 80 | |