Toonify is a Python implementation of TOON (Token-Oriented Object Notation), a compact, human-readable serialization format designed specifically for use with Large Language Models (LLMs). It aims to reduce token consumption by 30-60% compared to JSON, while preserving data structure, type safety, and human readability. The library provides functions to encode Python dictionaries and Pydantic models into TOON strings and decode them back. It is actively maintained with a regular release cadence.
pip install toonifyVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates the basic usage of the `encode` and `decode` functions to convert a Python dictionary containing nested data into a TOON string and then back into a Python dictionary. It showcases how `toonify` automatically uses a compact tabular format for uniform arrays.
Upgrade to `toonify` version 1.5.0 or newer. Ensure your data structures are well-formed and test round-trip conversions.
Evaluate your data structure; TOON provides significant savings for tabular data. For highly irregular data, traditional JSON might still be a suitable choice.
Always use `from toon import encode, decode` (or `encode_pydantic`, `decode_to_pydantic`) for the core serialization functions.
Verify the project description and import statements (`from toon import ...`) to confirm you are using the correct serialization library.
Ensure the library is installed in your active environment: `pip install toonify`. If using Pydantic, use `pip install toonify[pydantic]`.
Correct the import statement to `from toon import encode, decode` (or `encode_pydantic`, `decode_to_pydantic`) and use the functions directly, e.g., `encode(data)`.
Carefully review the TOON string for syntax errors, paying close attention to indentation, delimiters (comma, tab, pipe), and the correct format for object/array headers (e.g., `products[2]{sku,name,price}:`). Use a TOON linter if available or refer to the TOON specification.