Registry / serialization / srsly
library2.5.3pypypi✓ verified 24d ago

Srsly is a Python library providing modern, high-performance serialization utilities. It bundles optimized versions of popular serialization libraries (like ujson, msgpack, cloudpickle, and ruamel.yaml) into a single, standalone package, offering a consistent high-level API for handling JSON, JSONL, MessagePack, Pickle, and YAML data across different platforms and Python versions. It is actively maintained with frequent updates.

pip install srsly
INSTALL
IMPORT
SIG · SRSLY
S
srsly
serializationpythonv2.5.3
Install
1.9s avg
Import
181ms
Disk
22MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.5.3 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.190s · 23.4MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.9s · import 0.172s · 24MB
22MB installed
● package 22MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

json_loads
import srsly data = srsly.json_loads('{"key": "value"}')
read_json
import srsly data = srsly.read_json('path/to/file.json')
write_json
import srsly srsly.write_json('path/to/file.json', {'key': 'value'})
msgpack_dumps
import srsly msg_bytes = srsly.msgpack_dumps({'key': 'value'})

This quickstart demonstrates how to use `srsly` to write and read data in JSON and JSONL formats. It covers basic file operations using `srsly.write_json`, `srsly.read_json`, `srsly.write_jsonl`, and `srsly.read_jsonl`.

import srsly import os # Example with JSON file_path = 'example.json' data = {"name": "Alice", "age": 30, "isStudent": False} # Write JSON to a file srsly.write_json(file_path, data) print(f"Data written to {file_path}") # Read JSON from a file read_data = srsly.read_json(file_path) print(f"Data read from {file_path}: {read_data}") # Clean up os.remove(file_path) # Example with JSONL (newline-delimited JSON) jsonl_path = 'example.jsonl' lines = [{"id": 1, "text": "First line"}, {"id": 2, "text": "Second line"}] # Write JSONL to a file srsly.write_jsonl(jsonl_path, lines) print(f"Data written to {jsonl_path}") # Read JSONL from a file read_lines = list(srsly.read_jsonl(jsonl_path)) print(f"Data read from {jsonl_path}: {read_lines}") # Clean up os.remove(jsonl_path)
Debug
Known issues
breakingSrsly v2.x (and later) dropped support for Python 2.x. Users migrating from v1.x must ensure their environment is Python 3.6 or newer.
fix
Upgrade to Python 3.6+ to use srsly v2.x. For Python 2.7, use srsly v1.x (which is no longer actively maintained).
affects: >=2.0.0
gotchaVersions prior to v1.0.7 and early v2.x contained security vulnerabilities (CVE-2022-31116, CVE-2021-4595) related to incorrect handling of surrogate pair characters and buffer overflows in the vendored `ujson` component.
fix
Upgrade to srsly v1.0.7 (if on 1.x) or v2.4.7 (or newer) to include the patches for these vulnerabilities.
affects: <1.0.7, <2.4.7
gotchaSrsly v2.4.7 introduced a restriction to Cython 0.29.x due to incompatibilities with Cython 3. This primarily affects users who compile srsly from source or have Cython 3 installed in their environment.
fix
Ensure that if you are building srsly from source, your Cython version is 0.29.x. If using Cython 3, you might encounter build issues until srsly officially supports it. Binary wheels are not affected by this specific build-time dependency.
affects: >=2.4.7
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'srsly'
The srsly library is not installed in the current Python environment.
fix
pip install srsly
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
This error occurs when trying to parse an invalid, empty, or malformed JSON or JSONL string/file using srsly's JSON functions.
fix
Ensure the input data is valid JSON or JSON Lines format before attempting to load it.
TypeError: Object of type set is not JSON serializable
You are attempting to serialize a Python object (like a set or a custom class instance) that is not natively representable in JSON or MessagePack without providing a custom encoder.
fix
Convert non-serializable objects to a compatible type (e.g., list for a set) or provide a custom 'default' function to srsly.json_dumps or srsly.msgpack_dumps.
ruamel.yaml.scanner.ScannerError: while scanning a block scalar
The input YAML string or file contains syntax errors, incorrect indentation, or is malformed, which prevents srsly's underlying YAML parser from processing it.
fix
Review and correct the YAML syntax and indentation in your input data.
Upgrade
Version history
2.5.3latest on PyPI · released Mar 23, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
20 hits · last 30 days
node
16
OpenAI (training)
1
Resources
srsly — pip install srsly · libregistry