Skip to main content

Python wrapper around rapidjson

Project description

Authors:

Ken Robbins <ken@kenrobbins.com>; Lele Gaifax <lele@metapensiero.it>

License:

MIT License

Status:

Build status Documentation status

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.

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 shows 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.97

0.75

0.75

0.92

4.15

2.16

1.29

100 dicts array

1.00

1.04

0.84

0.82

1.08

5.29

2.22

1.35

256 Trues array

1.00

1.17

1.21

1.22

1.50

2.93

2.25

1.32

256 ascii array

1.00

1.01

1.04

1.04

0.52

1.21

1.05

1.24

256 doubles array

1.00

1.02

1.12

1.02

6.94

7.90

8.26

4.02

256 unicode array

1.00

0.86

0.87

0.85

0.55

0.72

0.65

0.52

complex object

1.00

1.01

0.85

0.88

1.02

3.86

2.56

2.09

composite object

1.00

1.02

0.73

0.70

0.87

2.79

1.83

1.88

overall

1.00

0.97

0.75

0.75

0.92

4.14

2.16

1.29

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

0.96

1.52

1.17

1.14

100 dicts array

1.00

1.22

0.85

0.87

0.93

2.13

1.58

1.23

256 Trues array

1.00

1.37

1.19

1.24

1.12

2.04

1.77

1.77

256 ascii array

1.00

1.03

1.03

1.04

1.38

1.22

1.17

1.41

256 doubles array

1.00

0.96

0.26

0.22

0.50

1.06

0.99

0.52

256 unicode array

1.00

1.01

1.02

1.01

1.26

5.35

6.05

2.96

complex object

1.00

1.02

0.98

0.84

1.09

1.79

1.31

1.34

composite object

1.00

1.03

0.80

0.83

0.75

2.01

1.36

1.22

overall

1.00

1.00

0.90

0.89

0.96

1.52

1.18

1.14

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.

Arbitrary encodings

json.loads() accepts an encoding kwarg determining the encoding of its input, when that is a bytes or bytearray instance. Although RapidJSON is able to cope with several different encodings, we currently supports only the recommended one, UTF-8.

Changes

