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 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}

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 turn True into '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.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.3.0.tar.gz (173.1 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.3.0-cp36-cp36m-win_amd64.whl (91.8 kB view details)

Uploaded CPython 3.6mWindows x86-64

python_rapidjson-0.3.0-cp36-cp36m-win32.whl (82.3 kB view details)

Uploaded CPython 3.6mWindows x86

python_rapidjson-0.3.0-cp35-cp35m-win_amd64.whl (91.8 kB view details)

Uploaded CPython 3.5mWindows x86-64

python_rapidjson-0.3.0-cp35-cp35m-win32.whl (82.3 kB view details)

Uploaded CPython 3.5mWindows x86

python_rapidjson-0.3.0-cp35-cp35m-manylinux1_x86_64.whl (722.0 kB view details)

Uploaded CPython 3.5m

python_rapidjson-0.3.0-cp35-cp35m-manylinux1_i686.whl (686.8 kB view details)

Uploaded CPython 3.5m

python_rapidjson-0.3.0-cp34-cp34m-win_amd64.whl (86.6 kB view details)

Uploaded CPython 3.4mWindows x86-64

python_rapidjson-0.3.0-cp34-cp34m-win32.whl (80.4 kB view details)

Uploaded CPython 3.4mWindows x86

python_rapidjson-0.3.0-cp34-cp34m-manylinux1_x86_64.whl (722.2 kB view details)

Uploaded CPython 3.4m

python_rapidjson-0.3.0-cp34-cp34m-manylinux1_i686.whl (687.7 kB view details)

Uploaded CPython 3.4m

File details

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

File metadata

File hashes

Hashes for python-rapidjson-0.3.0.tar.gz
Algorithm Hash digest
SHA256 14a607599f260cfccbb73e90d2e349cb64ad7a77a1b3d47c56bc8a9f96c9ba46
MD5 56017895847e3757068f2c9d62e8a82e
BLAKE2b-256 23d26439fa9260f75aec08d8542f72dc7bf6696821d89d065a267f7c0b7c3b8e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_rapidjson-0.3.0-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 ede7c571e0beb94a7e7b054c4c44d407fd2a27cde4d0d4a0c2cb9f2f60da74f9
MD5 56478e3388dfacfc2c03839a1948c77b
BLAKE2b-256 3a42ecbb56e444097e2d1749aa19f637a6e5bce112efc861c62bc597267c462b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_rapidjson-0.3.0-cp36-cp36m-win32.whl
Algorithm Hash digest
SHA256 87c00f5a293bae130039790bee3b42ba8ad2a27d04ccd746ce83b2221af7d411
MD5 0bf5213c34ca01c74a980dc1411ba158
BLAKE2b-256 81c349899dad8fc25539164d28cc695cee7c8badfeaba4cda784f961600c2eea

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_rapidjson-0.3.0-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 9bc850094a85222b143895387fa551a32be1a5d97b13f6d017ef33a85f846f3a
MD5 0fef4fc25ad17358e5d9fcf91fce5d8b
BLAKE2b-256 a9fd547b68c611330779fb5e474d0a300fe7ee3428917e401db1d0360f893513

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_rapidjson-0.3.0-cp35-cp35m-win32.whl
Algorithm Hash digest
SHA256 d9bcf5e55519d95a23a519e6a0b7a493920a500b5ecbb74f27bc9c9760e5ab6c
MD5 698b39f87aad0a5327f6abb0cb0e54e6
BLAKE2b-256 839f3274dcc5f0d48ef2443204d91b140d97a0af24dda335e1a6d9563bdd0e0f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_rapidjson-0.3.0-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 88bac6b33f2e81921cce4842099ca6080429f448b5713eea88454c069fdcc10a
MD5 abe253c7c17d707386d772769dcee782
BLAKE2b-256 8f8ef616ab4ce36779108f27d9c9f81653647f3cf082069a6b59a4e029ee99cc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_rapidjson-0.3.0-cp35-cp35m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 007894f0d8011de239950ec5bb8117ddf9aea10db5b2174ddd1db02a6e1e4304
MD5 b07bb51996c513ec8cbf824451defde8
BLAKE2b-256 458027e31f04b9d24ac2194ad81f5f335539b2b42d420e6807e970364cae7f16

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_rapidjson-0.3.0-cp34-cp34m-win_amd64.whl
Algorithm Hash digest
SHA256 618be0a30f2d5ae62db4dc60e840340a7d697303de071a0e498f2e4037301172
MD5 4be65915b9a152fd4b61d66e95f4d375
BLAKE2b-256 2bdabcf37c96ae8dc8ee65bf20af371c6d1a3f73409fb89a333c67a3faf99014

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_rapidjson-0.3.0-cp34-cp34m-win32.whl
Algorithm Hash digest
SHA256 aebb654aca098500e765ec376f803ff99458c372ecf6cd17787de66664d4540a
MD5 750fd8c3cdd3209b6b02b3e8c9d85032
BLAKE2b-256 b8f896955cf799b98ab738ede622abd2a02dae1a0351ad84bbb867a114376df1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_rapidjson-0.3.0-cp34-cp34m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 2b9147c64d2577aab42b2919eb2fe735998fdea72e96939ea816dcfc2c6765c8
MD5 0ba8bbc4310b21a7d7c15338b1ee7548
BLAKE2b-256 16ad54c5cc5ca6a18f18a79303a2d4614b46c47afe2aaadf6bcc7e417374c89a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_rapidjson-0.3.0-cp34-cp34m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 c7a7e503fdae1ce18a7178cc76bf81c8043c7987234bd250f6ef1ff0abfdbe64
MD5 60d4d42ee294551b2dff9a76d182c2ae
BLAKE2b-256 f8983fbee76856ab82addc14e2dc55b5f36d38a3fbf2cff97a68f2139ccfc3ac

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