Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Python wrapper around rapidjson

License

NotificationsYou must be signed in to change notification settings

python-rapidjson/python-rapidjson

Repository files navigation

Python wrapper around RapidJSON

Authors:Ken Robbins <ken@kenrobbins.com>
Lele Gaifax <lele@metapensiero.it>
License:MIT License
Status:Build statusDocumentation 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.

Getting Started

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}

Development

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.

Performance

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.

Incompatibility

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

Stars

Watchers

Forks

Packages

No packages published

Contributors24

Languages


[8]ページ先頭

©2009-2025 Movatter.jp