0.4.3 (2018-01-14)

  • Deserialize from bytes and bytearray instances, ensuring they contain valid UTF-8 data

  • Speed up parsing of floating point numbers, avoiding intermediary conversion to a Python string (PR #94)

0.4.2 (2018-01-09)

  • Fix precision handling of DM_UNIX_TIME timestamps

0.4.1 (2018-01-08)

  • Fix memory leaks in Decoder() and Encoder() classes, related to bad handling of PyObject_GetAttr() result value

  • Fix compatibility with Python 3.7a

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.3.tar.gz (181.3 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.3-cp36-cp36m-win_amd64.whl (121.1 kB view details)

Uploaded CPython 3.6mWindows x86-64

python_rapidjson-0.4.3-cp36-cp36m-win32.whl (105.6 kB view details)

Uploaded CPython 3.6mWindows x86

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

Uploaded CPython 3.6m

python_rapidjson-0.4.3-cp36-cp36m-manylinux1_i686.whl (1.1 MB view details)

Uploaded CPython 3.6m

python_rapidjson-0.4.3-cp36-cp36m-macosx_10_6_intel.whl (355.2 kB view details)

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

python_rapidjson-0.4.3-cp35-cp35m-win_amd64.whl (121.1 kB view details)

Uploaded CPython 3.5mWindows x86-64

python_rapidjson-0.4.3-cp35-cp35m-win32.whl (105.6 kB view details)

Uploaded CPython 3.5mWindows x86

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

Uploaded CPython 3.5m

python_rapidjson-0.4.3-cp35-cp35m-manylinux1_i686.whl (1.1 MB view details)

Uploaded CPython 3.5m

python_rapidjson-0.4.3-cp35-cp35m-macosx_10_6_intel.whl (355.2 kB view details)

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

python_rapidjson-0.4.3-cp34-cp34m-win_amd64.whl (114.4 kB view details)

Uploaded CPython 3.4mWindows x86-64

python_rapidjson-0.4.3-cp34-cp34m-win32.whl (103.7 kB view details)

Uploaded CPython 3.4mWindows x86

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

Uploaded CPython 3.4m

python_rapidjson-0.4.3-cp34-cp34m-manylinux1_i686.whl (1.1 MB view details)

Uploaded CPython 3.4m

python_rapidjson-0.4.3-cp34-cp34m-macosx_10_6_intel.whl (353.8 kB view details)

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

File details

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

File metadata

File hashes

Hashes for python-rapidjson-0.4.3.tar.gz
Algorithm Hash digest
SHA256 7038efdf7f0915a2ec78baff1aa0cc4f133c1949a582518d2f29e6d1a6c98ba6
MD5 a045122f4b13fcc5337b88ead18a0a6b
BLAKE2b-256 15fddc630f4a946fa9aa95350e8bd711f0d3df17311ee35c6943d60c584a8c3c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_rapidjson-0.4.3-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 35efa4bd0754b420b57d76f54e41d4a64e1c36fa8b201a25f27a1c591da61421
MD5 65c70dbb1abcece478ea962da8f59aca
BLAKE2b-256 2e3888e8dab30fed93a166580c86c2033d978afaf6965540ef52b044020327e6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_rapidjson-0.4.3-cp36-cp36m-win32.whl
Algorithm Hash digest
SHA256 00fe35c54c834d2bd4d52ab2ed0b386fa77c9a754477268cf90e621e96b7883e
MD5 43c62b14bb87c43fe579de6c6634bb8f
BLAKE2b-256 f1083d603f79b7c58013945af9962f438f005f6858f2915fad6aae9d19345ea6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_rapidjson-0.4.3-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 1879d4b7218fd27689c69f4de6ccad31aec85adb7b885d4a5514a9ff4a08b3f9
MD5 881b4f8c353a9b9876c87da571b4ada7
BLAKE2b-256 de9bbdc2b4ce4176bd5ff10607e2b177944eb19bfd4dbffa460e331d1177ba21

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_rapidjson-0.4.3-cp36-cp36m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 d2f53812ed5f1fe77a3e34d9512a8bfd4b54a52bcd71678a100cc605a4c2d1d7
MD5 cd5f2514adb3a11ee3ff7fad3fa9daf1
BLAKE2b-256 9ea23f63b4560ba1d3953fcd37e0cd123472119f75958229a6c560e5b74656a7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_rapidjson-0.4.3-cp36-cp36m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 b8c6018594eca9fea6e36a3fb77dea7cf72ce1c1b0891b1aa8c995208741f82b
MD5 7d494029761091effaae39aa470f6547
BLAKE2b-256 d4d9947ee63ec631f8305695a58dd2e19c882b75bccbffff72a649955b9f3545

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_rapidjson-0.4.3-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 28dd2ca9d4d01616eb0cef38020cb6883dd55c80e7a6d4e498e8f7c4d040d68e
MD5 8212040d369c127ec993cc5faba5ba83
BLAKE2b-256 a986bfdd76febee586ea93eb32715464a3df01cedf8c2b8ae74f5898f2184fe8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_rapidjson-0.4.3-cp35-cp35m-win32.whl
Algorithm Hash digest
SHA256 2f2c96d81d7a5abf4b1653a25a4d10bd5e701b26eb268a3ac0ad9be49aa78278
MD5 cf92181cddb3320f313c18bced8396ee
BLAKE2b-256 af22e24ed5e6890ae0c78cca1be6e3ea3a2e9cc0c141c46f38f9503467ee9d1e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_rapidjson-0.4.3-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 6afe8e046d5653bbfc06a6cb4535de701e52c150f88753cf2fe12fa3e1dbcdd7
MD5 cec5fe5e57d516688c4732142f8dd957
BLAKE2b-256 a9d86d6696243e984ac886e2d1e3ccb307ff7f0de2b60ce4034f46879a52450a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_rapidjson-0.4.3-cp35-cp35m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 cbf83c63b7f71abfa44711f633ad053a9d9a9e865431f3a94414628cf64ad684
MD5 160cded89e8d1379d6ef1f573255b769
BLAKE2b-256 f9768e1b25df142b307cc5fbb1e0cca6ea09459646a616d21726c335820b79a9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_rapidjson-0.4.3-cp35-cp35m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 ce11e10c53ca2fefa602777a8c888f029bd1e7a6af499ffc3896ebec16333341
MD5 9df91c68a3dce396d4db59af5280473e
BLAKE2b-256 21ebbb72fc60062a562df75946cea157f2c0e1cb767459406751eaa5bdba403f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_rapidjson-0.4.3-cp34-cp34m-win_amd64.whl
Algorithm Hash digest
SHA256 d60190d35fa703c881ea21cf9a33f9df8a5ef241abc3f4744c1294ceda6ebcfc
MD5 d5759de7fb79ea9269807415da33cf99
BLAKE2b-256 6e66b1b127dc7bb917817eafdfb588840c94963fbfc03afa9c3333a1923260c8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_rapidjson-0.4.3-cp34-cp34m-win32.whl
Algorithm Hash digest
SHA256 7ceaebf984399ddb2f0b5d56a0356541e3897f2e7e6269f3dd163d3fdb961152
MD5 19221cccf1a69c8ce0bbd7a2f8bf40dc
BLAKE2b-256 a7547a402463d508d1ae511037b22e264a6d6ce0aeeb4889edb4c00b88c53ebe

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_rapidjson-0.4.3-cp34-cp34m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 0959d955c83a373ee87c49ffa3b66ab40881ac7c1a941069a690567f9557e01f
MD5 ca91858553749b7d37ed2db2d5cc43fc
BLAKE2b-256 3f34e53ff127f079440d373f6786ba3527980e0b5ce6ca619cb40268821377e5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_rapidjson-0.4.3-cp34-cp34m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 a8e1856f666c8f7d31f9fb474cef41a5777a0092ba9a7752bdba0fc492fb4d62
MD5 8b5d6750496efdcac5f3b72c4095331d
BLAKE2b-256 8f62676cc904333a37bca637903dc19e177e726da69dd22efa9cacb18d39b867

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_rapidjson-0.4.3-cp34-cp34m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 bc1c5eeba94470d38d4167e82e4a806ed7dcffb8de67db14b47715ea317b48dc
MD5 6280c74aa8ac89ebfb2274b3c0ecd43a
BLAKE2b-256 664ec395d967a85b01ff70b8cd110c3eeb5e879ee3df10b8f6a69960ebdd5c88

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