python-rapidjson

Fast Python JSON parsing and serialization powered by the RapidJSON C++ library

Library
PyPI
v1.23
532stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
52/100Fair
Development Activity56
Maintenance16
Community56
Maturity60
Momentum20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
68/100Good
Architecture70
Code Quality78
Innovation62
Learning Curve60

python-rapidjson is a Python 3 C-extension wrapper around Tencent’s RapidJSON, a high-performance C++ JSON library. It exposes RapidJSON’s serialization, deserialization, and JSON Schema validation capabilities through an API deliberately modeled on the standard library’s json module, so it works as a near drop-in replacement for teams that need faster encode/decode throughput.

Beyond raw speed, it supports streaming to and from file-like objects with configurable chunk sizes, a relaxed parsing mode for JSONC-style comments and trailing commas, and both function-based (dumps/loads) and class-based (Encoder/Decoder) usage patterns for reusable, configured serializers.

What You Get

  • dumps/loads functions with an API closely modeled on the standard library json module
  • Class-based Encoder/Decoder objects for reusable, pre-configured serialization settings
  • Streaming support to/from file-like objects with configurable chunk sizes
  • A relaxed parsing mode (PM_COMMENTS, PM_TRAILING_COMMAS) for JSONC-style input
  • Built-in JSON Schema validation via RapidJSON’s schema module

Common Use Cases

  • Speeding up JSON encode/decode in high-throughput API services or data pipelines
  • Parsing JSONC-style config files that contain comments or trailing commas
  • Validating incoming JSON payloads against a JSON Schema without a separate validation library
  • Streaming large JSON documents to/from sockets or files instead of loading them fully into memory

Under The Hood

Architecture — the package is a thin Python-facing C++ extension (rapidjson.cpp) that binds directly to the RapidJSON C++ library (included as a git submodule), exposing dumps/loads module-level functions plus Encoder/Decoder classes; the Python side (rapidjson/ package) mostly re-exports the compiled extension and adds small conveniences like enum/dataclass support.

Tech Stack — built with setuptools as a C++ extension module (compiled via setup.py build), requiring a C++ compiler and the RapidJSON headers at build time; runtime has zero Python dependencies since all JSON logic lives in compiled code, and wheels are published for common platforms via PyPI.

Code Quality — the tests/ directory contains a large, granular suite covering base types, streams, Unicode edge cases, circular references, memory leaks, JSON Schema validation, and the official JSON test-suite fixtures (test_pass1/2/3.py), run via pytest/tox; this depth of coverage is notable for a C-extension project where memory safety is a real risk.

API Design — the API intentionally mirrors json.dumps/json.loads for near drop-in compatibility, while adding an explicit Encoder/Decoder class pair for callers who want to configure and reuse serialization settings (parse mode, datetime handling, NaN handling) without passing the same kwargs on every call; documented incompatibilities with the standard json module are called out explicitly in the docs rather than silently diverging.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search