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.1.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.1-py3-none-any.whl (21.3 kB view details)

Uploaded Python 3

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

Hashes for skeights-0.1.1.tar.gz
Algorithm Hash digest
SHA256 6687aa241f92baa9ff5bd7f8b1c68254c8a1ab3eceb5d1d2a76bdc14d542f63b
MD5 e66cfcdc9b45628bca49ff04f552901c
BLAKE2b-256 ac3052bb7f097301b25b613d201657d8b662f3c745cdc997af61ade09dbcdf25

See more details on using hashes here.

Provenance

The following attestation bundles were made for skeights-0.1.1.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.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

Hashes for skeights-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e71f6569761af91b8b375c92e80836210f0b062009efe30568e08656cf1e47ca
MD5 2e670065eb5b9d4b54c9d28a6dff187a
BLAKE2b-256 b202960e56f4f83b8b61ad28eee7fc7418df7c99f77c7e5efd6d67cf207e52a5

See more details on using hashes here.

Provenance

The following attestation bundles were made for skeights-0.1.1-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