Skip to main content

Python wrapper around rapidjson

Project description

RapidJSON is an extremely fast C++ JSON parser and serialization library: this module wraps it into a Python 3 extension, exposing its serialization/deserialization (to/from either bytes, str or file-like instances) and JSON Schema validation capabilities.

Latest version documentation is automatically rendered by Read the Docs.

Build status Documentation status

Getting Started

First install python-rapidjson:

$ pip install python-rapidjson

or, if you prefer Conda:

$ conda install -c conda-forge python-rapidjson

Basic usage looks like this:

>>> import rapidjson
>>> data = {'foo': 100, 'bar': 'baz'}
>>> rapidjson.dumps(data)
'{"bar":"baz","foo":100}'
>>> rapidjson.loads('{"bar":"baz","foo":100}')
{'bar': 'baz', 'foo': 100}
>>>
>>> class Stream:
...   def write(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"}'

Development

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/python-rapidjson/python-rapidjson.git

A set of makefiles implement most common operations, such as build, check and release; see make help output for a list of available targets.

Performance

python-rapidjson tries to be as performant as possible while staying compatible with the json module.

The following tables show a comparison between this module and other libraries with different data sets. Last row (“overall”) is the total time taken by all the benchmarks.

Each number show the factor between the time taken by each contender and python-rapidjson (in other words, they are normalized against a value of 1.0 for python-rapidjson): the lower the number, the speedier the contender.

In bold the winner.

Serialization

serialize

dumps()[1]

Encoder()[2]

dumps(n)[3]

Encoder(n)[4]

ujson[5]

simplejson[6]

stdlib[7]

yajl[8]

100 arrays dict

1.00

0.99

0.63

0.63

0.88

3.97

2.24

1.39

100 dicts array

1.00

1.04

0.73

0.70

0.87

5.79

2.31

1.36

256 Trues array

1.00

1.08

1.23

1.09

1.35

3.55

2.31

1.32

256 ascii array

1.00

1.01

1.04

1.03

0.51

1.17

1.04

1.12

256 doubles array

1.00

1.02

1.06

1.02

7.45

8.18

7.69

4.34

256 unicode array

1.00

0.88

0.88

0.88

0.55

0.74

0.67

0.51

complex object

1.00

1.02

0.81

0.79

1.13

3.98

2.84

2.21

composite object

1.00

1.00

0.69

0.65

0.98

3.12

1.99

2.00

overall

1.00

0.99

0.63

0.63

0.88

3.97

2.24

1.39

Deserialization

deserialize

loads()[9]

Decoder()[10]

loads(n)[11]

Decoder(n)[12]

ujson

simplejson

stdlib

yajl

100 arrays dict

1.00

1.00

0.90

0.90

0.96

1.40

1.12

1.15

100 dicts array

1.00

1.04

0.87

0.88

0.94

1.95

1.61

1.25

256 Trues array

1.00

1.24

1.17

1.25

1.16

2.09

1.87

1.86

256 ascii array

1.00

1.03

1.04

1.05

1.41

1.31

1.24

1.49

256 doubles array

1.00

1.01

0.19

0.19

0.44

0.91

0.85

0.56

256 unicode array

1.00

1.01

1.01

1.01

1.27

5.46

6.17

3.04

complex object

1.00

1.02

0.78

0.79

0.99

1.60

1.19

1.22

composite object

1.00

1.01

0.80

0.81

0.76

2.06

1.38

1.29

overall

1.00

1.00

0.90

0.90

0.96

1.41

1.13

1.15

DIY

To run these tests yourself, clone the repo and run:

$ make benchmarks

or

$ make benchmarks-other

The former will focus only on RapidJSON and is particularly handy coupled with the compare past runs functionality of pytest-benchmark:

$ make benchmarks PYTEST_OPTIONS=--benchmark-autosave
# hack, hack, hack!
$ make benchmarks PYTEST_OPTIONS=--benchmark-compare=0001

----------------------- benchmark 'deserialize': 18 tests ------------------------
Name (time in us)                                                            Min…
----------------------------------------------------------------------------------
test_loads[rapidjson-256 Trues array] (NOW)                         5.2320 (1.0)
test_loads[rapidjson-256 Trues array] (0001)                        5.4180 (1.04)

To reproduce the tables above run make benchmarks-tables

Incompatibility

Here are things in the standard json library supports that we have decided not to support:

separators argument

This is mostly used for pretty printing and not supported by RapidJSON so it isn’t a high priority. We do support indent kwarg that would get you nice looking JSON anyways.

Coercing keys when dumping

json will stringify a True dictionary key as "true" if you dump it out but when you load it back in it’ll still be a string. We want the dump and load to return the exact same objects so we have decided not to do this coercion.

Changes

0.4.0 (2018-01-05)

  • Implemented the streaming interface, see load() and dump() (issue #80)

    Backward incompatibility: now the flags arguments on all the functions are keyword only, to mimic stdlib’s json style

0.3.2 (2017-12-21)

0.3.1 (2017-12-20)

  • Fix Travis CI recipe to accomodate MacOS

0.3.0 (2017-12-20)

  • Fix compilation on MacOS (issue #78)

  • Handle generic iterables (PR #89)

    Backward incompatibility: the dumps() function and the Encoder() constructor used to accept a max_recursion_depth argument, to control the maximum allowed nesting of Python structures; since the underlying function is now effectively recursive, it has been replaced by the generic sys.setrecursionlimit() mechanism

0.2.7 (2017-12-08)

  • Restore compatibility with Python < 3.6

0.2.6 (2017-12-08)

  • Fix memory leaks when using object_hook/start_object/end_object

0.2.5 (2017-09-30)

  • Fix bug where error handling code could raise an exception causing a confusing exception to be returned (PR #82)

  • Fix bug where loads’s object_hook and dumps’s default arguments could not be passed None explicitly (PR #83)

  • Fix crash when dealing with surrogate pairs (issue #81)

0.2.4 (2017-09-17)

  • Fix compatibility with MacOS/clang

0.2.3 (2017-08-24)

  • Limit the precision of DM_UNIX_TIME timestamps to six decimal digits

0.2.2 (2017-08-24)

  • Nothing new, attempt to fix production of Python 3.6 binary wheels

0.2.1 (2017-08-24)

  • Nothing new, attempt to fix production of Python 3.6 binary wheels

0.2.0 (2017-08-24)

  • New parse_mode option, implementing relaxed JSON syntax (issue #73)

  • New Encoder and Decoder, implementing a class-based interface

  • New Validator, exposing the underlying JSON schema validation (issue #71)

0.1.0 (2017-08-16)

  • Remove beta status

0.1.0b4 (2017-08-14)

  • Make execution of the test suite on Appveyor actually happen

0.1.0b3 (2017-08-12)

  • Exclude CI configurations from the source distribution

0.1.0b2 (2017-08-12)

  • Fix Powershell wheel upload script in appveyor configuration

0.1.0b1 (2017-08-12)

  • Compilable with somewhat old g++ (issue #69)

  • Backward incompatibilities:

    • all DATETIME_MODE_XXX constants have been shortened to DM_XXX DATETIME_MODE_ISO8601_UTC has been renamed to DM_SHIFT_TO_UTC

    • all UUID_MODE_XXX constants have been shortened to UM_XXX

  • New option DM_UNIX_TIME to serialize date, datetime and time values as UNIX timestamps targeting issue #61

  • New option DM_NAIVE_IS_UTC to treat naïve datetime and time values as if they were in the UTC timezone (also for issue #61)

  • New keyword argument number_mode to use underlying C library numbers

  • Binary wheels for GNU/Linux and Windows on PyPI (one would hope: this is the reason for the beta1 release)

0.0.11 (2017-03-05)

  • Fix a couple of refcount handling glitches, hopefully targeting issue #48.

0.0.10 (2017-03-02)

  • Fix source distribution to contain all required stuff (PR #64)

0.0.9 (2017-03-02)

0.0.8 (2016-12-09)

Project details


Download files

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

Source Distribution

python-rapidjson-0.4.0.tar.gz (178.9 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

python_rapidjson-0.4.0-cp36-cp36m-win_amd64.whl (119.0 kB view details)

Uploaded CPython 3.6mWindows x86-64

python_rapidjson-0.4.0-cp36-cp36m-win32.whl (104.0 kB view details)

Uploaded CPython 3.6mWindows x86

python_rapidjson-0.4.0-cp36-cp36m-manylinux1_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.6m

python_rapidjson-0.4.0-cp36-cp36m-manylinux1_i686.whl (1.0 MB view details)

Uploaded CPython 3.6m

python_rapidjson-0.4.0-cp36-cp36m-macosx_10_6_intel.whl (352.7 kB view details)

Uploaded CPython 3.6mmacOS 10.6+ Intel (x86-64, i386)

python_rapidjson-0.4.0-cp35-cp35m-win_amd64.whl (119.0 kB view details)

Uploaded CPython 3.5mWindows x86-64

python_rapidjson-0.4.0-cp35-cp35m-win32.whl (104.0 kB view details)

Uploaded CPython 3.5mWindows x86

python_rapidjson-0.4.0-cp35-cp35m-manylinux1_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.5m

python_rapidjson-0.4.0-cp35-cp35m-manylinux1_i686.whl (1.0 MB view details)

Uploaded CPython 3.5m

python_rapidjson-0.4.0-cp35-cp35m-macosx_10_6_intel.whl (352.7 kB view details)

Uploaded CPython 3.5mmacOS 10.6+ Intel (x86-64, i386)

python_rapidjson-0.4.0-cp34-cp34m-win_amd64.whl (112.9 kB view details)

Uploaded CPython 3.4mWindows x86-64

python_rapidjson-0.4.0-cp34-cp34m-win32.whl (102.6 kB view details)

Uploaded CPython 3.4mWindows x86

python_rapidjson-0.4.0-cp34-cp34m-manylinux1_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.4m

python_rapidjson-0.4.0-cp34-cp34m-manylinux1_i686.whl (1.0 MB view details)

Uploaded CPython 3.4m

python_rapidjson-0.4.0-cp34-cp34m-macosx_10_6_intel.whl (351.7 kB view details)

Uploaded CPython 3.4mmacOS 10.6+ Intel (x86-64, i386)

File details

Details for the file python-rapidjson-0.4.0.tar.gz.

File metadata

File hashes

Hashes for python-rapidjson-0.4.0.tar.gz
Algorithm Hash digest
SHA256 8c65f955f064e93d064fe3e401c79855eac592702db608c37d53bad90604187e
MD5 2636822bb11fe15983383a799843e01d
BLAKE2b-256 5e05e5489d301421469e2b5892656e6efeb0084036c7ec417dc230142c5c5f29

See more details on using hashes here.

File details

Details for the file python_rapidjson-0.4.0-cp36-cp36m-win_amd64.whl.

File metadata

File hashes

Hashes for python_rapidjson-0.4.0-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 89b82dfc29fed941970a81be7f9dd6ecfcfa22ed2475b3603ad80d7350ffd926
MD5 e826adc5444c9bfe874f73840032d791
BLAKE2b-256 788816afe12dd454c9801cd9854c44ee2701c1527d13a97ca743b9853bb10863

See more details on using hashes here.

File details

Details for the file python_rapidjson-0.4.0-cp36-cp36m-win32.whl.

File metadata

File hashes

Hashes for python_rapidjson-0.4.0-cp36-cp36m-win32.whl
Algorithm Hash digest
SHA256 084ab245175cf25898d99cd6b50948b02b6c6bd5c9b175ceb782fb7fad07f916
MD5 bbb11b3faa4cec5a9ca8e4dc8cb42bf9
BLAKE2b-256 7e16711fc3316ef5c3405144f71e8992590954cd393561cf339a5394425014ec

See more details on using hashes here.

File details

Details for the file python_rapidjson-0.4.0-cp36-cp36m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for python_rapidjson-0.4.0-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 311fa5264c33969864e1beb8ab44042226fbfc4701cfd6f083b35a6ce2dcd850
MD5 fa2ab524c2cbeb5dadf46d9b11a2102e
BLAKE2b-256 68f2c6928fa88e843a00385bda47b90195cddf6e406daec6256014b8a0b02e78

See more details on using hashes here.

File details

Details for the file python_rapidjson-0.4.0-cp36-cp36m-manylinux1_i686.whl.

File metadata

File hashes

Hashes for python_rapidjson-0.4.0-cp36-cp36m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 b12470787a035eb4e0bc7e5d613fd462051d0fe7cb92900460f254ab68a64e71
MD5 71623113c221a7cd1a6a76e8d0638590
BLAKE2b-256 8c9d862ecc0966bc9304f19c594c0f79e6b3ce1594cf7eb3e027e4abf0c95d3f

See more details on using hashes here.

File details

Details for the file python_rapidjson-0.4.0-cp36-cp36m-macosx_10_6_intel.whl.

File metadata

File hashes

Hashes for python_rapidjson-0.4.0-cp36-cp36m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 1e323dd20f4c4415eb583fc66718ffbf645da82dceb5038c5ec03430fc7991f1
MD5 8c8bccb35f86ab8e3566a18d7730b636
BLAKE2b-256 8cbbfc711e4b771e83b5281dc5fe17dd006161cdf63223f6fa343d0b0b98aa4c

See more details on using hashes here.

File details

Details for the file python_rapidjson-0.4.0-cp35-cp35m-win_amd64.whl.

File metadata

File hashes

Hashes for python_rapidjson-0.4.0-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 e0abff6e3c7d2b77664a0d594943896d8c53c004b69c48cdd0d173d751655547
MD5 e8a0c15001e8110944975404c71a999b
BLAKE2b-256 0ff661d9605155a01d6459de69e7f173a6297638a5faf3d594bf63e2e00b41f5

See more details on using hashes here.

File details

Details for the file python_rapidjson-0.4.0-cp35-cp35m-win32.whl.

File metadata

File hashes

Hashes for python_rapidjson-0.4.0-cp35-cp35m-win32.whl
Algorithm Hash digest
SHA256 b4e5424a9128fbc8e39da27f3c570186b9f000857446bc83924e5e4fd890304d
MD5 6ad3cbf88fca1c0703b8e5223039d1a5
BLAKE2b-256 4017e72b7d3694a9ed2edbb0d77de7200711ff4abbf9b648029ac379a1882667

See more details on using hashes here.

File details

Details for the file python_rapidjson-0.4.0-cp35-cp35m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for python_rapidjson-0.4.0-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 81451eb4965e48a9faaf97a220f63e27755ecb5f7ff37efa2dbe6bb838da5580
MD5 dc9fb5b64ea0d204bd71ad8dd586f017
BLAKE2b-256 2f4fda843f73c6573e559bd96b3be7ce97d10dd680fdd73174250a973336e19d

See more details on using hashes here.

File details

Details for the file python_rapidjson-0.4.0-cp35-cp35m-manylinux1_i686.whl.

File metadata

File hashes

Hashes for python_rapidjson-0.4.0-cp35-cp35m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 0997f219b417a45ebd13cdc0044eed073b9ab6fc16113c2c044bb795f2cf76f0
MD5 55087de03a1a85c9a06bcda3a02316ab
BLAKE2b-256 d9627b8f5a7e6de323e50636a273281407b375d3a3fe3f39d120be77d519ace5

See more details on using hashes here.

File details

Details for the file python_rapidjson-0.4.0-cp35-cp35m-macosx_10_6_intel.whl.

File metadata

File hashes

Hashes for python_rapidjson-0.4.0-cp35-cp35m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 a6f08ecd3a5d11d8d257bc7189af72e14bdb8377aef81f48094c47be19eddf59
MD5 aa289ae5e6da7144939b0b5e7583fbfc
BLAKE2b-256 40e797249ffc87267e35a2bf9dac376425e033c1ba2b45d8604e82d8e0b76d2e

See more details on using hashes here.

File details

Details for the file python_rapidjson-0.4.0-cp34-cp34m-win_amd64.whl.

File metadata

File hashes

Hashes for python_rapidjson-0.4.0-cp34-cp34m-win_amd64.whl
Algorithm Hash digest
SHA256 4768f2e4412e135498ef8e43774f47a45fe0884768cd1939bbb6b8902ce9c291
MD5 d03782625c65d47e718de7ab57ecf3cb
BLAKE2b-256 c0d0a868ccb53726bf3e45cb9fe60e19e8527921cd4db67f0c01283f30f28b39

See more details on using hashes here.

File details

Details for the file python_rapidjson-0.4.0-cp34-cp34m-win32.whl.

File metadata

File hashes

Hashes for python_rapidjson-0.4.0-cp34-cp34m-win32.whl
Algorithm Hash digest
SHA256 e583e554a1f726c026d0510f9a412f1a417f29788e38489d9b1fa8eaf7709f06
MD5 727821d40302b58a5cdadbf6e292cafc
BLAKE2b-256 ec524013f0750863f7c084526da9433e60e552316bd78112874195f380ba1f27

See more details on using hashes here.

File details

Details for the file python_rapidjson-0.4.0-cp34-cp34m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for python_rapidjson-0.4.0-cp34-cp34m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 26287783473a7d10c6e87dbe9c5fa74c977216fe8d1606b2588969718109c81a
MD5 e9bb1d7061358152c76a1b426d5bd918
BLAKE2b-256 9e3c79d0ea59df673ed0594937703efe11cefdd09e04a6a1175f69594d64c5d9

See more details on using hashes here.

File details

Details for the file python_rapidjson-0.4.0-cp34-cp34m-manylinux1_i686.whl.

File metadata

File hashes

Hashes for python_rapidjson-0.4.0-cp34-cp34m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 e4b9e4b9a3e1f1f8a6ed6aba7943ceb15621b9b88fcd71810e36f2aa4c3e6f76
MD5 cf78d2f923906ec83bcfcd5e555e4b97
BLAKE2b-256 2d152c73ac7ab2b633857542e260550a1c4169d82eb284c7193a70121795cfdb

See more details on using hashes here.

File details

Details for the file python_rapidjson-0.4.0-cp34-cp34m-macosx_10_6_intel.whl.

File metadata

File hashes

Hashes for python_rapidjson-0.4.0-cp34-cp34m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 29692421e11809c0b425242cc7b50475443de84fd7132c0825c4614dad8d9761
MD5 2989449fcd306c0a4598b37e80e353dd
BLAKE2b-256 382e836a2b40e70593cb4440154f7acf2b719fe32a661804e5160c8d72ee3786

See more details on using hashes here.

Supported by

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