Skip to main content

A hyper-fast Python module for reading/writing JSON data

Project description

hyperjson

Build Status

A hyper-fast, safe Python module to read and write JSON data. Works as a drop-in replacement for Python's built-in json module. This is alpha software and there will be bugs, so maybe don't deploy to production just yet. :wink:

Installation

pip install hyperjson

Usage

hyperjson is meant as a drop-in replacement for Python's json module:

>>> import hyperjson
>>> hyperjson.dumps([{"key": "value"}, 81, True])
'[{"key":"value"},81,true]'
>>> hyperjson.loads("""[{"key": "value"}, 81, true]""")
[{u'key': u'value'}, 81, True]

Motivation

Parsing JSON is a solved problem; so, no need to reinvent the wheel, right?
Well, unless you care about performance and safety.

Turns out, parsing JSON correctly is a hard problem. Thanks to Rust however, we can minimize the risk of running into stack overflows or segmentation faults however.

hyperjson is a thin wrapper around Rust's serde-json and pyo3. It is compatible with Python 3 (and 2 on a best-effort basis).

For a more in-depth discussion, watch the talk about this project recorded at the Rust Cologne Meetup in August 2018.

Goals

  • Compatibility: Support the full feature-set of Python's json module.
  • Safety: No segfaults, panics, or overflows.
  • Performance: Significantly faster than json and as fast as ujson (both written in C).

Non-goals

  • Support ujson and simplejson extensions:
    Custom extensions like encode(), __json__(), or toDict() are not supported. The reason is, that they go against PEP8 (e.g. dunder methods are restricted to the standard library, camelCase is not Pythonic) and are not available in Python's json module.
  • Whitespace preservation: Whitespace in JSON strings is not preserved. Mainly because JSON is a whitespace-agnostic format and serde-json strips them out by default. In practice this should not be a problem, since your application must not depend on whitespace padding, but it's something to be aware of.

Benchmark

We are not fast yet. That said, we haven't done any big optimizations. In the long-term we might explore features of newer CPUs like multi-core and SIMD. That's one area other (C-based) JSON extensions haven't touched yet, because it might make code harder to debug and prone to race-conditions. In Rust, this is feasible due to crates like faster or rayon.

So there's a chance that the following measurements might improve soon.
If you want to help, check the instructions in the Development Environment section below.

Test machine:
MacBook Pro 15 inch, Mid 2015 (2,2 GHz Intel Core i7, 16 GB RAM) Darwin 17.6.18

Serialization benchmarks Deserialization benchmarks

Contributions welcome!

If you would like to hack on hyperjson, here's what needs to be done:

Just pick one of the open tickets. We can provide mentorship if you like. :smiley:

Developer guide

This project uses pipenv for managing the development environment. If you don't have it installed, run

pip install poetry

The project requires the nightly version of Rust.

Install it via rustup:

rustup install nightly

If you have already installed the nightly version, make sure it is up-to-date:

rustup update nightly

After that, you can compile the current version of hyperjson and execute all tests and benchmarks with the following commands:

make install
make test
make bench

🤫 Pssst!... run make help to learn more.

Drawing pretty diagrams

In order to recreate the benchmark histograms, you first need a few additional prerequisites:

On macOS, please also add the following to your ~/.matplotlib/matplotlibrc (reference):

backend: TkAgg

After that, run the following:

make plot

License

hyperjson is licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in hyperjson by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

hyperjson-0.2.4-cp38-none-win_amd64.whl (164.2 kB view details)

Uploaded CPython 3.8 Windows x86-64

hyperjson-0.2.4-cp38-cp38-manylinux1_x86_64.whl (191.1 kB view details)

Uploaded CPython 3.8

hyperjson-0.2.4-cp38-cp38-macosx_10_7_x86_64.whl (167.6 kB view details)

Uploaded CPython 3.8 macOS 10.7+ x86-64

hyperjson-0.2.4-cp37-none-win_amd64.whl (164.2 kB view details)

Uploaded CPython 3.7 Windows x86-64

hyperjson-0.2.4-cp37-cp37m-manylinux1_x86_64.whl (191.1 kB view details)

Uploaded CPython 3.7m

hyperjson-0.2.4-cp37-cp37m-macosx_10_7_x86_64.whl (167.6 kB view details)

Uploaded CPython 3.7m macOS 10.7+ x86-64

hyperjson-0.2.4-cp36-none-win_amd64.whl (164.4 kB view details)

Uploaded CPython 3.6 Windows x86-64

hyperjson-0.2.4-cp36-cp36m-manylinux1_x86_64.whl (191.2 kB view details)

Uploaded CPython 3.6m

hyperjson-0.2.4-cp36-cp36m-macosx_10_7_x86_64.whl (167.8 kB view details)

Uploaded CPython 3.6m macOS 10.7+ x86-64

hyperjson-0.2.4-cp35-none-win_amd64.whl (164.4 kB view details)

Uploaded CPython 3.5 Windows x86-64

hyperjson-0.2.4-cp35-cp35m-manylinux1_x86_64.whl (191.2 kB view details)

Uploaded CPython 3.5m

hyperjson-0.2.4-cp35-cp35m-macosx_10_7_x86_64.whl (167.8 kB view details)

Uploaded CPython 3.5m macOS 10.7+ x86-64

File details

Details for the file hyperjson-0.2.4-cp38-none-win_amd64.whl.

File metadata

File hashes

Hashes for hyperjson-0.2.4-cp38-none-win_amd64.whl
Algorithm Hash digest
SHA256 cf70d244f0bce0db4a6d0cb2958dcf14283045f17098831f5e8ef34b3d4a67a8
MD5 5a2508d0977d0de6a0b321f43e71fb6e
BLAKE2b-256 d1ee32eff3ee2754b1713409478052b01bfac7020cff45fa56417fa6451c0d56

