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 comile 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.

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.6.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.0.6-cp37-cp37m-win_amd64.whl (171.1 kB view details)

Uploaded CPython 3.7mWindows x86-64

srsly-0.0.6-cp37-cp37m-manylinux1_x86_64.whl (180.6 kB view details)

Uploaded CPython 3.7m

srsly-0.0.6-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 (270.9 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.6-cp36-cp36m-win_amd64.whl (171.5 kB view details)

Uploaded CPython 3.6mWindows x86-64

srsly-0.0.6-cp36-cp36m-manylinux1_x86_64.whl (180.7 kB view details)

Uploaded CPython 3.6m

srsly-0.0.6-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.0 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.6-cp35-cp35m-win_amd64.whl (170.0 kB view details)

Uploaded CPython 3.5mWindows x86-64

srsly-0.0.6-cp35-cp35m-manylinux1_x86_64.whl (179.1 kB view details)

Uploaded CPython 3.5m

srsly-0.0.6-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.5 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.6-cp27-cp27mu-manylinux1_x86_64.whl (175.4 kB view details)

Uploaded CPython 2.7mu

srsly-0.0.6-cp27-cp27m-win_amd64.whl (163.5 kB view details)

Uploaded CPython 2.7mWindows x86-64

srsly-0.0.6-cp27-cp27m-manylinux1_x86_64.whl (175.4 kB view details)

Uploaded CPython 2.7m

srsly-0.0.6-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.6 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.6.tar.gz.

File metadata

  • Download URL: srsly-0.0.6.tar.gz
  • Upload date:
  • Size: 186.1 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.6.tar.gz
Algorithm Hash digest
SHA256 dea20a00344a5f54fc5733df8ca742e4ecf404ef7b829ea674b3b5f5eefd20c4
MD5 8ac9fee4fcfd14216581a400347ffbed
BLAKE2b-256 591b542f85474db8be31bdd6350f2d33ac8db110a98b58b30f42e2dbc446174b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: srsly-0.0.6-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 171.1 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.6-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 00bfa174c8f0b5dcfc60c0c842d4a53cffe42058c29619c123c4739585749418
MD5 a6dbd7fb623ffe246ebc5eabb9756caf
BLAKE2b-256 fd57ba897bb610e368bb7108a2f8531596b406d3c26f62a10d21a8c948db3e1a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: srsly-0.0.6-cp37-cp37m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 180.6 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.6-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 bb2c6fd7dc161bddaadd20a68631f00c45e1b396a0948c862ddc4ddccdc4dbb4
MD5 a595755e22c990e00c88b1b754c7704f
BLAKE2b-256 36ab81c71ce6fb3a575a187c8971577b812b8ba36840cd9130eb9b31ed80d3ad

See more details on using hashes here.

File details

Details for the file srsly-0.0.6-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.6-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 5c9d00f02cf6929457f94175da46ef346d24a6f64cec6ed848c5a98001eed134
MD5 32c02ecaf0c75b47e7b44bc062cd4ff3
BLAKE2b-256 a54c2d698d6665c3905f698c3c7300fdd259f7c21c1a6f6c3b44df29d089fc4b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: srsly-0.0.6-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 171.5 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.6-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 419b003f19fb8aa6af40d3ef1f4bf50cb3a1834a3f61e65a61e6067b22111a28
MD5 f0e51e7ec2c2e99fe8deecd953ddbe60
BLAKE2b-256 0d25fdbebdf52098d1112d3514061ee3840c81528f0cb43623893d9ffc677bad

See more details on using hashes here.

File details

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

File metadata

  • Download URL: srsly-0.0.6-cp36-cp36m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 180.7 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.6-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 0264d21d6832010789623610a01d735149c1fa279d622b64a5725a0f22e33b2f
MD5 e4b3ecd28fafcd80f32413cbb246044f
BLAKE2b-256 4ceddadafaf4685d261e9a9583e4b27c5d94ae162b1435439d7eadf261d34c01

See more details on using hashes here.

File details

Details for the file srsly-0.0.6-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.6-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 023154016f8b5660768bd3c07bb5e8fb52816b4b81b0588c0b9614a0af5d8b10
MD5 2ac57ca16d1889a9a8fd10584228d38a
BLAKE2b-256 6ddb2658a336e3e8f9fbd30357bedd722056093ef1de5cb835ae395e1ebed836

See more details on using hashes here.

File details

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

File metadata

  • Download URL: srsly-0.0.6-cp35-cp35m-win_amd64.whl
  • Upload date:
  • Size: 170.0 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.6-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 4e9fa383d4d0b38013a5c690986a4015a5b0d61b16f030d0538c4785bb8f79c7
MD5 e68ea1e470fccc8630d9ba6b85f96aeb
BLAKE2b-256 4cc8b7465d537ba3288e02f05ec8e7a77c0db21c6c6f7caa14a5944716dedb62

See more details on using hashes here.

File details

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

File metadata

  • Download URL: srsly-0.0.6-cp35-cp35m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 179.1 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.6-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 fe2c326fbccaed38b16227bfd423d918396512bb31262941ffc7225216a8fa5c
MD5 953b67c6be993ab0808b11bf2d4deeb8
BLAKE2b-256 27c0a516f7d224c1fc76de0b6b3f6df4ac4f58f1f7390374727346ec1aa49af1

See more details on using hashes here.

File details

Details for the file srsly-0.0.6-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.6-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 1bb289a2cf0caccea391c4dd2fb7c1b61405ad722334f5a4e52e14b9f97540a7
MD5 68f676dcf346f7efb817ea9d62307af0
BLAKE2b-256 7dbe03f4063ac5e2387698cc7280067e74b527e6d08e957b4f8332e1fb1519f2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: srsly-0.0.6-cp27-cp27mu-manylinux1_x86_64.whl
  • Upload date:
  • Size: 175.4 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.6-cp27-cp27mu-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 60e78e760bb0df0a01d33bbc1d9f0274060b7ecfa8b6178903107d3056d314ad
MD5 06d6811d47f777b88eed1d3db0211b93
BLAKE2b-256 f6b51e40d0b8958a87cbb4b500535953f6a9f82054e63af473d66533d0494ac9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: srsly-0.0.6-cp27-cp27m-win_amd64.whl
  • Upload date:
  • Size: 163.5 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.6-cp27-cp27m-win_amd64.whl
Algorithm Hash digest
SHA256 ecead9694743976cf459b84a88f3520d9a8c4eddc720d0d2df84f98bd6ab412c
MD5 2f92b60c14598e307c511c4edeccacab
BLAKE2b-256 c36482c810e15fc995331739765bb66297b35ada7f1d4b783c9454d238ea7a60

See more details on using hashes here.

File details

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

File metadata

  • Download URL: srsly-0.0.6-cp27-cp27m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 175.4 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.6-cp27-cp27m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 4f121db67154ab4a0fd66a9b290bf10662f9eec564a238d5183b8cf184712dc5
MD5 733d7611b1df30b16e18b802ae85a5a7
BLAKE2b-256 1546c79b1d3925d01c249a5c3dcd53116e0fb61b51204ec6ffa2398afa6c8c50

See more details on using hashes here.

File details

Details for the file srsly-0.0.6-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.6-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 b5906fdd3b024a11b10d0f34072abd5a6333c4b41baac7dfa0a75ce0b7df9c63
MD5 850b5d816b59150c3cccee948073b182
BLAKE2b-256 a9624df8edcc08f4c8d2f335de19397cbdaf8149863d0bcb1783a81b6104126e

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