Skip to main content

Python wrapper around rapidjson

Project description

RapidJSON is an extremely fast C++ JSON serialization library.

We do not support legacy Python versions, you will need to upgrade to Python 3 to use this library.

Latest version documentation is automatically rendered by Read the Docs.

Build status Documentation status

Getting Started

First install python-rapidjson:

$ pip install python-rapidjson

RapidJSON tries to be compatible with the standard library json module so it should be a drop in replacement. 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}

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

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

native [1]

ujson [2]

simplejson [3]

stdlib [4]

yajl [5]

100 arrays dict

0.67

1.31

6.28

2.88

1.74

100 dicts array

0.79

1.19

7.16

2.92

1.69

256 Trues array

1.19

1.41

3.02

2.19

1.20

256 ascii array

1.02

0.92

1.90

1.77

2.05

256 doubles array

1.06

7.55

8.30

7.65

4.39

256 unicode array

0.87

0.72

0.82

0.88

0.53

complex object

0.82

1.41

5.17

3.39

2.87

composite object

0.68

0.93

3.01

1.92

1.85

overall

0.67

1.30

6.27

2.88

1.74

Deserialization

deserialize

native

ujson

simplejson

stdlib

yajl

100 arrays dict

0.90

0.97

1.48

1.25

1.20

100 dicts array

0.88

0.96

1.99

1.58

1.34

256 Trues array

1.22

1.31

2.08

1.93

2.08

256 ascii array

1.05

1.37

1.14

1.25

1.56

256 doubles array

0.16

0.33

0.72

0.70

0.47

256 unicode array

0.89

0.79

4.12

4.50

1.90

complex object

0.72

0.88

1.36

1.28

1.24

composite object

0.83

0.85

1.94

1.43

1.26

overall

0.90

0.97

1.49

1.25

1.20

DIY

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

$ tox -e py36 -- -m benchmark --compare-other-engines

Without the option --compare-other-engines it will focus only on RapidJSON. This is particularly handy coupled with the compare past runs functionality of pytest-benchmark:

$ tox -e py36 -- -m benchmark --benchmark-autosave
# hack, hack, hack!
$ tox -e py36 -- -m benchmark --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, use the option --benchmark-json so that the the results are written in the specified filename the run the benchmark-tables.py script giving that filename as the only argument:

$ tox -e py36 -- -m benchmark --compare-other-engines --benchmark-json=comparison.json
$ python3 benchmark-tables.py comparison.json

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 coercing.

Changes

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.1.0b1.tar.gz (161.7 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.1.0b1-cp36-cp36m-manylinux1_x86_64.whl (318.8 kB view details)

Uploaded CPython 3.6m

python_rapidjson-0.1.0b1-cp36-cp36m-manylinux1_i686.whl (309.7 kB view details)

Uploaded CPython 3.6m

python_rapidjson-0.1.0b1-cp35-cp35m-manylinux1_x86_64.whl (318.7 kB view details)

Uploaded CPython 3.5m

python_rapidjson-0.1.0b1-cp35-cp35m-manylinux1_i686.whl (309.6 kB view details)

Uploaded CPython 3.5m

python_rapidjson-0.1.0b1-cp34-cp34m-manylinux1_x86_64.whl (318.5 kB view details)

Uploaded CPython 3.4m

python_rapidjson-0.1.0b1-cp34-cp34m-manylinux1_i686.whl (309.4 kB view details)

Uploaded CPython 3.4m

File details

Details for the file python-rapidjson-0.1.0b1.tar.gz.

File metadata

File hashes

Hashes for python-rapidjson-0.1.0b1.tar.gz
Algorithm Hash digest
SHA256 3be47eba0c9bcc79355692e08f82e03fc57a0001839887ece057c490756d8200
MD5 21b8cd1159bc98f4acb5546b4f2cf152
BLAKE2b-256 46f5a2be8da7ddc4f854b4bc0cc0d5d6d4cf2e96341fb00d5990cb2134cb039e

See more details on using hashes here.

File details

Details for the file python_rapidjson-0.1.0b1-cp36-cp36m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for python_rapidjson-0.1.0b1-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 891a6fecd0e95df5a2ba196426018f3520a68cfe8082a1a528d191557f327da0
MD5 a872036d15bd28f368ae49d92837b7e7
BLAKE2b-256 5689546c600b9687bb3904821b52a551b73b3989dc1ed95d6bf9018e9b84a48a

See more details on using hashes here.

File details

Details for the file python_rapidjson-0.1.0b1-cp36-cp36m-manylinux1_i686.whl.

File metadata

File hashes

Hashes for python_rapidjson-0.1.0b1-cp36-cp36m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 f03f5de17a2caffbab34855cd2389d8c1cbf6753b847d9248d397414a04ca625
MD5 c7067627c0af647e0b56475d23d300e6
BLAKE2b-256 72f59288a19d6812cdbc94656886c7916eb1352ab80b0e07885e20caa15684ff

See more details on using hashes here.

File details

Details for the file python_rapidjson-0.1.0b1-cp35-cp35m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for python_rapidjson-0.1.0b1-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 16d4dc83c61f2f62288abfe096df07600e8a90102982d98cf922ac12a27085a9
MD5 8099b03bd26f36a00a906193094cbf27
BLAKE2b-256 49214d26d1d36b02bb8e6dd741beae2b8acf77c9e73a7d352861d7316cf55c87

See more details on using hashes here.

File details

Details for the file python_rapidjson-0.1.0b1-cp35-cp35m-manylinux1_i686.whl.

File metadata

File hashes

Hashes for python_rapidjson-0.1.0b1-cp35-cp35m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 2bd6c5fa4a4d843daa2e917ab5929e700bf0e93a9d4bc830edd85a9343a2baa6
MD5 22a0f5104e0ce5a51d8a2ff30dc4019d
BLAKE2b-256 43cbe7f784c7f226e49d952813de57488870369a6bb084bf9b5f0e26b31ea337

See more details on using hashes here.

File details

Details for the file python_rapidjson-0.1.0b1-cp34-cp34m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for python_rapidjson-0.1.0b1-cp34-cp34m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 e8458a23e88b09a39f555bf4fd320f149a0e9283595cbd093596a6ff90da85fd
MD5 764a25a63ad36fca6f47bf0c942fa784
BLAKE2b-256 55dd6b33027969840544c79abb5938af420dd096637bca9a71e17ec3c96c6491

See more details on using hashes here.

File details

Details for the file python_rapidjson-0.1.0b1-cp34-cp34m-manylinux1_i686.whl.

File metadata

File hashes

Hashes for python_rapidjson-0.1.0b1-cp34-cp34m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 8280fa6d97883c751d973ccc89f1d00f1557cfd3027a58e5325e8d95dba805a3
MD5 7a30b0d60271729f63d9060d59f7aae0
BLAKE2b-256 d8a84c7a75c1993a2b8948cee4596d3dbaf17a7f564f5cf409b26519332c60b3

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