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

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.

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.1.0.tar.gz (186.1 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.1.0-cp37-cp37m-win_amd64.whl (171.5 kB view details)

Uploaded CPython 3.7mWindows x86-64

srsly-0.1.0-cp37-cp37m-manylinux1_x86_64.whl (181.8 kB view details)

Uploaded CPython 3.7m

srsly-0.1.0-cp37-cp37m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (272.1 kB view details)

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

srsly-0.1.0-cp36-cp36m-win_amd64.whl (171.9 kB view details)

Uploaded CPython 3.6mWindows x86-64

srsly-0.1.0-cp36-cp36m-manylinux1_x86_64.whl (182.0 kB view details)

Uploaded CPython 3.6m

srsly-0.1.0-cp36-cp36m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (275.1 kB view details)

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

srsly-0.1.0-cp35-cp35m-win_amd64.whl (170.4 kB view details)

Uploaded CPython 3.5mWindows x86-64

srsly-0.1.0-cp35-cp35m-manylinux1_x86_64.whl (180.4 kB view details)

Uploaded CPython 3.5m

srsly-0.1.0-cp35-cp35m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (268.7 kB view details)

Uploaded CPython 3.5mmacOS 10.10+ Intel (x86-64, i386)macOS 10.10+ x86-64macOS 10.6+ Intel (x86-64, i386)macOS 10.9+ Intel (x86-64, i386)macOS 10.9+ x86-64

srsly-0.1.0-cp27-cp27mu-manylinux1_x86_64.whl (176.7 kB view details)

Uploaded CPython 2.7mu

srsly-0.1.0-cp27-cp27m-win_amd64.whl (163.8 kB view details)

Uploaded CPython 2.7mWindows x86-64

srsly-0.1.0-cp27-cp27m-manylinux1_x86_64.whl (176.7 kB view details)

Uploaded CPython 2.7m

srsly-0.1.0-cp27-cp27m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (267.7 kB view details)

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

File details

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

File metadata

  • Download URL: srsly-0.1.0.tar.gz
  • Upload date:
  • Size: 186.1 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.1.0.tar.gz
Algorithm Hash digest
SHA256 5cc0dc561fa70cf12d21d192990a48388a78c8062cd3dcadcf336fc1c3953ed1
MD5 80b9e18124c58ce509c262bd3ccc490c
BLAKE2b-256 b063b68061954228346cbab2c41adb36339678605c47da016f5c71c7ef65f510

See more details on using hashes here.

File details

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

File metadata

  • Download URL: srsly-0.1.0-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 171.5 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.1.0-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 eff9902cb28f4d54cd44d8f363d0b4e67ccc7a01e4558d6565f7ece37c654b08
MD5 ff2b4d45934e883f66e0f41364778d93
BLAKE2b-256 9fd9dc2979367b3f850ca31c181d58e05c26e7d3c0d4e71ab8455e26db979b2c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: srsly-0.1.0-cp37-cp37m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 181.8 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.1.0-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 ca77055c8c489e818532c300e74c2d1ff715396b12c1842065807b27b6906078
MD5 c2b7aec18ddfb677a1e6bc8b1d7e90e4
BLAKE2b-256 1ca38d84ede325d26075a4e1e2cba01201c6301545bca96dbff60ab9e9d96c3e

See more details on using hashes here.

File details

Details for the file srsly-0.1.0-cp37-cp37m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl.

File metadata

File hashes

Hashes for srsly-0.1.0-cp37-cp37m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
Algorithm Hash digest
SHA256 f128a3a57fed854930321527bd888a19c0a328cf70d1ca104cbc513f422b2860
MD5 489bb954088492f60d90bf52dac3a519
BLAKE2b-256 66aba26c85fe8e4d416a482bdafa4ea36fb59add449f0d00ec45ab51036528e3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: srsly-0.1.0-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 171.9 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.1.0-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 65ea2f04b2dc49e2f5ac3091cf6c41da81f192a44859f6ac947892610ff7326e
MD5 0efe8d901a4931b50a023f622204ee3b
BLAKE2b-256 e411664f4cf38222cfb718724576c16f806f131ef4ad94bf7d8fb9802ecb4a41

See more details on using hashes here.

File details

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

File metadata

  • Download URL: srsly-0.1.0-cp36-cp36m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 182.0 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.1.0-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 8b253482060917a07dbdaad66d03fd4071cbcc81c8e8534c1c87b99aa5c37021
MD5 913f865532608edeeeb8b23b5e76b7cf
BLAKE2b-256 8c600c448942ad5bd246c7abfbb7e1a1d8ec2b013f3e9a0abf180fc52b588fe4

See more details on using hashes here.

File details

Details for the file srsly-0.1.0-cp36-cp36m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl.

File metadata

File hashes

Hashes for srsly-0.1.0-cp36-cp36m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
Algorithm Hash digest
SHA256 95b9cb2463348173cf70bb161dbf96706a490d74cab3ee7f97dcc39870e23887
MD5 eca5cd79326af269ea88fd14376a6af2
BLAKE2b-256 bdb1d10e2447397b4b2d74a874f7600f1a36f7e35c832775e8a32a5787aced90

See more details on using hashes here.

File details

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

File metadata

  • Download URL: srsly-0.1.0-cp35-cp35m-win_amd64.whl
  • Upload date:
  • Size: 170.4 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.1.0-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 2b8d791b4a8ded47ce6a474903fb05d16bcdbabfcf8a5acde337ed5100fd45b9
MD5 72e5b0a2a38a805e777e8b107738cc9b
BLAKE2b-256 55e4de1921fbd859b90d2d8423239ad34a770244b2aa2ddfc90ed7f382834536

See more details on using hashes here.

File details

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

File metadata

  • Download URL: srsly-0.1.0-cp35-cp35m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 180.4 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.1.0-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 e623bb69585e8e014ddba20fce4cbca64ccc40b425a1496e291827a5fc274d06
MD5 267734acf2578d1291979b48bcc25f13
BLAKE2b-256 f3f9efafdda1cd36396194759ff12cb074366051f9dd15a0b99371f83e9be0ff

See more details on using hashes here.

File details

Details for the file srsly-0.1.0-cp35-cp35m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl.

File metadata

File hashes

Hashes for srsly-0.1.0-cp35-cp35m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
Algorithm Hash digest
SHA256 ab5650609761ccf31c8051d1c0dcbaa5579d47363b8c634f4e2643099188f5c8
MD5 22bceb36e0318600c55076c83bd8efcb
BLAKE2b-256 80cf511a7f75fb9e2a966810427e1d945703b39336f6667e40db749cd5412f1c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: srsly-0.1.0-cp27-cp27mu-manylinux1_x86_64.whl
  • Upload date:
  • Size: 176.7 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.1.0-cp27-cp27mu-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 4488eb4bd60825ac4ebf8dc4f8d8a0a87c5ef643b923764b9468315e3bef1ecd
MD5 263ed3fcdec99c1f02d02b934048b6cf
BLAKE2b-256 a5964c65e8f2aec3a9c9f40f0d0debdd3035f1cbf81947633a1a2cb59532b305

See more details on using hashes here.

File details

Details for the file srsly-0.1.0-cp27-cp27m-win_amd64.whl.

File metadata

  • Download URL: srsly-0.1.0-cp27-cp27m-win_amd64.whl
  • Upload date:
  • Size: 163.8 kB
  • Tags: CPython 2.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.1.0-cp27-cp27m-win_amd64.whl
Algorithm Hash digest
SHA256 04e15e87a373243dd0f09c002374eb773051575c3a360431c27aca590105bfe5
MD5 ff1e7aa52096bc05e6991dbe272a5ea2
BLAKE2b-256 b18a669f18d7bd006de1803c5ca47d81c53dea86d48ce51fc14fc8652a741b93

See more details on using hashes here.

File details

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

File metadata

  • Download URL: srsly-0.1.0-cp27-cp27m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 176.7 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.1.0-cp27-cp27m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 0c5adb835342070dbb8305e797ed1b7840ee4b0f14e8d037548f5425bdbc49e7
MD5 1a68a9d6bc9fe930bcad762df67ff401
BLAKE2b-256 f013408b34daf2d80559bb757d1f68703cd97aa971eac42e62a8126c12c1794d

See more details on using hashes here.

File details

Details for the file srsly-0.1.0-cp27-cp27m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl.

File metadata

File hashes

Hashes for srsly-0.1.0-cp27-cp27m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
Algorithm Hash digest
SHA256 e2f0dc57b6ea0848e2a3a867be6aa5e5ce3b1a6cc28be9b3c7dd0c49bd280fc9
MD5 32b15e58b27c1e569ba956abff25ae2c
BLAKE2b-256 670cb2b44ba3d0a7913f4e27e3e31ee54fa8bc26118ebbcdc55912e9cab038d4

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