{"id":1135,"library":"srsly","title":"Srsly: High-Performance Python Serialization Utilities","description":"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.","status":"active","version":"2.5.3","language":"en","source_language":"en","source_url":"https://github.com/explosion/srsly","tags":["serialization","json","msgpack","pickle","yaml","performance"],"install":[{"cmd":"pip install srsly","lang":"bash","label":"Install with pip"}],"dependencies":[],"imports":[{"symbol":"json_loads","correct":"import srsly\ndata = srsly.json_loads('{\"key\": \"value\"}')"},{"symbol":"read_json","correct":"import srsly\ndata = srsly.read_json('path/to/file.json')"},{"symbol":"write_json","correct":"import srsly\nsrsly.write_json('path/to/file.json', {'key': 'value'})"},{"symbol":"msgpack_dumps","correct":"import srsly\nmsg_bytes = srsly.msgpack_dumps({'key': 'value'})"}],"quickstart":{"code":"import srsly\nimport os\n\n# Example with JSON\nfile_path = 'example.json'\ndata = {\"name\": \"Alice\", \"age\": 30, \"isStudent\": False}\n\n# Write JSON to a file\nsrsly.write_json(file_path, data)\nprint(f\"Data written to {file_path}\")\n\n# Read JSON from a file\nread_data = srsly.read_json(file_path)\nprint(f\"Data read from {file_path}: {read_data}\")\n\n# Clean up\nos.remove(file_path)\n\n# Example with JSONL (newline-delimited JSON)\njsonl_path = 'example.jsonl'\nlines = [{\"id\": 1, \"text\": \"First line\"}, {\"id\": 2, \"text\": \"Second line\"}]\n\n# Write JSONL to a file\nsrsly.write_jsonl(jsonl_path, lines)\nprint(f\"Data written to {jsonl_path}\")\n\n# Read JSONL from a file\nread_lines = list(srsly.read_jsonl(jsonl_path))\nprint(f\"Data read from {jsonl_path}: {read_lines}\")\n\n# Clean up\nos.remove(jsonl_path)","lang":"python","description":"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`."},"warnings":[{"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).","message":"Srsly 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.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Upgrade to srsly v1.0.7 (if on 1.x) or v2.4.7 (or newer) to include the patches for these vulnerabilities.","message":"Versions 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.","severity":"gotcha","affected_versions":"<1.0.7, <2.4.7"},{"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.","message":"Srsly 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.","severity":"gotcha","affected_versions":">=2.4.7"}],"env_vars":null,"last_verified":"2026-04-05T00:00:00.000Z","next_check":"2026-07-04T00:00:00.000Z"}