Skip to main content

Serialize fitted scikit-learn models to safetensors + JSON

Project description

skeights logo

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

skeights-0.1.0.tar.gz (2.4 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

skeights-0.1.0-py3-none-any.whl (21.3 kB view details)

Uploaded Python 3

File details

Details for the file skeights-0.1.0.tar.gz.

File metadata

  • Download URL: skeights-0.1.0.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

Hashes for skeights-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e4bbd518424d3566f0e07748e0ae310b3315c26eb3c8d5d994694dcd31b4dcae
MD5 7a55b37a0d2a7626f34c883dc961115a
BLAKE2b-256 c74ac6f6267ad87b2379117ea37dc9907c8dedb0527559e1458c4d51badc6516

See more details on using hashes here.

Provenance

The following attestation bundles were made for skeights-0.1.0.tar.gz:

Publisher: publish.yml on carbon-re/skeights

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file skeights-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: skeights-0.1.0-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

Hashes for skeights-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ff4b9984ab0a5959a535c667a09a80007f939be2ab28e6c4faecfb1b0293caf5
MD5 f3f56195b3854cba1d399c2b64784966
BLAKE2b-256 0e2a272819e201eae2ff2cdf45a0bdbdab607ca937ef2086cd61559c423cbb60

See more details on using hashes here.

Provenance

The following attestation bundles were made for skeights-0.1.0-py3-none-any.whl:

Publisher: publish.yml on carbon-re/skeights

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page