Serialize fitted scikit-learn models to safetensors + JSON
Project description
skeights
Serialize fitted scikit-learn models to 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 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
pip install skeights
Usage
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
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file skeights-0.1.1.tar.gz.
File metadata
- Download URL: skeights-0.1.1.tar.gz
- Upload date:
- Size: 2.4 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6687aa241f92baa9ff5bd7f8b1c68254c8a1ab3eceb5d1d2a76bdc14d542f63b
|
|
| MD5 |
e66cfcdc9b45628bca49ff04f552901c
|
|
| BLAKE2b-256 |
ac3052bb7f097301b25b613d201657d8b662f3c745cdc997af61ade09dbcdf25
|
Provenance
The following attestation bundles were made for skeights-0.1.1.tar.gz:
Publisher:
publish.yml on carbon-re/skeights
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
skeights-0.1.1.tar.gz -
Subject digest:
6687aa241f92baa9ff5bd7f8b1c68254c8a1ab3eceb5d1d2a76bdc14d542f63b - Sigstore transparency entry: 2062850178
- Sigstore integration time:
-
Permalink:
carbon-re/skeights@3c2981bd71c3c2a4424592609079bdb4296d155d -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/carbon-re
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@3c2981bd71c3c2a4424592609079bdb4296d155d -
Trigger Event:
push
-
Statement type:
File details
Details for the file skeights-0.1.1-py3-none-any.whl.
File metadata
- Download URL: skeights-0.1.1-py3-none-any.whl
- Upload date:
- Size: 21.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e71f6569761af91b8b375c92e80836210f0b062009efe30568e08656cf1e47ca
|
|
| MD5 |
2e670065eb5b9d4b54c9d28a6dff187a
|
|
| BLAKE2b-256 |
b202960e56f4f83b8b61ad28eee7fc7418df7c99f77c7e5efd6d67cf207e52a5
|
Provenance
The following attestation bundles were made for skeights-0.1.1-py3-none-any.whl:
Publisher:
publish.yml on carbon-re/skeights
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
skeights-0.1.1-py3-none-any.whl -
Subject digest:
e71f6569761af91b8b375c92e80836210f0b062009efe30568e08656cf1e47ca - Sigstore transparency entry: 2062850259
- Sigstore integration time:
-
Permalink:
carbon-re/skeights@3c2981bd71c3c2a4424592609079bdb4296d155d -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/carbon-re
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@3c2981bd71c3c2a4424592609079bdb4296d155d -
Trigger Event:
push
-
Statement type: