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_gzip_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-1.0.2.tar.gz (192.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-1.0.2-cp38-cp38-win_amd64.whl (181.2 kB view details)

Uploaded CPython 3.8Windows x86-64

srsly-1.0.2-cp38-cp38-manylinux1_x86_64.whl (186.0 kB view details)

Uploaded CPython 3.8

srsly-1.0.2-cp38-cp38-macosx_10_9_x86_64.whl (183.6 kB view details)

Uploaded CPython 3.8macOS 10.9+ x86-64

srsly-1.0.2-cp37-cp37m-win_amd64.whl (179.5 kB view details)

Uploaded CPython 3.7mWindows x86-64

srsly-1.0.2-cp37-cp37m-manylinux1_x86_64.whl (185.5 kB view details)

Uploaded CPython 3.7m

srsly-1.0.2-cp37-cp37m-macosx_10_9_x86_64.whl (182.5 kB view details)

Uploaded CPython 3.7mmacOS 10.9+ x86-64

srsly-1.0.2-cp36-cp36m-win_amd64.whl (179.6 kB view details)

Uploaded CPython 3.6mWindows x86-64

srsly-1.0.2-cp36-cp36m-manylinux1_x86_64.whl (185.6 kB view details)

Uploaded CPython 3.6m

srsly-1.0.2-cp36-cp36m-macosx_10_9_x86_64.whl (184.1 kB view details)

Uploaded CPython 3.6mmacOS 10.9+ x86-64

srsly-1.0.2-cp35-cp35m-win_amd64.whl (174.9 kB view details)

Uploaded CPython 3.5mWindows x86-64

srsly-1.0.2-cp35-cp35m-manylinux1_x86_64.whl (184.0 kB view details)

Uploaded CPython 3.5m

File details

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

File metadata

  • Download URL: srsly-1.0.2.tar.gz
  • Upload date:
  • Size: 192.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.8

File hashes

Hashes for srsly-1.0.2.tar.gz
Algorithm Hash digest
SHA256 59258b81d567df207f8a0a33c4b5fa232afccf1d927c8ce3ba5395bfd64c0ed8
MD5 b3b4ae2fe58dca7cf85323c0bd3b2946
BLAKE2b-256 c428ffb9f0b940041aeaec2194e840b5ffe19d0ae252de89579fa8b810174d9f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: srsly-1.0.2-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 181.2 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.8

File hashes

Hashes for srsly-1.0.2-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 29434753a77481ec6129991f4116f983085cc8005c1ad963261124842e8c05fc
MD5 5f61976addf548275e8ed33e99d85277
BLAKE2b-256 a9c95d87269fda7a8ae2b87554624bccf429d8d40769fcf75c336a1a6bfd9a17

See more details on using hashes here.

File details

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

File metadata

  • Download URL: srsly-1.0.2-cp38-cp38-manylinux1_x86_64.whl
  • Upload date:
  • Size: 186.0 kB
  • Tags: CPython 3.8
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.8

File hashes

Hashes for srsly-1.0.2-cp38-cp38-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 18bad26c34cf5a8853fbf018fd168a7bf2ea7ce661e66476c25dac711cb79c9b
MD5 1c59042b3b3c0409557998bb1fe0d8a5
BLAKE2b-256 1e18eff2f26419bf99a0a18acfe287d98a0bedb1a65618f86bdbe95c5acd580b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: srsly-1.0.2-cp38-cp38-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 183.6 kB
  • Tags: CPython 3.8, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.8

File hashes

Hashes for srsly-1.0.2-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 d409beb7257208633c974c01f9dc3265562fb6802caee7de21880761ba87c3ed
MD5 b2befe4ba35a06a4140e8fd49077037f
BLAKE2b-256 e2d448d759d471dc2001257ef9d0d62c3e3769bd7746ea4561528c39cdd42888

See more details on using hashes here.

File details

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

File metadata

  • Download URL: srsly-1.0.2-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 179.5 kB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.8

File hashes

Hashes for srsly-1.0.2-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 3f3975e8cb67194d26dd03508469b1303f8b994f30e7782f7eae25fef6dc4aad
MD5 7a016ece2ae5b2ad645fc456064c11e4
BLAKE2b-256 fd31edaf3cdb7fcb644a51c7a568bc62a8c8d7462e61fa79b090f4d12d73d39e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: srsly-1.0.2-cp37-cp37m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 185.5 kB
  • Tags: CPython 3.7m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.8

File hashes

Hashes for srsly-1.0.2-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 95849d84e8929be248a180e672c8ce1ed98b1341263bc983efdf8427465584f1
MD5 7463573719ce3d8c47c488d39265b0af
BLAKE2b-256 4c270e1deb477dd422427a18d8283b7aacf48b5f77c668feeb2c4920ee6cc3a3

See more details on using hashes here.

File details

Details for the file srsly-1.0.2-cp37-cp37m-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: srsly-1.0.2-cp37-cp37m-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 182.5 kB
  • Tags: CPython 3.7m, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.8

File hashes

Hashes for srsly-1.0.2-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 c8beff52c104a7ffe4a15513a05dc0497998cf83aa1ca39454489994d18c1c07
MD5 3f4410d13e5944b3a9b4fcf9cb2f75f5
BLAKE2b-256 77212bfb8d559ed128b43e3a12e28579ab5f6b043f1ac079168de3025c0d0a39

See more details on using hashes here.

File details

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

File metadata

  • Download URL: srsly-1.0.2-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 179.6 kB
  • Tags: CPython 3.6m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.8

File hashes

Hashes for srsly-1.0.2-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 b94d8a13c60e3298a9ba12b1b211026e8378c7d087efd7ce46a3f2d8d4678d94
MD5 ed6fda807844ebb1e62b7fa858382147
BLAKE2b-256 3ad6939d46c05289b185226a576421079468123b1719ffe16e181e0005d45ef9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: srsly-1.0.2-cp36-cp36m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 185.6 kB
  • Tags: CPython 3.6m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.8

File hashes

Hashes for srsly-1.0.2-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 2179cf1e88c250e89e40227bd5848341011c170079b3d424987d067de6a73f42
MD5 7f94229388d2101682a17273e344cf6c
BLAKE2b-256 0e9a70bd934dd4d25545c9aa6c8cd4edbac2a33ba9c915439a9209b69f0ec0ad

See more details on using hashes here.

File details

Details for the file srsly-1.0.2-cp36-cp36m-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: srsly-1.0.2-cp36-cp36m-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 184.1 kB
  • Tags: CPython 3.6m, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.8

File hashes

Hashes for srsly-1.0.2-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 46213d8f094b348a9433c825ac1eba36a21aa25a8bae6f29c2f9f053e15be961
MD5 e03026f8c16e902add97260cbb085869
BLAKE2b-256 6dc825815a551ce777d298f581e15bb48579fe61c23368837dc1b5cebf6b5477

See more details on using hashes here.

File details

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

File metadata

  • Download URL: srsly-1.0.2-cp35-cp35m-win_amd64.whl
  • Upload date:
  • Size: 174.9 kB
  • Tags: CPython 3.5m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.8

File hashes

Hashes for srsly-1.0.2-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 21cfb0e5dea2c4515b5c2daa78402d5782c6425b4f58af40d2e2cb45e4778d8c
MD5 a2cfdff71c52fcde7e972f67802f4e72
BLAKE2b-256 c40fae21a4135abc789f9d2e2c3bff05b1fa33cb9f718947ce61a874893b7f5e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: srsly-1.0.2-cp35-cp35m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 184.0 kB
  • Tags: CPython 3.5m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.8

File hashes

Hashes for srsly-1.0.2-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 7c553a709fd56a37a07f969e849f55a0aeabaeb7677bebc588a640ab8ec134aa
MD5 a236dc345195b45d4c8b028ee1f7f732
BLAKE2b-256 e00d6a6bb9831cadbeae24454238ed0dd38d2d1e714489c6a4a72b8187662792

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