Python package leveraging our Canonical JSON implementation in Rust.
In order to validate content signatures of our data, Canonical JSON gives us a predictable JSON serialization. And Rust allows us to reuse the same implementation between our server in Python (this package) and our diverse clients (Rust, Android/iOS, JavaScript).
pip install canonicaljson-rs
>>> import canonicaljson
>>>
>>> canonicaljson.dumps({"héo": 42})
'{"h\\u00e9o":42}'
canonicaljson.dumps(obj: Any) -> str
canonicaljson.dump(obj: Any, stream: IO) -> str
We rely on a specific Python builder that automates everything around Rust bindings.
pip install maturin
In order to install the package in the current environment:
maturin develop
Run tests:
pytest
- Create a release on Github on https://github.com/mozilla-services/python-canonicaljson-rs/releases/new
- Create a new tag vX.Y.Z (This tag will be created from the target when you publish this release.)
- Generate release notes
- Publish release
- https://github.com/gibson042/canonicaljson-spec
- The code to build a
serde_json::Value
from apyo3::PyObject
was greatly inspired by Matthias Endler's hyperjson
Other specs:
- https://github.com/Kinto/kinto-signer/blob/6.1.0/kinto_signer/canonicaljson.py
- https://searchfox.org/mozilla-central/rev/b2395478c/toolkit/modules/CanonicalJSON.jsm
- https://github.com/matrix-org/python-canonicaljson
- Mozilla Public License 2.0