toons is a high-performance Python library for parsing and serializing TOON (Token Oriented Object Notation), implemented in Rust for speed. It offers an API that mirrors Python's built-in `json` module, making it easy to convert Python objects to TOON strings and vice-versa. TOON is a token-efficient data serialization format specifically designed to reduce token counts for Large Language Models. The current version is 0.5.4, with frequent minor releases addressing fixes and specification compliance.
pip install toonsVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to serialize a Python dictionary and a list of dictionaries (tabular data) into TOON format, and then parse a TOON string back into a Python object using `toons.dumps` and `toons.loads`, mirroring the standard `json` library API.
Review the TOON Specification v3.0 for any changes relevant to your data structures and update your TOON inputs/outputs accordingly.
Upgrade to `toons` version 0.5.3 or later to ensure correct handling of unicode and datetime types.
Ensure your TOON input strictly adheres to the v3.0 specification, or pass `strict=False` to `toons.loads()` for more tolerant parsing, e.g., `toons.loads(toon_str, options={'strict': False})`.Import the `toons` module directly: `import toons` then use `toons.dumps()` or `toons.loads()`.
Convert the object to a TOON-serializable type before dumping, or provide a `default` function to `toons.dumps` to handle custom types: `toons.dumps(data, default=my_serializer_function)`.
Verify the input string for malformation and ensure it strictly adheres to the TOON specification before passing it to `toons.loads`.
Install the Rust toolchain (`rustup install stable`, `rustup update`) and any necessary system build tools (e.g., `build-essential` on Linux, Xcode Command Line Tools on macOS, Visual Studio Build Tools on Windows), then retry `pip install toons`.
No dependency data recorded yet.