orjson
A fast, correct, Rust-backed JSON library for Python with native dataclass, datetime, and numpy support
Repository Health
Technical Analysis
orjson is a fast, correct JSON library for Python, implemented in Rust and exposed via PyO3 bindings. It benchmarks as the fastest Python JSON library and serializes dataclass, datetime, numpy, and UUID instances natively, without needing a custom default handler for the common cases most projects hit.
orjson.dumps() is roughly 10x faster than the standard library’s json module and orjson.loads() roughly 2x faster, while staying strictly compliant with UTF-8 and RFC 8259. It intentionally does not provide file I/O or line-delimited JSON helpers, keeping its scope to serialization/deserialization only, and treats adding an implicit serialization for a new type without an opt-in flag as a breaking change under its semver policy.
What You Get
- A
dumps/loadsAPI that is a near drop-in replacement for the standard libraryjsonmodule - Native serialization of dataclasses, datetime/date/time objects, numpy arrays, and UUIDs without a custom
defaultfunction - Strict RFC 8259 and UTF-8 compliant deserialization, more correct than
jsonor most third-party alternatives - Prebuilt wheels for amd64/arm64/ppc64le/s390x across Linux, macOS, and Windows, with AVX-512 runtime acceleration when available
- A stable semver policy where any new implicit type serialization is treated as a breaking change
Common Use Cases
- Speeding up API response serialization in high-throughput Python web services
- Serializing dataclass-based domain models directly to JSON without writing custom encoders
- Working with numpy-heavy data pipelines that need fast JSON I/O for arrays
- Replacing
json.dumps/json.loadscalls in performance-sensitive code paths with minimal migration effort
Under The Hood
Architecture - orjson is a thin Python-facing API (pysrc/) over a Rust core (src/) split into serialize and deserialize modules plus ffi glue and a typeref.rs module that caches references to Python type objects (dataclass, datetime, UUID, numpy) to avoid repeated attribute lookups on the hot path; PyO3 handles the CPython/Rust boundary. Tech Stack - Rust (Cargo.toml/Cargo.lock pin the toolchain and dependencies) built via build.rs into a CPython extension module, published as prebuilt wheels for CPython 3.10-3.15 across six CPU architectures and three OSes. Code Quality - the test/ directory contains 34 Python test modules covering dataclasses, datetime, numpy, UUID, fragments, and option flags, plus a bench benchmark suite comparing against json and other libraries; the project has no public issue tracker (by design, to reduce noise) which means quality is enforced primarily through the maintainer’s own test/benchmark discipline rather than community triage. API Design - the dumps/loads surface intentionally mirrors the standard library’s json module for near drop-in migration, while option flags (rather than kwargs sprawl) control serialization behavior like non-str keys, UTC handling, and numpy array support, keeping the public API small and stable under its semver-as-breaking-change policy.