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.5.tar.gz (86.3 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.5-cp39-cp39-win_amd64.whl (177.8 kB view details)

Uploaded CPython 3.9Windows x86-64

srsly-1.0.5-cp39-cp39-manylinux2014_x86_64.whl (184.2 kB view details)

Uploaded CPython 3.9

srsly-1.0.5-cp39-cp39-macosx_10_9_x86_64.whl (179.9 kB view details)

Uploaded CPython 3.9macOS 10.9+ x86-64

srsly-1.0.5-cp38-cp38-win_amd64.whl (178.2 kB view details)

Uploaded CPython 3.8Windows x86-64

srsly-1.0.5-cp38-cp38-manylinux2014_x86_64.whl (186.5 kB view details)

Uploaded CPython 3.8

srsly-1.0.5-cp38-cp38-macosx_10_9_x86_64.whl (177.8 kB view details)

Uploaded CPython 3.8macOS 10.9+ x86-64

srsly-1.0.5-cp37-cp37m-win_amd64.whl (176.4 kB view details)

Uploaded CPython 3.7mWindows x86-64

srsly-1.0.5-cp37-cp37m-manylinux2014_x86_64.whl (184.3 kB view details)

Uploaded CPython 3.7m

srsly-1.0.5-cp37-cp37m-macosx_10_9_x86_64.whl (177.1 kB view details)

Uploaded CPython 3.7mmacOS 10.9+ x86-64

srsly-1.0.5-cp36-cp36m-win_amd64.whl (176.5 kB view details)

Uploaded CPython 3.6mWindows x86-64

srsly-1.0.5-cp36-cp36m-manylinux2014_x86_64.whl (184.2 kB view details)

Uploaded CPython 3.6m

srsly-1.0.5-cp36-cp36m-macosx_10_9_x86_64.whl (178.6 kB view details)

Uploaded CPython 3.6mmacOS 10.9+ x86-64

File details

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

File metadata

  • Download URL: srsly-1.0.5.tar.gz
  • Upload date:
  • Size: 86.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.7.9

File hashes

Hashes for srsly-1.0.5.tar.gz
Algorithm Hash digest
SHA256 d3dd796372367c71946d0cd6f734e49db3d99dd13a57bdac937d9eb62689fc9e
MD5 e239afc67bfd5e85ab9e2e3cd38f67a8
BLAKE2b-256 c708abe935f33b69a08d365b95e62b47ef48f93a69ab734e623248a8a4079ecb

See more details on using hashes here.

File details

Details for the file srsly-1.0.5-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: srsly-1.0.5-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 177.8 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.7.9

File hashes

Hashes for srsly-1.0.5-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 334f29435099e644a8047b63d60b8386a98b5f7b4739f7efc86b46ca0200aa0e
MD5 3cea5614414f19f0f4dfa25732491057
BLAKE2b-256 32e034310f61f6dcc6e6e3dd93600c0687f4d484377addf618a937691b67a097

See more details on using hashes here.

File details

Details for the file srsly-1.0.5-cp39-cp39-manylinux2014_x86_64.whl.

File metadata

  • Download URL: srsly-1.0.5-cp39-cp39-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 184.2 kB
  • Tags: CPython 3.9
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.7.9

File hashes

Hashes for srsly-1.0.5-cp39-cp39-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4c43a1f28e555891a1e65650adea2c5d0f0fe4b3d63821de65c8357f32c3a11c
MD5 0a042870ab69e0b9a900cf20ea1b6de4
BLAKE2b-256 237c09be4657debd5fb4e0002956329a0ca4fd163bdb4e9cd00fe9820c75255d

See more details on using hashes here.

File details

Details for the file srsly-1.0.5-cp39-cp39-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: srsly-1.0.5-cp39-cp39-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 179.9 kB
  • Tags: CPython 3.9, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.7.9

File hashes

Hashes for srsly-1.0.5-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 779ebfaa3cf1d5c0f1286ac1baf06af5f2a17bb103622992c71acc6ac20b2781
MD5 86f77a5d80632abd916a2a966c24fb5a
BLAKE2b-256 73ad7a8b1da7179b95e357b84f59d4161193bc815e780c22d1e4c52bc02c6cac

See more details on using hashes here.

File details

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

File metadata

  • Download URL: srsly-1.0.5-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 178.2 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.7.9

File hashes

Hashes for srsly-1.0.5-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 fd5e1e01f5fd0f532a6f3977bb74facc42f1b7155402ee3d06c07a73e83e3c47
MD5 16b8419fdedd8a5fa50dd4c732424023
BLAKE2b-256 73fd8b123bda298cc56118670cd3fc7d4474aff32750a1c0b2c7e387b781a012

See more details on using hashes here.

File details

Details for the file srsly-1.0.5-cp38-cp38-manylinux2014_x86_64.whl.

File metadata

  • Download URL: srsly-1.0.5-cp38-cp38-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 186.5 kB
  • Tags: CPython 3.8
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.7.9

File hashes

Hashes for srsly-1.0.5-cp38-cp38-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b5b887328ac6e210842560fcf32a29c2a9c1ed38c6d47479cadc03d81940da8c
MD5 744fc3088ad9ff858df85a2716d8cff4
BLAKE2b-256 83acbd460cd87e8644399cc042d7b757fceb5c7924cfe6aa37b3a406887e9432

See more details on using hashes here.

File details

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

File metadata

  • Download URL: srsly-1.0.5-cp38-cp38-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 177.8 kB
  • Tags: CPython 3.8, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.7.9

File hashes

Hashes for srsly-1.0.5-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 2615b8713dfe793ca57925076b0869385d56754816b1eaee5490a6827a1cb5c7
MD5 e2cbdee5774e35b1d392696e68cf722a
BLAKE2b-256 1baa6219d4f349fa1cb0b834d65d62b97db7b606347539ec730dcd4be5bde54f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: srsly-1.0.5-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 176.4 kB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.7.9

File hashes

Hashes for srsly-1.0.5-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 23c7205b8c1cac49a03521bee37f0afe3680d9f0ec18c75ab3ac39bd3e15272b
MD5 be58c38fa356e50cf723e967ee093960
BLAKE2b-256 349d23daf512877cc4a60e60d407926c69c01f91d8aa99fbc4177919f490dbd1

See more details on using hashes here.

File details

Details for the file srsly-1.0.5-cp37-cp37m-manylinux2014_x86_64.whl.

File metadata

  • Download URL: srsly-1.0.5-cp37-cp37m-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 184.3 kB
  • Tags: CPython 3.7m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.7.9

File hashes

Hashes for srsly-1.0.5-cp37-cp37m-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a1449da4195e30a3bd1fd3122e5b1a0c57703843c590643555c412fc87132aa0
MD5 951efb304d78e8000af0a6fc02f7cba9
BLAKE2b-256 cc4844bd8693a7a705976884cabd52a516fe5cbcecf5f45be732f8f04ad2605b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: srsly-1.0.5-cp37-cp37m-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 177.1 kB
  • Tags: CPython 3.7m, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.7.9

File hashes

Hashes for srsly-1.0.5-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 a2746afccfd4f51f0793cccc2b6d5e8a564c962870feec5c77408244c1dbb3c5
MD5 1b489dd0fd21ffbf5bad3afc71032a32
BLAKE2b-256 85be1b94141d3d65ddf86a7e63daeba72fbbf054ad6ad3a5d42b296f68c70030

See more details on using hashes here.

File details

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

File metadata

  • Download URL: srsly-1.0.5-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 176.5 kB
  • Tags: CPython 3.6m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.7.9

File hashes

Hashes for srsly-1.0.5-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 11447f8e659e1f62f29302252fb057f179031457b36c83426027182f624fe565
MD5 74a976e96b4c87aa465c65c0a88fdcd2
BLAKE2b-256 a9fb1c384843d66a33d2d32d25c4aca0c101dc71bf716275a97b2a154c83fa73

See more details on using hashes here.

File details

Details for the file srsly-1.0.5-cp36-cp36m-manylinux2014_x86_64.whl.

File metadata

  • Download URL: srsly-1.0.5-cp36-cp36m-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 184.2 kB
  • Tags: CPython 3.6m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.7.9

File hashes

Hashes for srsly-1.0.5-cp36-cp36m-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8fc4c0641537262e15c7b5b57edc47487b15ac47b696adcb81e0a770ef78e8f5
MD5 7b51c7755cb424174cfaec2448c80b40
BLAKE2b-256 526156e8aac918a220f53b11ce341eab7789e6b50e5d9b191a281dbb983e838e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: srsly-1.0.5-cp36-cp36m-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 178.6 kB
  • Tags: CPython 3.6m, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.7.9

File hashes

Hashes for srsly-1.0.5-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 a696e9c925e91f76ec53840c55483a4fbf76cb717424410a4f249d4805439038
MD5 1490a6711835dd02448280f0a1449d0f
BLAKE2b-256 6d23c8863fbb0f207762af5c334cbe1e58539b988114cf43274edd62bd93e31e

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