Registry / serialization / rfc8785

rfc8785

JSON →
library0.1.4pypypi✓ verified 85d ago

rfc8785.py is a pure-Python, no-dependency implementation of RFC 8785, also known as the JSON Canonicalization Scheme (JCS). It provides deterministic serialization of JSON data, essential for cryptographic operations like hashing and signing where byte-identical representations are required for logically equivalent data. The library is actively maintained, with version 0.1.4 being the latest stable release, and it follows an irregular release cadence driven by contributions and fixes.

pip install rfc8785
INSTALL
IMPORT
SIG · RFC8785
R
rfc8785
serializationpythonv0.1.4
Install
1.5s avg
Import
12ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.1.4 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.012s · 17.8MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 1.5s · import 0.012s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

dumps
from rfc8785 import dumps
import rfc8785
dump
from rfc8785 import dump
import rfc8785
CanonicalizationError
from rfc8785 import CanonicalizationError
import rfc8785

Demonstrates how to use `rfc8785.dumps` to get the canonical byte representation of a Python dictionary. The output is always UTF-8 encoded bytes with keys sorted lexicographically, and specific number and literal serialization as per RFC 8785.

import rfc8785 data = { "name": "Alice", "age": 30, "isStudent": False, "courses": ["Math", "Science"], "address": { "city": "New York", "zip": "10001" } } canonical_bytes = rfc8785.dumps(data) print(canonical_bytes.decode('utf-8'))
Debug
Known issues
breakingAs of v0.1.3, the library explicitly raises `CanonicalizationError` when encountering non-string dictionary keys, rather than attempting implicit conversion or silent failure.
fix
Ensure all dictionary keys in the input data are strings before passing to `rfc8785.dumps` or `rfc8785.dump`.
affects: >=0.1.3
gotchaAll API functions (`dumps`, `dump`) produce UTF-8 encoded `bytes` objects or write to `bytes` I/O, not standard Python `str` objects. You must decode the output if a string is required.
fix
Call `.decode('utf-8')` on the result of `rfc8785.dumps` if a string is needed (e.g., `rfc8785.dumps(data).decode('utf-8')`).
affects: All versions
gotchaThe library enforces strict number serialization according to ECMAScript's IEEE 754 double-precision float representation, raising `IntegerDomainError` or `FloatDomainError` for integers exceeding this precision or floats like NaN/Infinity.
fix
Ensure numbers adhere to IEEE 754 double-precision standards. Large integers or special float values (NaN, Inf) must be serialized as strings in the input data if they are not representable.
affects: All versions
gotcharfc8785.py explicitly does not support indentation or pretty-printing. The output is always minimally encoded as required by JCS.
fix
Do not expect or attempt to configure `rfc8785` for human-readable output; its purpose is machine-readable canonicalization.
affects: All versions
Upgrade
Version history
0.1.4latest on PyPI · released Sep 27, 2024
Audit
Dependencies

No dependency data recorded yet.

Agent activity
10 hits · last 30 days
node
8
OpenAI (training)
2
Resources
rfc8785 — pip install rfc8785 · libregistry