Skip to main content

A pure-Python implementation of RFC 8785 (JSON Canonicalization Scheme)

Project description

rfc8785.py

CI PyPI version Packaging status

A pure-Python, no-dependency implementation of RFC 8785, a.k.a. JSON Canonicalization Scheme or JCS.

This implementation should be behaviorally comparable to Andrew Rundgren's reference implementation, with the following added constraints:

  1. This implementation does not transparently convert non-str dictionary keys into strings. Users must explicitly perform this conversion.
  2. No support for indentation, pretty-printing, etc. is provided. The output is always minimally encoded.
  3. All APIs produce UTF-8-encoded bytes objects or bytes I/O.

Installation

python -m pip install rfc8785

Usage

See the full API documentation here.

import rfc8785

foo = {
    "key": "value",
    "another-key": 2,
    "a-third": [1, 2, 3, [4], (5, 6, "this works too")],
    "more": [None, True, False],
}

rfc8785.dumps(foo)

yields:

b'{"a-third":[1,2,3,[4],[5,6,"this works too"]],"another-key":2,"key":"value","more":[null,true,false]}'

For direct serialization to an I/O sink, use rfc8785.dump instead:

import rfc8785

with open("/some/file", mode="wb") as io:
    rfc8785.dump([1, 2, 3, 4], io)

All APIs raise rfc8785.CanonicalizationError or a subclass on serialization failures.

Licensing

Apache License, Version 2.0.

Where noted, parts of this implementation are adapted from Andrew Rundgren's reference implementation, which is also licensed under the Apache License, Version 2.0.

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

rfc8785-0.0.2.tar.gz (8.5 kB view details)

Uploaded Source

Built Distribution

rfc8785-0.0.2-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file rfc8785-0.0.2.tar.gz.

File metadata

  • Download URL: rfc8785-0.0.2.tar.gz
  • Upload date:
  • Size: 8.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.8

File hashes

Hashes for rfc8785-0.0.2.tar.gz
Algorithm Hash digest
SHA256 21cad1927557486e6ad2f7c06b35196ed97b4453264e215c45f5c835a2b6ccbc
MD5 91d9c21c36fb5f01272e86fc295bca96
BLAKE2b-256 344e3216ac933546b370fbccc25c4327d7e2564eaa5255efd9ce7d4db071f418

See more details on using hashes here.

File details

Details for the file rfc8785-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: rfc8785-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 8.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.8

File hashes

Hashes for rfc8785-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 0a186666340b57c1c8f365429a07f55261a1a60b2957f63b294820c4e3c0b5e4
MD5 780886a7f3bcee5f6f49afbfa9f499f2
BLAKE2b-256 807926e853e5f95e99a0799762bfd1b07b0a24189c92a1f989b70960ded8c22d

See more details on using hashes here.

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