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.

⚠️ Still under construction!

Travis Appveyor PyPi 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 maintainence 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.jsonl", 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.5.tar.gz (184.9 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.5-cp37-cp37m-win_amd64.whl (170.5 kB view details)

Uploaded CPython 3.7mWindows x86-64

srsly-0.0.5-cp37-cp37m-manylinux1_x86_64.whl (180.0 kB view details)

Uploaded CPython 3.7m

srsly-0.0.5-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.2 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.5-cp36-cp36m-win_amd64.whl (170.9 kB view details)

Uploaded CPython 3.6mWindows x86-64

srsly-0.0.5-cp36-cp36m-manylinux1_x86_64.whl (180.2 kB view details)

Uploaded CPython 3.6m

srsly-0.0.5-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 (273.3 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.5-cp35-cp35m-win_amd64.whl (169.5 kB view details)

Uploaded CPython 3.5mWindows x86-64

srsly-0.0.5-cp35-cp35m-manylinux1_x86_64.whl (178.6 kB view details)

Uploaded CPython 3.5m

srsly-0.0.5-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 (266.9 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.5-cp27-cp27mu-manylinux1_x86_64.whl (174.9 kB view details)

Uploaded CPython 2.7mu

srsly-0.0.5-cp27-cp27m-win_amd64.whl (162.9 kB view details)

Uploaded CPython 2.7mWindows x86-64

srsly-0.0.5-cp27-cp27m-manylinux1_x86_64.whl (174.9 kB view details)

Uploaded CPython 2.7m

srsly-0.0.5-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.0 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.5.tar.gz.

File metadata

  • Download URL: srsly-0.0.5.tar.gz
  • Upload date:
  • Size: 184.9 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.0.5.tar.gz
Algorithm Hash digest
SHA256 977aa6e5fd3f7e9d1c8fe7aeed841dfe3ede75dfce04255d4c670e663faaef2a
MD5 740c9c742d81de8a3a60e9da11213462
BLAKE2b-256 05df6ad3ad1d2747b0ef17e674c8cf7f0cb5e5c0056ee6e9b2ebc88e55871cd4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: srsly-0.0.5-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 170.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.0.5-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 850399e43f4cefdcac7a913363b120ea084cb02fcfdbbde1bd37444804d7def4
MD5 c36924ffa2eff4ab1debb1a80e855f2c
BLAKE2b-256 cb1850c367d3da6bf24fee73f6edae6409d59b997804beab25d13216190bde65

See more details on using hashes here.

File details

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

File metadata

  • Download URL: srsly-0.0.5-cp37-cp37m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 180.0 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.5-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 1e4ef85bf133e384f465865ba4e0a14a52c4f2e4b46c763faf100339a06f09c4
MD5 ffde34e2672415f4e2191f4be2412926
BLAKE2b-256 c248b688b6657a723c7b938deedc72edda2d97ea8848709a2830997a118caaec

See more details on using hashes here.

File details

Details for the file srsly-0.0.5-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.5-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 ef7897050c04a313f2db99c9bcaf2f0c3c75609677683ca5a6e1e7a515325d72
MD5 e1c05a4d46b5730b37ee05a3572b9220
BLAKE2b-256 c8b2d2cc9f5aa5a458aca45d8689279b41d4b42ba4e8c63b0cb6a9f009340fd0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: srsly-0.0.5-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 170.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.0.5-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 d7c91f59edc2ceeca70adf1b0a46d337234ff4fb7ca2b579ca41885f011b329f
MD5 e2353f1f2e217e3b66b98e792d9e7e25
BLAKE2b-256 8bd8dd8cd2a1620d5ebbc808cd3937e498ce63a58c2207366edba196df093032

See more details on using hashes here.

File details

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

File metadata

  • Download URL: srsly-0.0.5-cp36-cp36m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 180.2 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.5-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 1bf6af7a86f34969a3997da09fc8c2f72ee02cd74ff40035e37c2f968776fa23
MD5 cd22ada760128f6bb4422ceb4675ad6a
BLAKE2b-256 6b9747753e3393aa4b18de9f942fac26f18879d1ae950243a556888f389d1398

See more details on using hashes here.

File details

Details for the file srsly-0.0.5-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.5-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 d906a2a3df1cac2cb4bf382b8aaf14e22df2ca3758eba0d3049723c851c8ebf0
MD5 85124bc2e8afb6e525ba34f193c80bc6
BLAKE2b-256 ff9f19db645dcc2798e04b12f66859af69e421d76ae63100171d670ec5029f63

See more details on using hashes here.

File details

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

File metadata

  • Download URL: srsly-0.0.5-cp35-cp35m-win_amd64.whl
  • Upload date:
  • Size: 169.5 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.5-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 abdc5b46866648b123517550582dc4c4b767b816ae54c44e5973bbebc3f0dab4
MD5 8dcbbd11901c6a47c41c7d3445d11d89
BLAKE2b-256 c2675791e1f4bf6a8bb1ed3ab7538205c985a106dc8fa3390056f1a071d789c6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: srsly-0.0.5-cp35-cp35m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 178.6 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.5-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 b8646f0f7cf6fd1de4919ab456d9c030e09e74f741a0cecc941363414109ccdc
MD5 d45f14c993040c42af33f1a3facb0319
BLAKE2b-256 be8dcef914768d64ab41ab4900ad2f82faeb842d3da4de50400437bca941fe24

See more details on using hashes here.

File details

Details for the file srsly-0.0.5-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.5-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 ac0dbe6e715e1fe3536397a9e65ec8f3c624c99f45b6f30e87d220071ef84721
MD5 7d669f5e76bd96059d1928f23244263b
BLAKE2b-256 060a98b8207a151730927dfb3213ef50e4c4f77f15db318bb2d105c1640e6d64

See more details on using hashes here.

File details

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

File metadata

  • Download URL: srsly-0.0.5-cp27-cp27mu-manylinux1_x86_64.whl
  • Upload date:
  • Size: 174.9 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.5-cp27-cp27mu-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 ecec49c9cdaae4594011666dd654e1e044e552f63bb3a62a1849c65a92ee302e
MD5 f926edf814ba49a477b15b66b4e74af6
BLAKE2b-256 db65066ab96cc14ccc2fe908663fab329df96bd92a168f74d6249473b4fb0a55

See more details on using hashes here.

File details

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

File metadata

  • Download URL: srsly-0.0.5-cp27-cp27m-win_amd64.whl
  • Upload date:
  • Size: 162.9 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.5-cp27-cp27m-win_amd64.whl
Algorithm Hash digest
SHA256 b9dc81339c1ab969057e790d7b2a56fd4da87336785bd671c86520e8272e3663
MD5 25b8e2a3da9d07f7857883a17ee829db
BLAKE2b-256 b4df0446be11204ec2ed8d2797bc9835f8d3096f6d6bd10f6ea52b5f3941e64b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: srsly-0.0.5-cp27-cp27m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 174.9 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.5-cp27-cp27m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 061ade35556e51b2e1da6f8552be7a6327d2d02b69edf0aacc9f5c4319d495f1
MD5 c33e8ee52b4d1a8ad0a14af0af73410e
BLAKE2b-256 41fea7d01abdd38aae1b4024f5e35a07a64b025c9f739a9811deb429d1a9171f

See more details on using hashes here.

File details

Details for the file srsly-0.0.5-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.5-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 02ea974c4b80f9ffdea4f953ffece5a8715e4e4b37d09192ab65cf4edfbf74d1
MD5 adfac2d3d70dbd07a40c0498467cd6f5
BLAKE2b-256 dd252eba6f2e09df320f38ee2108d434b2e830798e325168d5f12259c562e2b9

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