See more details on using hashes here.

File details

Details for the file hyperjson-0.2.4-cp38-cp38-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for hyperjson-0.2.4-cp38-cp38-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 4451c5b85471a14d5d8ee1764e2622301979bf41da9be95472fb279f0c5db4b6
MD5 1d9f3061a97cdd3b53e6612474adcac9
BLAKE2b-256 14dc746513b710a32f7e3529ad26d4d0133107f3bed9096c0a3d96920775868a

See more details on using hashes here.

File details

Details for the file hyperjson-0.2.4-cp38-cp38-macosx_10_7_x86_64.whl.

File metadata

File hashes

Hashes for hyperjson-0.2.4-cp38-cp38-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 59ebe0e4b8f1a97c078cc5a7d214c59eda24acc1e530ae9f26a4148e26cca9e6
MD5 5a368556e9a571fb371c1f64f72aeeb2
BLAKE2b-256 fb82718296dd66b194984e5e182d5646e096d0c4cc41ec13db2f7053ca7f8715

See more details on using hashes here.

File details

Details for the file hyperjson-0.2.4-cp37-none-win_amd64.whl.

File metadata

File hashes

Hashes for hyperjson-0.2.4-cp37-none-win_amd64.whl
Algorithm Hash digest
SHA256 e4ab23d72c3646a3053db049a14b1fdf79521e04d2db98b18dc0dc858de242e2
MD5 19d100cc24fae66b3e54678a13b06077
BLAKE2b-256 a64f1392ef06faec75b80726816d9ca52d5ef0163f4f495f32201ba489ce38aa

See more details on using hashes here.

File details

Details for the file hyperjson-0.2.4-cp37-cp37m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for hyperjson-0.2.4-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 a9b6f33593729c1ba5990c46f8d34e61d63670d15622c228663fe3528e4149ad
MD5 41af9935603f052c3d1301a5e98b3590
BLAKE2b-256 ad51008a732d3e92d44e9b358ab668df6a95303088f9374ae72a73f158f842ad

See more details on using hashes here.

File details

Details for the file hyperjson-0.2.4-cp37-cp37m-macosx_10_7_x86_64.whl.

File metadata

File hashes

Hashes for hyperjson-0.2.4-cp37-cp37m-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 31b7287c8973ec92a14ced88f29b075568d884ec63a03a3bd18046ff445e085f
MD5 6dec929d46eee09c6ea6d1961ffc9ecb
BLAKE2b-256 e3ce23dc13114354b496ed6680599a169790af2717281d9c2bb9204683944bb3

See more details on using hashes here.

File details

Details for the file hyperjson-0.2.4-cp36-none-win_amd64.whl.

File metadata

File hashes

Hashes for hyperjson-0.2.4-cp36-none-win_amd64.whl
Algorithm Hash digest
SHA256 fc70be6d7e0f4cef9e79e965400b8e6167caaa14305016e1226e92b3a6ec52ec
MD5 722e3609b88246959abb7bc95a6d387a
BLAKE2b-256 c709b9dc6e67228236100df442e92ea38e2d28f7fe76c553aa9b492381540231

See more details on using hashes here.

File details

Details for the file hyperjson-0.2.4-cp36-cp36m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for hyperjson-0.2.4-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 3342dd9296035d8f0670f09e246ab36fea1017c4dae73c24a418960ed1eb8beb
MD5 efd889486a6b2ff28a2ac532eacc97ed
BLAKE2b-256 4625cc2b3f1dfd4c7b2e559e671472775a126a8a5044d49dc942bfde5c6e34eb

See more details on using hashes here.

File details

Details for the file hyperjson-0.2.4-cp36-cp36m-macosx_10_7_x86_64.whl.

File metadata

File hashes

Hashes for hyperjson-0.2.4-cp36-cp36m-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 005dee52ee0646ecc2173199223e73a5a7a85cbfb9b888b0f4bc9e07906dd0ca
MD5 115b1e8ba4e574f6be187b5a44ba623b
BLAKE2b-256 823ac4b490b9e68fb899fca4e4071cfab5f7486b4056e298f630db7ec25905de

See more details on using hashes here.

File details

Details for the file hyperjson-0.2.4-cp35-none-win_amd64.whl.

File metadata

File hashes

Hashes for hyperjson-0.2.4-cp35-none-win_amd64.whl
Algorithm Hash digest
SHA256 6dff1448fd69378703f50cfdacc8e5de36a9b0da3d8c4016add80dc9b6f8cc3b
MD5 af224b09c00ad836e5459260a91fbcfa
BLAKE2b-256 e737e3cf269bd0fe3a19978f826cb68e131bf6918592a044019a0a264c08caa2

See more details on using hashes here.

File details

Details for the file hyperjson-0.2.4-cp35-cp35m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for hyperjson-0.2.4-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 95a411e6460307fd51f51e387522ff1e0387a9dae7d1a4b5cdaa07fce7cd5e6f
MD5 4a26cc628c690959b34876dbb78a5ecc
BLAKE2b-256 91ceca2f48d4c31d31386719f30ea536d3a4308453e8dcb49079e87423b4a6a0

See more details on using hashes here.

File details

Details for the file hyperjson-0.2.4-cp35-cp35m-macosx_10_7_x86_64.whl.

File metadata

File hashes

Hashes for hyperjson-0.2.4-cp35-cp35m-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 c222f8f613ad729336e1f01108f242cbd1cf8ef361a3cd2b69a21a470b5adff1
MD5 0907741c6e01a89f00a97628699b80a3
BLAKE2b-256 a4346d19f99d9871fcc5fd01b97a7ddb33cbf7a20b98929d3d23f64286e6b8e1

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page