| Authors: | Meagan Lang <langmm.astro@gmail.com>
Ken Robbins [RapidJSON] <ken@kenrobbins.com> Lele Gaifax [RapidJSON] <lele@metapensiero.it> |
|---|---|
| License: | MIT License |
YggdrasilRapidJSON is an extension to RapidJSON, an extremely fast C++ JSON parser and serialization library. This package wraps it into a Python C-extension, duplicating the functions/classes provided by python-rapidjson and exposing the features added by YggdrasilRapidJSON including serialization/deserialization of additional datatypes, unitful scalars/arrays, and schema normalization/comparison.
First install yggdrasil-python-rapidjson:
$ pip install yggdrasil-python-rapidjsonor, if you prefer Conda:
$ conda install -c conda-forge yggdrasil-python-rapidjsonBasic usage looks the same as python-rapidjson, with the exception of the package name (example adapted from python-rapidjson README.rst):
>>> import yggdrasil_rapidjson
>>> data = {'foo': 100, 'bar': 'baz'}
>>> yggdrasil_rapidjson.dumps(data)
'{"foo":100,"bar":"baz"}'
>>> yggdrasil_rapidjson.loads('{"bar":"baz","foo":100}')
{'bar': 'baz', 'foo': 100}
>>>
>>> class Stream:
... def write(self, data):
... print("Chunk:", data)
...
>>> yggdrasil_rapidjson.dump(data, Stream(), chunk_size=5)
Chunk: b'{"foo'
Chunk: b'":100'
Chunk: b',"bar'
Chunk: b'":"ba'
Chunk: b'z"}'If you want to install the development version (maybe to contribute fixes or enhancements) you may clone the repository:
$ git clone --recursive https://github.com/cropsinsilico/yggdrasil-python-rapidjson.gitNote
The --recursive option is needed because we use a submodule to
include YggdrasilRapidJSON sources. Alternatively you can do a plain
clone immediately followed by a git submodule update --init.
Alternatively, if you already have (a compatible version of)
YggdrasilRapidJSON includes around, you can compile the module specifying
their location with the option --config-settings=cmake.define.RAPIDJSON_INCLUDE_DIRS=, for example:
$ pip install . --config-settings=cmake.define.RAPIDJSON_INCLUDE_DIRS=/usr/include/rapidjsonThe package can be built and installed from source via
$ pip install .The package tests and doctests can be run via pytest
$ python -m pytest tests/ --doctest-glob="docs/*.rst" --doctest-modules docs