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)
'{"foo":100,"bar":"baz"}'
>>> 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.

See the this section in the documentation for a comparison with other JSON libraries.

Incompatibility

Although we tried to implement an API similar to the standard library json, being a strict drop-in replacement in not our goal and we have decided to depart from there in some aspects. See this section in the documentation for further details.

Changes

1.16 (2024-02-28)

  • Produce Python 3.8 wheels again, I deactivated it too eagerly, it’s in security fixes only mode, not yet reached its end-of-life state

1.15 (2024-02-28)

1.14 (2023-12-14)

  • Produce binary wheels for macOS/arm64, thanks to timothyjlaurent (PR #195)

1.13 (2023-10-29)

  • Fix handling of write_mode in dump functions (problem emerged discussing issue #191)

1.12 (2023-10-07)

  • Generate wheels on PyPI using final Python 3.12 release, thanks to cibuildwheel 2.16.2

1.11 (2023-09-11)

1.10 (2023-03-15)

1.9 (2022-10-17)

  • Produce Python 3.11 wheels, thanks to cibuildwheel 2.11.1

1.8 (2022-07-07)

1.7 (2022-07-06)

  • Use current master version of rapidjson

  • Update the test suite to work on Pyston, thanks to Kevin Modzelewski (PR #161)

1.6 (2022-02-19)

  • Fix memory leak when using end_array (issue #160)

1.5 (2021-10-16)

  • Fix serialization bug when using DM_UNIX_TIME in a non-C locale context

1.4 (2021-06-25)

  • Build binary wheel for aarch64, thanks to odidev (PR #156)

1.3 (2021-06-25)

  • Yet another attempt to fix automatic wheels upload

1.2 (2021-06-25)

  • Fix automatic wheels upload from GH Actions to PyPI

1.1 (2021-06-25)

  • Reduce decoder memory consumption by uniquifiying keys in the loaded dictionaries

  • Implement an alternative way of transmogrify JSON objects, similar to json‘s object_pairs_hook load option (issue #154)

1.0 (2020-12-13)

  • Require Python 3.6 or greater

  • New serialization options, iterable_mode and mapping_mode, to give some control on how generic iterables and mappings get encoded (fix issue #149 and issue #150)

  • Internal refactorings, folding “skipkeys” and “sort_keys” arguments into the mapping_mode options, respectively as MM_SKIP_NON_STRING_KEYS and MM_SORT_KEYS: “old” arguments kept for backward compatibility

  • Bump major version to 1, tag as “production/stable” and switch to a simpler X.Y versioning schema

0.9.4 (2020-11-16)

  • Fix memory leak loading an invalid JSON (issue #148)

0.9.3 (2020-10-24)

  • Fix access to Encoder instance attributes (issue #147)

0.9.2 (2020-10-24)

  • Use current master version of rapidjson

  • Enable GH Actions-based test workflow, thanks to Martin Thoma (PR #143)

  • Produce Python 3.9 wheels, disable testing under Python < 3.6

  • Make the character used for indentation in pretty mode a parameter (issue #135)

  • Handle wider precision range in timestamps fractional seconds (PR 133), thanks to Karl Seguin

  • Add comparison benchmarks against orjson and hyperjson (issue #130 and PR #131, thanks to Sebastian Pipping)

0.9.1 (2019-11-13)

  • Fix memory leak in case of failed validation (issue #126)

0.9.0 (2019-11-13)

  • Produce Python 3.8 wheels

  • Compatibility fix for Python 3.8 (issue #125)

  • New dump option write_mode, supporting RapidJSON’s kFormatSingleLineArray option (issue #123), thanks to Nguyễn Hồng Quân for the initial implementation (PR #124)

0.8.0 (2019-08-09)

  • New serialization option bytes_mode to control how bytes instances get encoded (issue #122)

0.7.2 (2019-06-09)

  • Hopefully fix the memory leak when loading from a stream (issue #117)

0.7.1 (2019-05-11)

  • Raise a more specific exception on loading errors, JSONDecodeError, instead of generic ValueError (issue #118)

  • Fix optimization path when using OrderedDicts (issue #119)

  • Fix serialization of IntEnums (issue #121)

  • I spent quite a lot of time investigating on the memory leak when loading from a stream (issue #117): as I was not able to fully replicate the problem, I cannot be sure I solved the problem… sorry!

0.7.0 (2019-02-11)

  • Raise correct exception in code samples (PR #109), thanks to Thomas Dähling

  • Fix compilation with system-wide install of rapidjson (issue #110)

  • Use current master version of rapidjson, that includes a fix for its issue #1368 and issue #1336, and cures several compilation warnings as well (issue #112 and issue #107)

  • Fix memory leak when using object_hook (issue #115)

0.6.3 (2018-07-11)

  • No visible changes, but now PyPI carries binary wheels for Python 3.7.

0.6.2 (2018-06-08)

  • Use a more specific ValidationError, to differentiate from invalid JSON

0.6.1 (2018-06-06)

  • Nothing new, attempt to build Python 3.6 binary wheels on Travis CI

0.6.0 (2018-06-06)

  • Add a new comparison table involving ensure_ascii (issue #98)

  • Use Python’s repr() to emit float values instead of rapidjson’s dtoa() (issue #101)

  • Use a newer (although unreleased) version of rapidjson to fix an issue with JSONSchema validation (PR #103), thanks to Anthony Miyaguchi

0.5.2 (2018-03-31)

  • Tiny tweak to restore macOS build on Travis CI

0.5.1 (2018-03-31)

  • Minor tweaks to CI and PyPI deploy configuration

0.5.0 (2018-03-31)

  • New RawJSON class, allowing inclusion of pre-serialized content (PR #95 and PR #96), thanks to Silvio Tomatis

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-1.16.tar.gz (230.1 kB view hashes)

Uploaded Source

Built Distributions

python_rapidjson-1.16-cp312-cp312-win_amd64.whl (147.0 kB view hashes)

Uploaded CPython 3.12 Windows x86-64

python_rapidjson-1.16-cp312-cp312-win32.whl (126.3 kB view hashes)

Uploaded CPython 3.12 Windows x86

python_rapidjson-1.16-cp312-cp312-musllinux_1_1_x86_64.whl (2.3 MB view hashes)

Uploaded CPython 3.12 musllinux: musl 1.1+ x86-64

python_rapidjson-1.16-cp312-cp312-musllinux_1_1_ppc64le.whl (2.3 MB view hashes)

Uploaded CPython 3.12 musllinux: musl 1.1+ ppc64le

python_rapidjson-1.16-cp312-cp312-musllinux_1_1_i686.whl (2.2 MB view hashes)

Uploaded CPython 3.12 musllinux: musl 1.1+ i686

python_rapidjson-1.16-cp312-cp312-musllinux_1_1_aarch64.whl (2.2 MB view hashes)

Uploaded CPython 3.12 musllinux: musl 1.1+ ARM64

python_rapidjson-1.16-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.7 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

python_rapidjson-1.16-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.7 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ ppc64le

python_rapidjson-1.16-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.7 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ ARM64

python_rapidjson-1.16-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (1.6 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

python_rapidjson-1.16-cp312-cp312-macosx_11_0_arm64.whl (208.0 kB view hashes)

Uploaded CPython 3.12 macOS 11.0+ ARM64

python_rapidjson-1.16-cp312-cp312-macosx_10_9_x86_64.whl (228.4 kB view hashes)

Uploaded CPython 3.12 macOS 10.9+ x86-64

python_rapidjson-1.16-cp311-cp311-win_amd64.whl (147.1 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

python_rapidjson-1.16-cp311-cp311-win32.whl (125.7 kB view hashes)

Uploaded CPython 3.11 Windows x86

python_rapidjson-1.16-cp311-cp311-musllinux_1_1_x86_64.whl (2.3 MB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.1+ x86-64

python_rapidjson-1.16-cp311-cp311-musllinux_1_1_ppc64le.whl (2.3 MB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.1+ ppc64le

python_rapidjson-1.16-cp311-cp311-musllinux_1_1_i686.whl (2.2 MB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.1+ i686

python_rapidjson-1.16-cp311-cp311-musllinux_1_1_aarch64.whl (2.2 MB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.1+ ARM64

python_rapidjson-1.16-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.7 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

python_rapidjson-1.16-cp311-cp311-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.7 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ppc64le

python_rapidjson-1.16-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.6 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARM64

python_rapidjson-1.16-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (1.6 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

python_rapidjson-1.16-cp311-cp311-macosx_11_0_arm64.whl (207.2 kB view hashes)

Uploaded CPython 3.11 macOS 11.0+ ARM64

python_rapidjson-1.16-cp311-cp311-macosx_10_9_x86_64.whl (226.8 kB view hashes)

Uploaded CPython 3.11 macOS 10.9+ x86-64

python_rapidjson-1.16-cp310-cp310-win_amd64.whl (147.1 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

python_rapidjson-1.16-cp310-cp310-win32.whl (125.7 kB view hashes)

Uploaded CPython 3.10 Windows x86

python_rapidjson-1.16-cp310-cp310-musllinux_1_1_x86_64.whl (2.2 MB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

python_rapidjson-1.16-cp310-cp310-musllinux_1_1_ppc64le.whl (2.3 MB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ ppc64le

python_rapidjson-1.16-cp310-cp310-musllinux_1_1_i686.whl (2.2 MB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ i686

python_rapidjson-1.16-cp310-cp310-musllinux_1_1_aarch64.whl (2.2 MB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ ARM64

python_rapidjson-1.16-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.7 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

python_rapidjson-1.16-cp310-cp310-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.7 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ppc64le

python_rapidjson-1.16-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.6 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

python_rapidjson-1.16-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (1.6 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

python_rapidjson-1.16-cp310-cp310-macosx_11_0_arm64.whl (207.2 kB view hashes)

Uploaded CPython 3.10 macOS 11.0+ ARM64

python_rapidjson-1.16-cp310-cp310-macosx_10_9_x86_64.whl (226.8 kB view hashes)

Uploaded CPython 3.10 macOS 10.9+ x86-64

python_rapidjson-1.16-cp39-cp39-win_amd64.whl (146.8 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

python_rapidjson-1.16-cp39-cp39-win32.whl (125.4 kB view hashes)

Uploaded CPython 3.9 Windows x86

python_rapidjson-1.16-cp39-cp39-musllinux_1_1_x86_64.whl (2.2 MB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

python_rapidjson-1.16-cp39-cp39-musllinux_1_1_ppc64le.whl (2.2 MB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ ppc64le

python_rapidjson-1.16-cp39-cp39-musllinux_1_1_i686.whl (2.2 MB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ i686

python_rapidjson-1.16-cp39-cp39-musllinux_1_1_aarch64.whl (2.2 MB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ ARM64

python_rapidjson-1.16-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.7 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

python_rapidjson-1.16-cp39-cp39-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.7 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ppc64le

python_rapidjson-1.16-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.6 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARM64

python_rapidjson-1.16-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (1.6 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

python_rapidjson-1.16-cp39-cp39-macosx_11_0_arm64.whl (207.2 kB view hashes)

Uploaded CPython 3.9 macOS 11.0+ ARM64

python_rapidjson-1.16-cp39-cp39-macosx_10_9_x86_64.whl (227.0 kB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

python_rapidjson-1.16-cp38-cp38-win_amd64.whl (147.9 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

python_rapidjson-1.16-cp38-cp38-win32.whl (127.8 kB view hashes)

Uploaded CPython 3.8 Windows x86

python_rapidjson-1.16-cp38-cp38-musllinux_1_1_x86_64.whl (2.2 MB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ x86-64

python_rapidjson-1.16-cp38-cp38-musllinux_1_1_ppc64le.whl (2.3 MB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ ppc64le

python_rapidjson-1.16-cp38-cp38-musllinux_1_1_i686.whl (2.2 MB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ i686

python_rapidjson-1.16-cp38-cp38-musllinux_1_1_aarch64.whl (2.2 MB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ ARM64

python_rapidjson-1.16-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.7 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

python_rapidjson-1.16-cp38-cp38-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.7 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ppc64le

python_rapidjson-1.16-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.6 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ARM64

python_rapidjson-1.16-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (1.6 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

python_rapidjson-1.16-cp38-cp38-macosx_11_0_arm64.whl (208.3 kB view hashes)

Uploaded CPython 3.8 macOS 11.0+ ARM64

python_rapidjson-1.16-cp38-cp38-macosx_10_9_x86_64.whl (227.8 kB view hashes)

Uploaded CPython 3.8 macOS 10.9+ x86-64

Supported by

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