Skip to main content

skjson

Export scikit-learn models to JSON for cross-language inference.

  1. Running inference using npm package: skjson-js
  2. Check out the Info Page

Installation

pip install skjson

Quick Start

Check out the demo notebook for an example training a Random Forest on the Iris dataset:

from sklearn.datasets import load_iris
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import train_test_split
import skjson

# Load the Iris dataset and split
X, y = load_iris(return_X_y=True)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

# Train a Random Forest classifier
clf = RandomForestClassifier(random_state=42)
clf.fit(X_train, y_train)

# Export the trained model to JSON
skjson.save(clf, 'demo.json')

# Load and reuse the model
predictor = skjson.load("demo.json")

Convert from Joblib and ONNX

skjson supports converting sklearn models directly from joblib and ONNX format without the need to load the model in Python first.

Convert from Joblib

import skjson

# Convert a joblib-serialized sklearn model to JSON
skjson.joblib_to_json("model.joblib")
# → Creates "model.json" in the same directory

# Or specify a custom output path and feature names
skjson.joblib_to_json(
    "model.joblib",
    output_path="output/model.json",
    feature_names=["sepal_length", "sepal_width", "petal_length", "petal_width"]
)

Convert from ONNX

Works with ONNX models exported from sklearn using skl2onnx:

import skjson

# Convert an ONNX model to JSON
skjson.onnx_to_json("model.onnx")
# → Creates "model.json" in the same directory

# Or specify a custom output path
skjson.onnx_to_json("model.onnx", output_path="output/model.json")

Supported ONNX model types (exported from sklearn via skl2onnx):

ONNX Operator sklearn Model
LinearRegressor LinearRegression, Ridge, Lasso, ElasticNet
LinearClassifier LogisticRegression
TreeEnsembleClassifier DecisionTreeClassifier, RandomForestClassifier
TreeEnsembleRegressor DecisionTreeRegressor, RandomForestRegressor
SVMClassifier SVC, LinearSVC
SVMRegressor SVR

Supported models for conversion

Linear Models (sklearn.linear_model)

  • LinearRegression, Ridge, Lasso, ElasticNet
  • LogisticRegression

Tree-based Models (sklearn.tree, sklearn.ensemble)

  • DecisionTreeClassifier, DecisionTreeRegressor
  • RandomForestClassifier, RandomForestRegressor
  • GradientBoostingClassifier, GradientBoostingRegressor

Support Vector Machines (sklearn.svm)

  • SVC, SVR, LinearSVC

Neighbors (sklearn.neighbors)

  • KNeighborsClassifier, KNeighborsRegressor

Naive Bayes (sklearn.naive_bayes)

  • GaussianNB

Preprocessing (sklearn.preprocessing)

  • StandardScaler, MinMaxScaler, LabelEncoder

Future Directions

  • Support for scikit-learn Pipeline objects and feature unions.
  • npm package for inference using our json models
  • Support for sklearn.neural_network models

Note

  • This project built with Google Gemini and Claude Opus.
  • If you wish to contribute, please contact me.

Metadata

Release files for skjson 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for skjson 0.1.3
File Size Uploaded Provenance Actions
skjson-0.1.3.tar.gz 36.7 kB With provenance Details for skjson-0.1.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for skjson 0.1.3
File Interpreter ABI Platform Actions
skjson-0.1.3-py3-none-any.whl Python 3 none any Details for skjson-0.1.3-py3-none-any.whl

Total release size: 59.6 kB

Release files / skjson-0.1.3.tar.gz

Download URL skjson-0.1.3.tar.gz
Size 36.7 kB
Tags Source
SHA-256 checksum
How to use checksums
e1f8fa3b17ad1c27f03d8512308a3dd3073a636d898503d83c3f4c296ab04ffa
BLAKE2b-256 checksum
How to use checksums
2fc342f4858bff67229932392f77d85a263b6eb9720b2f7d4c769b326b8d5bfa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 10, 2026.

Transparency log

Release files / skjson-0.1.3-py3-none-any.whl

Download URL skjson-0.1.3-py3-none-any.whl
Size 22.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dc63cd750cbf073e2d2056a1e33fdecadbda9eb0a5f06d84464ded43441f867f
BLAKE2b-256 checksum
How to use checksums
ea6274ea7948d31dd91c3b834807993df781155ea7bf45e4e60a8f2d7edd9fb1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 10, 2026.

Transparency log

Security for skjson 0.1.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for skjson-0.1.3.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 10, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page