Skip to main content

sklearn-serialize

JSON serialization for scikit-learn pipelines and the Python/NumPy/SciPy/pandas types that appear inside them. The goal is lossless round-trips: json_to_data(data_to_json(obj)) reproduces the original object, including fitted model state.

from sklearn_serialize import data_to_json, json_to_data

json_str = data_to_json(fitted_pipeline)
restored  = json_to_data(json_str)

restored.predict(X)  # identical output to the original

Installation

pip install sklearn-serialize

Supported types

  • sklearn: Pipeline, FeatureUnion, ColumnTransformer, and any BaseEstimator subclass
  • NumPy: ndarray, scalar integer/float/complex types, datetime64, dtype, Generator, RandomState
  • SciPy: sparse matrices (csr, csc, coo, lil, dok)
  • pandas: Series, DataFrame
  • polars: Series, DataFrame (optional — requires polars to be installed)
  • Python: tuple, set, frozenset, bytes, bytearray, slice, complex, OrderedDict, namedtuple, datetime, date

Custom estimators

Custom estimators work out of the box as long as their class is importable at deserialization time. Call trust_module once at startup to allow deserialization from your package:

from sklearn_serialize import trust_module

trust_module("my_package.transformers")

The argument is a module prefix — "my_package" covers my_package.transformers, my_package.pipelines, etc. Only exact matches and dotted submodules are allowed; "my_pack" does not cover "my_package".

json_to_data will raise ValueError if it encounters a class from an untrusted module. This prevents arbitrary code execution when deserializing JSON from untrusted sources. Only call json_to_data on JSON you produced yourself or received from a trusted source.

The default trusted set covers sklearn, numpy, scipy, pandas, builtins, and sklearn_serialize.

To trust modules globally without calling trust_module in every script, create ~/.sklearnserialize:

[trusted_modules]
my_package
polars

One module prefix per line. Blank lines and lines starting with # are ignored. This file is loaded once at import time.

Metadata

Release files for sklearn-serialize 0.1

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

Source distribution (sdist)

Source distribution for sklearn-serialize 0.1
File Size Uploaded Provenance Actions
sklearn_serialize-0.1.tar.gz 18.4 kB With provenance Details for sklearn_serialize-0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for sklearn-serialize 0.1
File Interpreter ABI Platform Actions
sklearn_serialize-0.1-py3-none-any.whl Python 3 none any Details for sklearn_serialize-0.1-py3-none-any.whl

Total release size: 33.0 kB

Release files / sklearn_serialize-0.1.tar.gz

Download URL sklearn_serialize-0.1.tar.gz
Size 18.4 kB
Tags Source
SHA-256 checksum
How to use checksums
d8f30d6e18b2b998ee00cd94e1771f439e9598ef304f3a2398b0f60613b240ec
BLAKE2b-256 checksum
How to use checksums
31537ef0faa6355abac0ae23a61960ef0faa9e1702fec3f9803fb9e0ec9d9103
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

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 Mar 27, 2026.

Transparency log

Release files / sklearn_serialize-0.1-py3-none-any.whl

Download URL sklearn_serialize-0.1-py3-none-any.whl
Size 14.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fcc4f194bb2b84675bd4ed7b626f60754dc3617407752a7780e6a3c710cb4062
BLAKE2b-256 checksum
How to use checksums
54ca0c00e8e6b8605a5ae8bccea93d07bff40378b5de0884631d49dfdc9a362e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

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 Mar 27, 2026.

Transparency log

Security for sklearn-serialize 0.1

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

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for sklearn_serialize-0.1.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 Mar 27, 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.

Release history Release notifications | RSS feed

This release

0.1 This release

2 release files Full provenance

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