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_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.0.7.tar.gz (186.4 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.0.7-cp37-cp37m-win_amd64.whl (171.2 kB view details)

Uploaded CPython 3.7mWindows x86-64

srsly-0.0.7-cp37-cp37m-manylinux1_x86_64.whl (180.7 kB view details)

Uploaded CPython 3.7m

srsly-0.0.7-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 (271.0 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.0.7-cp36-cp36m-win_amd64.whl (171.6 kB view details)

Uploaded CPython 3.6mWindows x86-64

srsly-0.0.7-cp36-cp36m-manylinux1_x86_64.whl (180.8 kB view details)

Uploaded CPython 3.6m

srsly-0.0.7-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 (274.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.0.7-cp35-cp35m-win_amd64.whl (170.1 kB view details)

Uploaded CPython 3.5mWindows x86-64

srsly-0.0.7-cp35-cp35m-manylinux1_x86_64.whl (179.2 kB view details)

Uploaded CPython 3.5m

srsly-0.0.7-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 (267.6 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.0.7-cp27-cp27mu-manylinux1_x86_64.whl (175.5 kB view details)

Uploaded CPython 2.7mu

srsly-0.0.7-cp27-cp27m-win_amd64.whl (163.6 kB view details)

Uploaded CPython 2.7mWindows x86-64

srsly-0.0.7-cp27-cp27m-manylinux1_x86_64.whl (175.5 kB view details)

Uploaded CPython 2.7m

srsly-0.0.7-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 (266.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.0.7.tar.gz.

File metadata

  • Download URL: srsly-0.0.7.tar.gz
  • Upload date:
  • Size: 186.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.6

File hashes

Hashes for srsly-0.0.7.tar.gz
Algorithm Hash digest
SHA256 f3a2948b088064f719918ef46a1f14ffbd3ccab4c639c4ecb65053814fb036ed
MD5 49db681e1dc3d42142a773a814a07b07
BLAKE2b-256 84596f276ab6d74888eed0e999d617101ed7357fc1ee073e9aac92d53260bd23

See more details on using hashes here.

File details

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

File metadata

  • Download URL: srsly-0.0.7-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 171.2 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.0.7-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 f845dc259a18a6ed83c4bc3dde6722563b4a7536a23c5a8c2159cdd242b8f994
MD5 c75cad06377aee2929936f0330ddc655
BLAKE2b-256 218989033beed5e5c5216a6c2c057244bd81944a054e251ef2330ddcde8e13ac

See more details on using hashes here.

File details

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

File metadata

  • Download URL: srsly-0.0.7-cp37-cp37m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 180.7 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.0.7-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 78d987ad6b785badfe6150c314b0150ee2bf99f3ca38e138ebb2c024911d528e
MD5 f5c680462158f016ab0c957dbcfbe804
BLAKE2b-256 f9d275ed228767b20b1109f52d08d6db2f4c4ca33c5ab55f0d7f0422a390dd02

See more details on using hashes here.

File details

Details for the file srsly-0.0.7-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.0.7-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 7aaccb4e8e73f825b0ae49f6712c43792c4281e4126fdbd2812314d6704e27a4
MD5 3caacb5673309657a251810668a40286
BLAKE2b-256 44f9092f2f006150c92b13096811f5797f2430f55cb2756cb83ee421f59b2a3f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: srsly-0.0.7-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 171.6 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.0.7-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 e1f6779a993740da8545ac0e1d2b8d5b27cc67e318c6b8bf200481165c76d6e4
MD5 4b7d4d4ef2fcd462a93e46024f6e71d2
BLAKE2b-256 8cb575b8284a3ec9d6cc98a3fef0a581bf0b3493adabb1d33751fc1aa969f4e3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: srsly-0.0.7-cp36-cp36m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 180.8 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.0.7-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 b7d539d70c30c272542ca3aae0b2a75f2ca455687c951a238aab69e57bfd4ef6
MD5 b223ef2160b5c650f09c7a47e0805fcc
BLAKE2b-256 aa6c2ef2d6f4c63a197981f4ac01bb17560c857c6721213c7c99998e48cdda2a

See more details on using hashes here.

File details

Details for the file srsly-0.0.7-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.0.7-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 9ccb083828b1443eb016bc874bb4854618c439181065e62d157c5d91064f048c
MD5 beb20ad7ddc2f3cbbb8c18c631ca1709
BLAKE2b-256 3854ce024ddd9b3f55316ff6b956a84b537a400b0e82f88c6fce0f0cf2c71bef

See more details on using hashes here.

File details

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

File metadata

  • Download URL: srsly-0.0.7-cp35-cp35m-win_amd64.whl
  • Upload date:
  • Size: 170.1 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.0.7-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 7d3a67800a651b367dec37195481b8e6ef11b7747501c45177c333bcf0f1413c
MD5 5de951a68651c8c3ba81921bf665a011
BLAKE2b-256 5e03ec7f846d709182847d72dca4259c13260246da3e7b27ae749dff71fcf99c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: srsly-0.0.7-cp35-cp35m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 179.2 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.0.7-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 c5a9bc9d04d1dbc2d40776c2a11a70dbb5253ef10b4e0203b70c96d8540f10c6
MD5 512749afa11adb83148cebdae5a20fd8
BLAKE2b-256 0273c8d50b8b012c2207f0bff363a122e06a49c63abb8a6ee0ebf3e38408437c

See more details on using hashes here.

File details

Details for the file srsly-0.0.7-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.0.7-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 7817c37b0c01279e6d12fee1fc11eaea8e4110d5642834b68cd3d15307d8b6df
MD5 cca24109c947b00b325253c4478741e7
BLAKE2b-256 4f1c45063071e910b8f0dc686701d9a76fb8785f66374ed7b2ebb9d9f1a833d9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: srsly-0.0.7-cp27-cp27mu-manylinux1_x86_64.whl
  • Upload date:
  • Size: 175.5 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.0.7-cp27-cp27mu-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 c2a1f597f83e4356618bd49b395c05c87e02bb4a67aaf175d391e7b0f940708b
MD5 87adddc87b4dfd566a05883c18216d16
BLAKE2b-256 3d17e003b2e9122500762a9ba6f3dfe4db912604e6be840c7d3041ae72787ae3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: srsly-0.0.7-cp27-cp27m-win_amd64.whl
  • Upload date:
  • Size: 163.6 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.0.7-cp27-cp27m-win_amd64.whl
Algorithm Hash digest
SHA256 dc4163ad94bda47196c57ef438dc718569f264ef11e8079b3e85f73a2b9bde7f
MD5 1523e5e37032f53cba23ee8789ec2008
BLAKE2b-256 6688858974be94b86969f465f0ac771709989378356ec15ba547998c203b0f55

See more details on using hashes here.

File details

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

File metadata

  • Download URL: srsly-0.0.7-cp27-cp27m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 175.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.0.7-cp27-cp27m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 d717fddc3772308f97cee018c1c8d5202f47a223782f5bc28bf5f588bd261fb6
MD5 91e3a0d25428e5761db996390123b2ac
BLAKE2b-256 63b0f76c674eb9edabb839ee5e52967ad03b3493da5917c2094f977ed852320e

See more details on using hashes here.

File details

Details for the file srsly-0.0.7-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.0.7-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 06c98093f9d1e2573e6bcb64945b748326b31aa3dd8c4945f195a9f33858b420
MD5 4d8800c541883a095f8b5ebcd14117ae
BLAKE2b-256 5827b0986acc12fc417c6767972ec56b95a353e09658d208526bcee3c19d773a

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