| 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 (NOTE: the conda-forge feedstock for yggdrasil-python-rapidjson is not yet available, but will be once the PR is merged):
$ 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 https://github.com/cropsinsilico/yggdrasil-python-rapidjson.gitThe package can be built and installed from source via
$ pip install .Note
The install command will clone a copy of the YggdrasilRapidJSON sources as part of the build process if an existing YggdrasilRapidJSON installation cannot be found (in the usual locations checked by cmake for your OS).
Alternatively, if you already have a (compatible) local copy of the
YggdrasilRapidJSON repository around, you can compile the module specifying
their location with the option --config-settings=cmake.define.YGGDRASIL_RAPIDJSON_REPO_DIR=, for example:
$ pip install . --config-settings=cmake.define.YGGDRASIL_RAPIDJSON_REPO_DIR=/usr/local/yggdrasil-rapidjsonThe package tests and doctests can be run via pytest
$ python -m pytest tests/ --doctest-glob="docs/*.rst" --doctest-modules docs