Skip to main content

Python implementation of the cnf format

Packages

  • cnfembed - Text-preserving cnf to json, a single file for embedding.
  • cnftest - Harness to run the conformance tests.

Specification

Consult the full specification for examples and details of the format.

Running tests

The cnftest harness runs the full conformance corpus, from a local copy of the spec kept for the tests. To run the tests:

python3 -m unittest discover

Performance

The following table offers a vague data point on the performance of the implementation. The benchmark was run using the data of a real yaml file with ~67k nodes in a diversified distribution totaling ~800kb. The same file was converted to cnf in the same structure, and also compact json.

Test Parser Best (ms) MB/s
yaml => map (safe_load) YAML 1.2, pure Python 1,441.7 0.53
cnf => map (to_json + json.loads) cnfembed, pure Python 142.6 7.72
cnf => map (ToJSON + json.Unmarshal) cnfembed, Go 23.4 47.24

A conformant YAML 1.2 pure Python implementation was selected, not named here as this is just supposed to show that the performance is not so bad, even being a pure Python implementation, and even if we opt to translate first into json rather than doing a direct map decode.

Example

This simple example shows the conversion of cnf to json:

key: "value"
nested.key: 0xff
string:
    """
    Hello
    world
    """

One call decodes it to JSON:

from cnfembed import to_json

json = to_json(doc)

This results in:

{"key":"value","nested":{"key":255},"string":"Hello\nworld\n"}

For the time being this port converts one direction only: cnf to json.

A string that fails to parse raises Error with the message including the line and column of the problem:

from cnfembed import Error, to_json

try:
    to_json("a: bare\n")
except Error as err:
    print(err)  # 1:4: cannot parse unquoted value `bare`

For actual embedding into your project, you may opt to copy the cnfembed/cnf.py file alone.

Metadata

Release files for python-cnf 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for python-cnf 0.0.2
File Size Uploaded Provenance Actions
python_cnf-0.0.2.tar.gz 63.6 kB Without provenance Details for python_cnf-0.0.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for python-cnf 0.0.2
File Interpreter ABI Platform Actions
python_cnf-0.0.2-py3-none-any.whl Python 3 none any Details for python_cnf-0.0.2-py3-none-any.whl

Total release size: 83.1 kB

Release files / python_cnf-0.0.2.tar.gz

Download URL python_cnf-0.0.2.tar.gz
Size 63.6 kB
Tags Source
SHA-256 checksum
How to use checksums
427016f8ee2bae6bc639e8a82252f5c3a069a483364be457651eb0f766a9b9fa
BLAKE2b-256 checksum
How to use checksums
23e6829cc889bc10d55f3a87baceb0c74b8093cecec2e5811aa82077b24a3cf4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.4

Release files / python_cnf-0.0.2-py3-none-any.whl

Download URL python_cnf-0.0.2-py3-none-any.whl
Size 19.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
10e7783c537ac64c1b6201b67da40f6255e48dd65d9dea7dd99dc911c559faf8
BLAKE2b-256 checksum
How to use checksums
725f94fbe360bb2241ccf139c597e604070a0bd1ecae65fe508e0113310a3879
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.4

Security for python-cnf 0.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page