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!
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
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_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_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.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.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. |
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for srsly-0.0.2-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fba937146124bcf80412d957a626e4ab6000c50316629f710d9986ebf78f174e |
|
MD5 | a7c77484c162e60b793a64ee702dbe67 |
|
BLAKE2b-256 | c4894c207835ef9ecd3cc14976d910fd68c9f6f53bc215cef9912226de54a94c |
Hashes for srsly-0.0.2-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 48716787d0fa18a847dc20daa3c78636aae4aab9a115ced0477c3e857dc7e9c0 |
|
MD5 | e6c45316624909cfea69b50be4e58a86 |
|
BLAKE2b-256 | 5e5faa6475c3b527e5fdfec5698a737ff08adbb310aa9dbc5e51b989b679560a |
Hashes for srsly-0.0.2-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 | 4ccbd57da2ef98e69e4e5a354e6b58603e8ef606ebffb048f0d149b5c38ba6e0 |
|
MD5 | 8ed0f2394581389049f1f9bfe91f6522 |
|
BLAKE2b-256 | a8826b484b991d7317e668bcbaec936323e60824656c9b5ee66260e58346ba24 |
Hashes for srsly-0.0.2-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 01aeaacd44745c7c4fdd97e7fc01b84285c47fd9562181912c4352333a9ad400 |
|
MD5 | 587dac9d12dcd3a82049c89b18b4e32e |
|
BLAKE2b-256 | f7eaea545da7b474319f523e7d547b15f7186affbf10604fb4548a772278c9f3 |
Hashes for srsly-0.0.2-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0190c23c35326d8ea583315df9a69d13d16a57880d61148af417c10e61bf3c90 |
|
MD5 | b74698d3035f30482d57cb5ccb30479d |
|
BLAKE2b-256 | c6e313ed61259595bd01d73c2f61e5d5760428a8c1e0d226df31641031a6cbea |
Hashes for srsly-0.0.2-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 | b67a1906614144800225c294655df4eb125d0517799dab8281d18c32ac249601 |
|
MD5 | d595b0403ac27db883c40761d4e53d02 |
|
BLAKE2b-256 | 14c0113aa47317b1b5f77049102150fcc60bf56db72eddf89473d4d792913155 |
Hashes for srsly-0.0.2-cp35-cp35m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1e5e19dda8ab9fdb29c97db6a6c933c3534bbfc99046336ce7f5c5f803792fbe |
|
MD5 | f9859fc46828537ce31efdc3df8de340 |
|
BLAKE2b-256 | a7a8d8002a7bbf0871d85dcea71ac7708a5e83e760529041b99df3bc5503b94c |
Hashes for srsly-0.0.2-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 222cac513479fe820b5b9977f96ab7fad6dfe376d52ea365a3422d4a52be14d2 |
|
MD5 | be6d3eccda7ce9101575e82279383cc1 |
|
BLAKE2b-256 | af9c52a05f15d7f2a660f95aa79c7ad04817a3520c1881f9f6126163388eb8f5 |
Hashes for srsly-0.0.2-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 | f710312904e07a13b5e0cde599dab56720ae91812f6729b9be652f96dd580ca4 |
|
MD5 | 43a2e64555ee8ecf5c82f5bcd866110d |
|
BLAKE2b-256 | 864795750f65490cfe4d8ccfc8afbf1db9ac48b2c5cacecc7595877592a946c1 |
Hashes for srsly-0.0.2-cp27-cp27mu-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 57a0eed3ff8ec0372222a64d6a47dbfd4b300f37682579de323e29463d60d4e2 |
|
MD5 | 982adb101783571c760275b67218cb72 |
|
BLAKE2b-256 | 4898a4aa5ae50ecb40b53eef67547eb38459d458684e3cb4e35257c859e7b390 |
Hashes for srsly-0.0.2-cp27-cp27m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5ababf35b7202c82db84f88566350afe4cd2fbd0b4f47cd38b89100d9a20367e |
|
MD5 | d02b7d2c78036cb7ff2951ca784cbe85 |
|
BLAKE2b-256 | 686318b52763a08b01cc415dda4493ebe7c1a008f9640474b676869ee0ab6ab7 |
Hashes for srsly-0.0.2-cp27-cp27m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 03869a7a3b09b9a83b49a019764eddf32d68c2875f8890d0ce47ff8317f46972 |
|
MD5 | a6288bb75824599ae2bd89a96edff022 |
|
BLAKE2b-256 | bbbff1b112cd5d8198dafc774ad947c9242de677ad6729ea2bf7e784828a3286 |
Hashes for srsly-0.0.2-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 | e21a34418a82540436ce701441b7ca8146f673931a21f2522145b161c0ba457c |
|
MD5 | a2a236221a34066ab444ea02ddc366eb |
|
BLAKE2b-256 | d3bb9c8cf5d1c2ebccb061953e7a8f17b8f567d9cf30403a6d9ab1f4977075ad |