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

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

0.77

0.97

4.82

2.27

1.37

100 dicts array

1.00

1.02

0.82

0.85

0.90

5.68

2.19

1.36

256 Trues array

1.00

1.04

1.24

1.09

1.31

2.41

2.04

1.12

256 ascii array

1.00

1.01

1.04

1.09

0.49

1.01

0.95

1.08

256 doubles array

1.00

1.02

1.08

1.03

6.76

7.34

6.88

3.89

256 unicode array

1.00

0.89

0.89

0.91

0.56

0.73

0.83

0.47

complex object

1.00

1.01

0.85

0.82

1.04

4.11

2.62

2.16

composite object

1.00

1.02

0.72

0.68

0.88

2.79

1.82

1.71

overall

1.00

0.99

0.73

0.78

0.97

4.81

2.27

1.36

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

1.60

1.11

1.18

100 dicts array

1.00

1.04

0.86

0.86

0.94

2.00

1.43

1.27

256 Trues array

1.00

1.16

1.10

1.12

1.20

1.95

1.90

1.89

256 ascii array

1.00

1.02

1.02

1.02

1.39

1.14

1.25

1.62

256 doubles array

1.00

0.90

0.16

0.16

0.39

0.86

0.83

0.42

256 unicode array

1.00

1.01

1.01

1.00

1.02

5.14

5.34

2.40

complex object

1.00

1.01

0.73

0.73

0.88

1.60

1.14

1.20

composite object

1.00

1.02

0.81

0.81

0.85

1.97

1.42

1.26

overall

1.00

1.00

0.90

0.90

0.95

1.61

1.12

1.18

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.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.2.0.tar.gz (169.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.2.0-cp36-cp36m-win_amd64.whl (90.2 kB view details)

Uploaded CPython 3.6mWindows x86-64

python_rapidjson-0.2.0-cp36-cp36m-win32.whl (80.8 kB view details)

Uploaded CPython 3.6mWindows x86

python_rapidjson-0.2.0-cp35-cp35m-win_amd64.whl (90.2 kB view details)

Uploaded CPython 3.5mWindows x86-64

python_rapidjson-0.2.0-cp35-cp35m-win32.whl (80.8 kB view details)

Uploaded CPython 3.5mWindows x86

python_rapidjson-0.2.0-cp35-cp35m-manylinux1_x86_64.whl (726.0 kB view details)

Uploaded CPython 3.5m

python_rapidjson-0.2.0-cp35-cp35m-manylinux1_i686.whl (694.5 kB view details)

Uploaded CPython 3.5m

python_rapidjson-0.2.0-cp34-cp34m-win_amd64.whl (84.5 kB view details)

Uploaded CPython 3.4mWindows x86-64

python_rapidjson-0.2.0-cp34-cp34m-win32.whl (79.8 kB view details)

Uploaded CPython 3.4mWindows x86

python_rapidjson-0.2.0-cp34-cp34m-manylinux1_x86_64.whl (725.6 kB view details)

Uploaded CPython 3.4m

python_rapidjson-0.2.0-cp34-cp34m-manylinux1_i686.whl (697.6 kB view details)

Uploaded CPython 3.4m

File details

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

File metadata

File hashes

Hashes for python-rapidjson-0.2.0.tar.gz
Algorithm Hash digest
SHA256 68713cf8552d7628da3035385565fd0ac3e82203c0231f3cdb5008a9418f3479
MD5 5e68818933c1c7a2cb140bc98e75a79f
BLAKE2b-256 4344fca8b06b348a14213309b28e7cdd41cfa4b4c700a0f050068f5e61e28244

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_rapidjson-0.2.0-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 ef9a417194bd09aed044695f848865499f268d4b8699c736edb9192d2dc73e30
MD5 80b8cb99a16bec965cd6fb3d44d161ae
BLAKE2b-256 0cd8043b704550634d3b30cb06a73fae792934214a099bf8a37a651e113ba950

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_rapidjson-0.2.0-cp36-cp36m-win32.whl
Algorithm Hash digest
SHA256 f45140ff40051188f77773fd71579ffd7ee6e706847968ead9a0520f1e9b30ec
MD5 e413f9bb9728d3dfd4fe042595490323
BLAKE2b-256 20c68cd7b304b15bb9e6d3204f71a174bcdfeeb8411f3b576350333fa00f5583

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_rapidjson-0.2.0-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 0851caaf3bfcb383775a4b36494fae82dee9a020d57e2d380beed2eca11e0607
MD5 d611e6242fe71625611ce0b9835bb49d
BLAKE2b-256 cc023ea9ce5410569866d6ac3efdf477525b6a2a19e913851b961958d5b89071

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_rapidjson-0.2.0-cp35-cp35m-win32.whl
Algorithm Hash digest
SHA256 90f5a49f0fb3b48576bbc83440495b34fb022eaf66c8c94c6d6fc202897727bb
MD5 de31b875634ddea26bf3ca7e17960378
BLAKE2b-256 b1e45e5ccd006e16995a8b8b94b9aeb49ec52c9ab397eababc90a7d25439c1ba

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_rapidjson-0.2.0-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 e9dc541a4a25e3c86b9917fbe31ee20c3f522d1447d230321b573f7b8b8c5766
MD5 c82bb9db1366686e6b4bdca680231249
BLAKE2b-256 8b7bf77b10009df322027680a555c96e2796ef4b1855e387e65da38f4e2d51f1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_rapidjson-0.2.0-cp35-cp35m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 fa6aae4d0c5a0993b6d574dd652851096c00e7fd650bffabc707af44dc709cb1
MD5 dd793c2a404f9ba4c86bef3155726912
BLAKE2b-256 7e3eba1489b52e0cb0aa9e8a614f6f975f01417eee3afadf0e33489bb29e75ad

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_rapidjson-0.2.0-cp34-cp34m-win_amd64.whl
Algorithm Hash digest
SHA256 a023f14497dcdeb849cd753c7291d61a60a29c4881e83a8c628a550c5284c69c
MD5 a1582dd76ba215867477fa11829fda54
BLAKE2b-256 d778754a9dca488f488e5ab2b6ce80bc199dd6b138cae7945a86c09e3dede583

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_rapidjson-0.2.0-cp34-cp34m-win32.whl
Algorithm Hash digest
SHA256 74170a05c485e0ac604ac9173a676a9741e2e123d2d1b56cff25c6a1c5e70d6a
MD5 0c1986fb0f92e6348b3a6a43501e1fdb
BLAKE2b-256 d210e956b9be57c0bcd900c95570e1bb8ac5b6207ec6f4bdc9e47d9e916cf7ab

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_rapidjson-0.2.0-cp34-cp34m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 8aa4db7b1e722c4ad5285fcf47adb9a9f023cc66f67b628991a62d9e562d42ff
MD5 939721b9cdd4fa5fb3a2e4ca4c7b721c
BLAKE2b-256 5bbe0e7c323862cb68547b87c42bd541afb385d0d71d1e428954140a4be0976e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_rapidjson-0.2.0-cp34-cp34m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 d64b46f91fc34f4346d9676c8448ebfbbe3c76f8269c7d79e3165de1a06911e1
MD5 4c8b5410da6d9a96bef4b77a0b99e219
BLAKE2b-256 81cc885aec71c1db4ba9ac1ac658de9a8e4fc14c76a752b582c4587f0f755e93

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