Description
<a href="https://explosion.ai"><img src="https://explosion.ai/assets/img/logo.svg" width="125" height="125" align="right" /></a> # srsly: Modern high-performance serialization utilities for Python This package bundles some of the best Python serialization libraries into one standalone package, with a high-level API that makes it easy to write code that's correct across platforms and Pythons. This allows us to provide all the serialization utilities we need in a single binary wheel. Currently supports **JSON**, **JSONL**, **MessagePack**, **Pickle** and **YAML**. [](https://github.com/explosion/srsly/actions/workflows/tests.yml) [](https://pypi.python.org/pypi/srsly) [](https://anaconda.org/conda-forge/srsly) [](https://github.com/explosion/srsly) [](https://github.com/explosion/wheelwright/releases) ## Motivation Serialization is hard, especially across Python versions and multiple platforms. After dealing with many subtle bugs over the years (encodings, locales, large files) our libraries like [spaCy](https://github.com/explosion/spaCy) and [Prodigy](https://prodi.gy) had steadily grown a number of utility functions to wrap the multiple serialization formats we need to support (especially `json`, `msgpack` and `pickle`). These wrapping functions ended up duplicated across our codebases, so we wanted to put them in one place. At the same time, we noticed that having a lot of small dependencies was making maintenance harder, and making installation slower. To solve this, we've made `srsly` standalone, by including the component packages directly within it. This way we can provide all the serialization utilities we need in a single binary wheel. `srsly` currently includes forks of the following packages: - [`ujson`](https://github.com/esnme/ultrajson) - [`msgpack`](https://github.com/msgpack/msgpack-python) - [`msgpack-numpy`](https://github.com/lebedov/msgpack-numpy) - [`cloudpickle`](https://github.com/cloudpipe/cloudpickle) - [`ruamel.yaml`](https://github.com/pycontribs/ruamel-yaml) (without unsafe implementations!) ## Installation > ⚠️ Note that `v2.x` is only compatible with **Python 3.6+**. For 2.7+ > compatibility, use `v1.x`. `srsly` can be installed from pip. Before installing, make sure that your `pip`, `setuptools` and `wheel` are up to date. ```bash python -m pip install -U pip setuptools wheel python -m pip install srsly ``` Or from conda via conda-forge: ```bash conda install -c conda-forge srsly ``` Alternatively, you can also compile the library from source. You'll need to make sure that you have a development environment with a Python distribution including header files, a compiler (XCode command-line tools on macOS / OS X or Visual C++ build tools on Windows), pip and git installed. Install from source: ```bash # clone the repo git clone https://github.com/explosion/srsly cd srsly # create a virtual environment python -m venv .env source .env/bin/activate # update pip python -m pip install -U pip setuptools wheel # compile and install from source python -m pip install . ``` For developers, install requirements separately and then install in editable mode without build isolation: ```bash # install in editable mode python -m pip install -r requirements.txt python -m pip install --no-build-isolation --editable . # run test suite python -m pytest --pyargs srsly ``` ## API ### JSON > 📦 The underlying module is exposed via `srsly.ujson`. However, we normally > interact with it via the utility functions only. #### <kbd>function</kbd> `srsly.json_dumps` Serialize an object to a JSON string. Falls back to `json` if `sort_keys=True` is used (until it's fixed in `ujson`). ```python data = {"foo": "bar", "baz": 123} json_string = srsly.json_dumps(data) ``` | Argument | Type | Description | | ----------- | ---- | ------------------------------------------------------ | | `data` | - | The JSON-serializable data to output. | | `indent` | int | Number of spaces used to indent JSON. Defaults to `0`. | | `sort_keys` | bool | Sort dictionary keys. Defaults to `False`. | | **RETURNS** | str | The serialized string. | #### <kbd>function</kbd> `srsly.json_loads` Deserialize unicode or bytes to a Python object. ```python data = '{"foo": "bar", "baz": 123}' obj = srsly.json_loads(data) ``` | Argument | Type | Description
Release History
| Version | Changes | Urgency | Date |
|---|---|---|---|
| 2.5.3 | Imported from PyPI (2.5.3) | Low | 4/21/2026 |
| release-v2.5.3 | # Generated notes (2026-03-23 12:38) Python 3.14 support via updated cloudpickle ## Features - Add Python 3.14 compatibility by updating vendored cloudpickle to 3.1.2 | Medium | 3/23/2026 |
| release-v2.5.2 | Release release-v2.5.2 | Low | 11/17/2025 |
| release-v2.5.1 | Now that Github have runners for Linux ARM, we can build wheels for that again 🎉 | Low | 1/17/2025 |
| release-v2.5.0 | * Update vendored `msgpack-python` to v1.1.0 * Update build system and support Python 3.13 * Update metadata to accurately reflect Python version ranges | Low | 12/10/2024 |
| v2.4.8 | * Updates for Python 3.12 support (#102). * Add Python 3.12 wheels. | Low | 9/22/2023 |
| v2.4.7 | - Restrict to Cython 0.29.x due to incompatibilities with Cython 3. | Low | 7/18/2023 |
| v1.0.7 | - Port https://github.com/ultrajson/ultrajson/pull/550 and https://github.com/ultrajson/ultrajson/pull/555 to fix incorrect handling of invalid surrogate pair characters (CVE-2022-31116) - Port https://github.com/ultrajson/ultrajson/pull/519 to fix buffer overflows ([CVE-2021-4595](https://github.com/advisories/GHSA-fh56-85cw-5pq6)) | Low | 7/18/2023 |
| v2.4.6 | * Fix typing for `JSONInput` and `JSONInputBin` (#79). * Add `read_gzip_jsonl` and `write_gzip_jsonl` (#84). | Low | 2/28/2023 |
| v1.0.6 | * Drop support for Python 3.5 and earlier. * Update to cloudpickle v2.2.0 for Python 3.11 support. * Add Python 3.11 wheels. | Low | 10/18/2022 |
| v2.4.5 | * Update to cloudpickle v2.2.0 for Python 3.11 support. * Add Python 3.11 wheels. | Low | 10/18/2022 |
| v2.4.4 | - Port https://github.com/ultrajson/ultrajson/pull/550 and https://github.com/ultrajson/ultrajson/pull/555 to fix incorrect handling of invalid surrogate pair characters (CVE-2022-31116) | Low | 7/20/2022 |
| v2.4.3 | - Port https://github.com/ultrajson/ultrajson/pull/519 to fix buffer overflows ([CVE-2021-4595](https://github.com/advisories/GHSA-fh56-85cw-5pq6)) | Low | 4/13/2022 |
| v2.4.1 | * Use str with chdir in setup * Fix type of `write_jsonl` * Fix `json_loads` behaviour for string "-" | Low | 4/12/2021 |
| v2.4.0 | * Support custom `msgpack` serializers and deserializers via function registries (mostly internals). * Update setup. | Low | 2/1/2021 |
| v1.0.3 | * Update for python 3.9 | Low | 11/4/2020 |
| v2.3.1 | * Update for python 3.9 | Low | 11/4/2020 |
| v2.3.0 | * Adjust argument names. * Expose data loaders for spaCy v3. | Low | 10/1/2020 |
| v2.2.0 | * Remove unsafe YAML implementations, raising if called (see #28) | Low | 6/30/2020 |
| v2.1.0 | * Include vendorized [`ruamel.yaml`](https://github.com/pycontribs/ruamel-yaml). * Add YAML API for saving and loading YAML. | Low | 6/21/2020 |
| v2.0.1 | * Support `cupy.ndarray` in `msgpack_numpy`. * Make `msgpack` raise correct errors for unserializable objects if `numpy` is not installed. | Low | 3/4/2020 |
| v1.0.2 | * Support `cupy.ndarray` in `msgpack_numpy`. * Make `msgpack` raise correct errors for unserializable objects if `numpy` is not installed. | Low | 3/4/2020 |
| v1.0.1 | * Fix source distribution. | Low | 1/6/2020 |
| v2.0.0 | * Port over esnme/ultrajson#323 by @timdawborn. * Drop support for Python 2.7 and 3.5. * Tidy up code and remove compatibility helpers. * Add type hints. * Improve setup and compilation. | Low | 1/2/2020 |
| v1.0.0 | - Add official support for Python 3.8. - Fix typo in `README.md`. Thanks to @pfvosi for the pull request! | Low | 1/2/2020 |
| v0.2.0 | * Fix issue #10: Update cloudpickle to 1.2.2 to support Python 3.8. * Fix issue #13: Add `append_new_line` option to `write_jsonl` to control whether newline is appended. Thanks to @nyejon for the pull request! | Low | 10/28/2019 |
| v0.1.0 | * Add `read_gzip_json` and `write_gzip_json` for working with compressed JSON. Thanks to @polm for the pull request! | Low | 8/18/2019 |
| v0.0.7 | * Fix issue #6: Don't write to JSONL as `"a"` (append) by default. | Low | 6/13/2019 |
| v0.0.6 | * Fix issue #4: Fix memory leak. Thanks to @sadovnychyi for the pull request and to @Adriandorr for the fix. | Low | 6/7/2019 |
| v0.0.5 | * Fix length limits on `msgpack` serialization. | Low | 12/2/2018 |
| v0.0.4 | * Move `ujson` to `srsly.ujson` for API consistency. * Add pickle utilities: `pickle_loads` and `pickle_dumps`. * Add msgpack utilities: `msgpack_loads`, `msgpack_dumps`, `write_msgpack`, `read_msgpack`. * Improve test suite. | Low | 12/2/2018 |
| v0.0.3 | * Expose `json_dumps` and `json_loads` helpers. * Add support for `sort_keys` via `json`. | Low | 12/2/2018 |
| v0.0.2 | * Fix tests across Python versions and platforms. * Improve file path handling. | Low | 12/2/2018 |
| v0.0.1 | Release v0.0.1 | Low | 12/1/2018 |
