Metadata-Version: 2.4
Name: skeights
Version: 0.2.0
Summary: Serialize fitted scikit-learn models to safetensors + JSON
Project-URL: Repository, https://github.com/carbon-re/skeights
Author-email: Gigaton <engineering@gigaton.co>
License-Expression: MIT
License-File: LICENSE
Keywords: machine-learning,safetensors,scikit-learn,serialization
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.11
Requires-Dist: numpy
Requires-Dist: safetensors
Requires-Dist: scikit-learn>=1.5
Provides-Extra: all
Requires-Dist: lightgbm; extra == 'all'
Requires-Dist: xgboost; extra == 'all'
Provides-Extra: dev
Requires-Dist: lightgbm; extra == 'dev'
Requires-Dist: pandas; extra == 'dev'
Requires-Dist: pyright; extra == 'dev'
Requires-Dist: pytest; extra == 'dev'
Requires-Dist: ruff; extra == 'dev'
Requires-Dist: xgboost; extra == 'dev'
Provides-Extra: lightgbm
Requires-Dist: lightgbm; extra == 'lightgbm'
Provides-Extra: xgboost
Requires-Dist: xgboost; extra == 'xgboost'
Description-Content-Type: text/markdown

<p align="center">
  <img src="https://raw.githubusercontent.com/carbon-re/skeights/main/logo.png" alt="skeights logo" width="200">
</p>

# skeights

Serialize fitted scikit-learn models to [safetensors](https://github.com/huggingface/safetensors) + JSON.

No pickle. No joblib. Just weights and config.

## Why?

Pickle is the default way to save sklearn models, but it's:
- **Insecure**: arbitrary code execution on load
- **Fragile**: breaks across sklearn versions, Python versions, and platforms
- **Opaque**: you can't inspect what's inside

[skops](https://github.com/skops-dev/skops) solves the security
problem by replacing pickle with a safe binary format, but the
output is still a single opaque blob; you can't easily inspect
the hyperparameters or diff two versions of a model.

skeights separates structure from weights:
- **`.json`**: hyperparameters and scalar fitted state,
  human-readable and diffable
- **`.safetensors`**: numeric arrays (weights, fitted params)
  in a safe, fast, widely-supported format

## Install

```bash
pip install skeights
```

## Usage

```python
import skeights
from sklearn.linear_model import Ridge
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import StandardScaler

# Fit your model as usual
pipe = Pipeline([
    ("scaler", StandardScaler()),
    ("model", Ridge(alpha=0.1)),
])
pipe.fit(X_train, y_train)

# Save
skeights.save(pipe, "model.safetensors", "model.json")

# Load and predict
loaded = skeights.load("model.safetensors", "model.json")
predictions = loaded.predict(X_test)
```

## Supported estimators

- **Linear models**: Ridge, Lasso, LinearRegression, LogisticRegression, etc.
- **MLPRegressor / Classifier**: multi-layer perceptron
- **DecisionTreeRegressor / Classifier**: full tree serialization
- **RandomForestRegressor / Classifier**: full tree serialization
- **GradientBoostingRegressor / Classifier**: including init estimator
- **HistGradientBoostingRegressor / Classifier**: including bin mapper state
- **LGBMRegressor / Classifier**: via booster model string
- **XGBRegressor / Classifier**: via booster JSON
- **GaussianProcessRegressor / Classifier**: including composite kernels
- **TransformedTargetRegressor**: target scaling wrappers
- **Scalers**: StandardScaler, MinMaxScaler, RobustScaler
- **Pipelines**: any Pipeline composed of supported estimators

## Compatibility

skeights requires scikit-learn >= 1.5 and tests against 1.5,
1.6, and latest in CI.

Saved models are forward-compatible on a best-effort basis: we
test loading sklearn 1.5 fixtures on newer versions, but don't
guarantee cross-version compatibility.

When loading a model saved with a different sklearn version,
skeights will emit a warning.

## License

MIT
