- Notifications
You must be signed in to change notification settings - Fork53
Python wrapper around rapidjson
License
python-rapidjson/python-rapidjson
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
| Authors: | Ken Robbins <ken@kenrobbins.com> Lele Gaifax <lele@metapensiero.it> |
|---|---|
| License: | MIT License |
| Status: |
RapidJSON is an extremely fast C++ JSON parser and serialization library: this modulewraps it into a Python 3 extension, exposing its serialization/deserialization (to/fromeitherbytes,str orfile-like instances) andJSON Schema validationcapabilities.
Latest version documentation is automatically rendered byRead the Docs.
First installpython-rapidjson:
$ pip install python-rapidjson
or, if you preferConda:
$ conda install -c conda-forge python-rapidjson
Basic usage looks like this:
>>>importrapidjson>>>data= {'foo':100,'bar':'baz'}>>>rapidjson.dumps(data)'{"foo":100,"bar":"baz"}'>>>rapidjson.loads('{"bar":"baz","foo":100}'){'bar':'baz','foo':100}>>>>>>classStream:...defwrite(self,data):...print("Chunk:",data)...>>>rapidjson.dump(data,Stream(),chunk_size=5)Chunk:b'{"foo'Chunk:b'":100'Chunk:b',"bar'Chunk:b'":"ba'Chunk:b'z"}'
Most functionalities are exposed both asfunctions and asclasses.
The following uses arelaxed syntaxDecoder instance, that handlesJSONC andtrailing commas:
>>>fromrapidjsonimportDecoder>>>fromrapidjsonimportPM_COMMENTS,PM_TRAILING_COMMAS>>>decoder=Decoder(parse_mode=PM_COMMENTS|PM_TRAILING_COMMAS)>>>decoder('''... {... "bar": /* Block comment */ "baz",... "foo":100, // Trailing comma and comment... }... '''){'bar':'baz','foo':100}
If you want to install the development version (maybe to contribute fixes orenhancements) you may clone the repository:
$ git clone --recursive https://github.com/python-rapidjson/python-rapidjson.git
Note
The--recursive option is needed because we use asubmodule toincludeRapidJSON sources. Alternatively you can do a plainclone immediately followed by agit submodule update --init.
Alternatively, if you already have (acompatible version of)RapidJSON includes around, you can compile the module specifyingtheir location with the option--rj-include-dir, for example:
$ python3 setup.py build --rj-include-dir=/usr/include/rapidjson
A set of makefiles implement most common operations, such asbuild,checkandrelease; seemake help output for a list of available targets.
python-rapidjson tries to be as performant as possible while stayingcompatible with thejson module.
Seethis section in the documentation for a comparison with other JSON libraries.
Although we tried to implement an API similar to the standard libraryjson, being astrictdrop-in replacement in not our goal and we have decided to depart from there insome aspects. Seethis section in the documentation for further details.
About
Python wrapper around rapidjson
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.