Skip to main content

Modern high-performance serialization utilities for Python

Project description

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.

Azure Pipelines PyPi conda GitHub Python wheels

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 and Prodigy have 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:

Installation

srsly can be installed from pip:

pip install srsly

Or from conda via conda-forge:

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 consisting of a Python distribution including header files, a compiler (XCode command-line tools on macOS / OS X or Visual C++ build tools on Windows), pip, virtualenv and git installed.

pip install -r requirements.txt  # install development dependencies
python setup.py build_ext --inplace  # compile the library

API

JSON

📦 The underlying module is exposed via srsly.ujson. However, we normally interact with it via the utility functions only.

function srsly.json_dumps

Serialize an object to a JSON string. Takes care of Python 2/3 compatibility and falls back to json if sort_keys=True is used (until it's fixed in ujson).

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 unicode The serialized string.

function srsly.json_loads

Deserialize unicode or bytes to a Python object.

data = '{"foo": "bar", "baz": 123}'
obj = srsly.json_loads(data)
Argument Type Description
data unicode / bytes The data to deserialize.
RETURNS - The deserialized Python object.

function srsly.write_json

Create a JSON file and dump contents or write to standard output.

data = {"foo": "bar", "baz": 123}
srsly.write_json("/path/to/file.json", data)
Argument Type Description
location unicode / Path The file path or "-" to write to stdout.
data - The JSON-serializable data to output.
indent int Number of spaces used to indent JSON. Defaults to 2.

function srsly.read_json

Load JSON from a file or standard input.

data = srsly.read_json("/path/to/file.json")
Argument Type Description
location unicode / Path The file path or "-" to read from stdin.
RETURNS dict / list The loaded JSON content.

function srsly.write_gzip_json

Create a gzipped JSON file and dump contents.

data = {"foo": "bar", "baz": 123}
srsly.write_gzip_json("/path/to/file.json.gz", data)
Argument Type Description
location unicode / Path The file path.
data - The JSON-serializable data to output.
indent int Number of spaces used to indent JSON. Defaults to 2.

function srsly.read_gzip_json

Load gzipped JSON from a file.

data = srsly.read_json("/path/to/file.json.gz")
Argument Type Description
location unicode / Path The file path.
RETURNS dict / list The loaded JSON content.

function srsly.write_jsonl

Create a JSONL file (newline-delimited JSON) and dump contents line by line, or write to standard output.

data = [{"foo": "bar"}, {"baz": 123}]
srsly.write_jsonl("/path/to/file.jsonl", data)
Argument Type Description
location unicode / Path The file path or "-" to write to stdout.
lines iterable The JSON-serializable lines.
append bool Append to an existing file. Will open it in "a" mode and insert a newline before writing lines. Defaults to False.
append_new_line bool Defines whether a new line should first be written when appending to an existing file. Defaults to True.

function srsly.read_jsonl

Read a JSONL file (newline-delimited JSON) or from JSONL data from standard input and yield contents line by line. Blank lines will always be skipped.

data = srsly.read_jsonl("/path/to/file.jsonl")
Argument Type Description
location unicode / Path The file path or "-" to read from stdin.
skip bool Skip broken lines and don't raise ValueError. Defaults to False.
YIELDS - The loaded JSON contents of each line.

function srsly.is_json_serializable

Check if a Python object is JSON-serializable.

assert srsly.is_json_serializable({"hello": "world"}) is True
assert srsly.is_json_serializable(lambda x: x) is False
Argument Type Description
obj - The object to check.
RETURNS bool Whether the object is JSON-serializable.

msgpack

📦 The underlying module is exposed via srsly.msgpack. However, we normally interact with it via the utility functions only.

function srsly.msgpack_dumps

Serialize an object to a msgpack byte string.

data = {"foo": "bar", "baz": 123}
msg = srsly.msgpack_dumps(data)
Argument Type Description
data - The data to serialize.
RETURNS bytes The serialized bytes.

function srsly.msgpack_loads

Deserialize msgpack bytes to a Python object.

msg = b"\x82\xa3foo\xa3bar\xa3baz{"
data = srsly.msgpack_loads(msg)
Argument Type Description
data bytes The data to deserialize.
use_list bool Don't use tuples instead of lists. Can make deserialization slower. Defaults to True.
RETURNS - The deserialized Python object.

function srsly.write_msgpack

Create a msgpack file and dump contents.

data = {"foo": "bar", "baz": 123}
srsly.write_msgpack("/path/to/file.msg", data)
Argument Type Description
location unicode / Path The file path.
data - The data to serialize.

function srsly.read_msgpack

Load a msgpack file.

data = srsly.read_msgpack("/path/to/file.msg")
Argument Type Description
location unicode / Path The file path.
use_list bool Don't use tuples instead of lists. Can make deserialization slower. Defaults to True.
RETURNS - The loaded and deserialized content.

pickle

📦 The underlying module is exposed via srsly.cloudpickle. However, we normally interact with it via the utility functions only.

function srsly.pickle_dumps

Serialize a Python object with pickle.

data = {"foo": "bar", "baz": 123}
pickled_data = srsly.pickle_dumps(data)
Argument Type Description
data - The object to serialize.
protocol int Protocol to use. -1 for highest. Defaults to None.
RETURNS bytes The serialized object.

function srsly.pickle_loads

Deserialize bytes with pickle.

pickled_data = b"\x80\x04\x95\x19\x00\x00\x00\x00\x00\x00\x00}\x94(\x8c\x03foo\x94\x8c\x03bar\x94\x8c\x03baz\x94K{u."
data = srsly.pickle_loads(pickled_data)
Argument Type Description
data bytes The data to deserialize.
RETURNS - The deserialized Python object.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

srsly-0.2.0.tar.gz (187.7 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

srsly-0.2.0-cp38-cp38-win_amd64.whl (176.7 kB view details)

Uploaded CPython 3.8Windows x86-64

srsly-0.2.0-cp38-cp38-manylinux1_x86_64.whl (185.7 kB view details)

Uploaded CPython 3.8

srsly-0.2.0-cp38-cp38-macosx_10_9_x86_64.whl (183.4 kB view details)

Uploaded CPython 3.8macOS 10.9+ x86-64

srsly-0.2.0-cp37-cp37m-win_amd64.whl (174.9 kB view details)

Uploaded CPython 3.7mWindows x86-64

srsly-0.2.0-cp37-cp37m-manylinux1_x86_64.whl (185.2 kB view details)

Uploaded CPython 3.7m

srsly-0.2.0-cp37-cp37m-macosx_10_6_intel.whl (275.3 kB view details)

Uploaded CPython 3.7mmacOS 10.6+ Intel (x86-64, i386)

srsly-0.2.0-cp36-cp36m-win_amd64.whl (175.3 kB view details)

Uploaded CPython 3.6mWindows x86-64

srsly-0.2.0-cp36-cp36m-manylinux1_x86_64.whl (185.3 kB view details)

Uploaded CPython 3.6m

srsly-0.2.0-cp36-cp36m-macosx_10_6_intel.whl (278.3 kB view details)

Uploaded CPython 3.6mmacOS 10.6+ Intel (x86-64, i386)

srsly-0.2.0-cp35-cp35m-win_amd64.whl (173.8 kB view details)

Uploaded CPython 3.5mWindows x86-64

srsly-0.2.0-cp35-cp35m-manylinux1_x86_64.whl (183.8 kB view details)

Uploaded CPython 3.5m

srsly-0.2.0-cp27-cp27mu-manylinux1_x86_64.whl (180.6 kB view details)

Uploaded CPython 2.7mu

srsly-0.2.0-cp27-cp27m-manylinux1_x86_64.whl (180.5 kB view details)

Uploaded CPython 2.7m

srsly-0.2.0-cp27-cp27m-macosx_10_6_intel.whl (270.5 kB view details)

Uploaded CPython 2.7mmacOS 10.6+ Intel (x86-64, i386)

File details

Details for the file srsly-0.2.0.tar.gz.

File metadata

  • Download URL: srsly-0.2.0.tar.gz
  • Upload date:
  • Size: 187.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.6

File hashes

Hashes for srsly-0.2.0.tar.gz
Algorithm Hash digest
SHA256 aa02e2a62093ef09d7904343ee7381b9c9bab5b4f06960dfbeaa12035d0f0a3e
MD5 f6e4a12233df87c8f5c102cca89178e0
BLAKE2b-256 1e5bf83e478fbf44c0d04f182e56db0871a53f5096febb8eb0be7cec75dca73b

See more details on using hashes here.

File details

Details for the file srsly-0.2.0-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: srsly-0.2.0-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 176.7 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.7.0

File hashes

Hashes for srsly-0.2.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 eca4be587d20a3dfbf45b316ceec5e9f9fd231c3b7d1365a35ce34d34b6e184b
MD5 29fadfe512335ce8bae6648466d11ce8
BLAKE2b-256 164b57e28409e7a6d6e4f9eaca59f70a9c41368146e8923137ca467ce23c593d

See more details on using hashes here.

File details

Details for the file srsly-0.2.0-cp38-cp38-manylinux1_x86_64.whl.

File metadata

  • Download URL: srsly-0.2.0-cp38-cp38-manylinux1_x86_64.whl
  • Upload date:
  • Size: 185.7 kB
  • Tags: CPython 3.8
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.7.0

File hashes

Hashes for srsly-0.2.0-cp38-cp38-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 d60256e395cc61e85e26b0e3549ed8839e365106f8cd2ed5db43bf79ad5efce4
MD5 5bd9bdf3655e704344196545a1b4b375
BLAKE2b-256 0f439754d339c746808eae249cdb2388dd2ddf614ce2e4f4844eb87c60f3a637

See more details on using hashes here.

File details

Details for the file srsly-0.2.0-cp38-cp38-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: srsly-0.2.0-cp38-cp38-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 183.4 kB
  • Tags: CPython 3.8, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.30.0 CPython/3.7.2

File hashes

Hashes for srsly-0.2.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 57a87513ffcf986d0da842241f2f01a2a719cb97c7ecb01d07f14e7c48392eb4
MD5 1634f0626e9f4556a0cc8fad2ea3e83c
BLAKE2b-256 a66818d4a2e6e54c8d9812da19b18c03fc9a1a0b6d8cad07b88731424dcac859

See more details on using hashes here.

File details

Details for the file srsly-0.2.0-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: srsly-0.2.0-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 174.9 kB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.6

File hashes

Hashes for srsly-0.2.0-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 97e5101d6ff08e5a2ebd83fc31b48c90aad24ba35eb4468f5b7ec56ecd8bdb6b
MD5 64763fd6072193f51e13cf3c7b60e600
BLAKE2b-256 b7a78829e71f434e442564dd9958299aa15c35885923aabe41bdc35f79887bad

See more details on using hashes here.

File details

Details for the file srsly-0.2.0-cp37-cp37m-manylinux1_x86_64.whl.

File metadata

  • Download URL: srsly-0.2.0-cp37-cp37m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 185.2 kB
  • Tags: CPython 3.7m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.6

File hashes

Hashes for srsly-0.2.0-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 798010e744469f65b3c492eac77d9b46a47a7bc229428f63e9c1c7445efc1809
MD5 ee02a580321cb7d96ceb824644305ba3
BLAKE2b-256 005a9a3288b648a0c5c86d0a2ef972b0a8062ff1088658da8165b370564ef346

See more details on using hashes here.

File details

Details for the file srsly-0.2.0-cp37-cp37m-macosx_10_6_intel.whl.

File metadata

  • Download URL: srsly-0.2.0-cp37-cp37m-macosx_10_6_intel.whl
  • Upload date:
  • Size: 275.3 kB
  • Tags: CPython 3.7m, macOS 10.6+ Intel (x86-64, i386)
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.6

File hashes

Hashes for srsly-0.2.0-cp37-cp37m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 f2f6a950b801352f596667459839235cf059b39307e4034d7ed68e7dfb497bd6
MD5 167131c4cda546ccef6217a23b1d8e00
BLAKE2b-256 44abfa09de5430537c12f445d049f3a2bad75cee160e81aae3455d34977c1e0e

See more details on using hashes here.

File details

Details for the file srsly-0.2.0-cp36-cp36m-win_amd64.whl.

File metadata

  • Download URL: srsly-0.2.0-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 175.3 kB
  • Tags: CPython 3.6m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.6

File hashes

Hashes for srsly-0.2.0-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 f48623820170eff0e2fc79419688a16f5977916548dd0d3a8d0d3fc93a7978ad
MD5 1564f66d1ecee0b1a266f4a7cc76f8ef
BLAKE2b-256 04cdf0fffcb49f06155698353e7b289e335ad085a02ca3cbd3b848ce0cc32f35

See more details on using hashes here.

File details

Details for the file srsly-0.2.0-cp36-cp36m-manylinux1_x86_64.whl.

File metadata

  • Download URL: srsly-0.2.0-cp36-cp36m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 185.3 kB
  • Tags: CPython 3.6m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.6

File hashes

Hashes for srsly-0.2.0-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 9e9a395ea53dbac0b705556246d1a9f8e5fea9ba49bc63ec3d3de05bfbe48735
MD5 11980b28f387b0447a8396760ce4641c
BLAKE2b-256 d7fb34136c7b2ad04d4472dd9ea86536f5e9fb71fb0eb78edc8dad76a3f9edf2

See more details on using hashes here.

File details

Details for the file srsly-0.2.0-cp36-cp36m-macosx_10_6_intel.whl.

File metadata

  • Download URL: srsly-0.2.0-cp36-cp36m-macosx_10_6_intel.whl
  • Upload date:
  • Size: 278.3 kB
  • Tags: CPython 3.6m, macOS 10.6+ Intel (x86-64, i386)
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.6

File hashes

Hashes for srsly-0.2.0-cp36-cp36m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 41f2fe803fe6985eb79982ce5d571b81413adfe2d01dcd470e55c6a0f16e07d8
MD5 d14624cba28c959db6957dd5268a9082
BLAKE2b-256 c5d4dafdfa1a5515b27b52e26ffb16eb9d80ab6d1071b04337d6c752c5eb352c

See more details on using hashes here.

File details

Details for the file srsly-0.2.0-cp35-cp35m-win_amd64.whl.

File metadata

  • Download URL: srsly-0.2.0-cp35-cp35m-win_amd64.whl
  • Upload date:
  • Size: 173.8 kB
  • Tags: CPython 3.5m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.6

File hashes

Hashes for srsly-0.2.0-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 6ec70d50d2a63452faf5b7606120310c4a95f2c24d931bd8f5babae9d1d99412
MD5 7a86a18582c4738b5b91418d8fca19ab
BLAKE2b-256 d507e0f090f52991597cfccb795f2b03a7dde00a96e3d5a4a255749a93c7e9ef

See more details on using hashes here.

File details

Details for the file srsly-0.2.0-cp35-cp35m-manylinux1_x86_64.whl.

File metadata

  • Download URL: srsly-0.2.0-cp35-cp35m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 183.8 kB
  • Tags: CPython 3.5m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.6

File hashes

Hashes for srsly-0.2.0-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 8730016fc5ca49dbaf676a8d02b12b184e909a26e596d51f46a6c71a963de462
MD5 45c18d98f89f392b9eea64d8c739ba76
BLAKE2b-256 1db368eb6f2788e100245f510d0da7fb9633744630acc9f40fef10ebd54d959d

See more details on using hashes here.

File details

Details for the file srsly-0.2.0-cp27-cp27mu-manylinux1_x86_64.whl.

File metadata

  • Download URL: srsly-0.2.0-cp27-cp27mu-manylinux1_x86_64.whl
  • Upload date:
  • Size: 180.6 kB
  • Tags: CPython 2.7mu
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.6

File hashes

Hashes for srsly-0.2.0-cp27-cp27mu-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 c62acffd96b4699820e39fcc47fc5a45ff14432c4665d4112ee08e42aeda047e
MD5 afe9c2929d0a7e8f922da276da723a24
BLAKE2b-256 e1a4f5fcb610d135b604937c4f2c8923ab524970b3ee88189e12ab9cd9696c64

See more details on using hashes here.

File details

Details for the file srsly-0.2.0-cp27-cp27m-manylinux1_x86_64.whl.

File metadata

  • Download URL: srsly-0.2.0-cp27-cp27m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 180.5 kB
  • Tags: CPython 2.7m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.6

File hashes

Hashes for srsly-0.2.0-cp27-cp27m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 d30074fdb05a739358fef33701315f8247161fbdb52f29fca368d10c2ef23fae
MD5 82da4fee71ca1d575dda5d2b02b9f3e3
BLAKE2b-256 7a8acdc55eed536772d67f7dd2ae5c3ddf0baf881c3353222e5264549d93a08f

See more details on using hashes here.

File details

Details for the file srsly-0.2.0-cp27-cp27m-macosx_10_6_intel.whl.

File metadata

  • Download URL: srsly-0.2.0-cp27-cp27m-macosx_10_6_intel.whl
  • Upload date:
  • Size: 270.5 kB
  • Tags: CPython 2.7m, macOS 10.6+ Intel (x86-64, i386)
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.6

File hashes

Hashes for srsly-0.2.0-cp27-cp27m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 8ffa7deafac1fb961385eff6feed324b5890b42175e1dde2c3e3fab2034756bb
MD5 e634ab1b32c92bf0673193dc811f58e4
BLAKE2b-256 a3038b51c211d642ac2f5faae5c5cfa0c09d43904297c910825e710642ff85bc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page