Skip to main content

toon_serializer: Token Oriented Object Notation for Python

toon_serializer is a high performance Python serializer/deserializer for TOON (Token Oriented Object Notation).

TOON is a human readable data format designed to minimize token usage for LLMs by removing redundant syntax (braces, quotes, repeated keys) while maintaining structure. It excels at compressing list of dictionaries into Tabular Arrays, often reducing payload sizes by 30-50% compared to JSON.

Features

  • 📉 Token Efficient Replaces repetitive JSON keys with compact CSV-like headers.
  • 🧠 Adaptive Schema The decoder "learns" column types from the first row to parse massive tables instantly.
  • ⚡ Fast Primitives Optimized integer, float, and boolean parsing.
  • csv-compatible Handles complex string escaping and quoting automatically.
  • Lazy Decoding Iterates over lines lazily, efficient for large datasets.

Installation

pip install toon_serializer

Usage

toon_serializery mimics the standard Python json API with loads and dumps.

  1. Encoding Data (Serialization)

toon_serializer automatically detects Uniform Lists of Dictionaries and compresses them into a tabular format.

Input

import toon_serializer

data = {
    "model": "gpt-4",
    "parameters": {
        "temperature": 0.7,
        "stream": True
    },
    "messages": [
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Explain quantum physics."},
        {"role": "assistant", "content": "Quantum physics studies..."}
    ]
}

toon_str = toon_serializer.dumps(data)
print(toon_str)

Output:

model: gpt-4
parameters:
  temperature: 0.7
  stream: true
messages[3]{role,content}:
  system,"You are a helpful assistant."
  user,"Explain quantum physics."
  assistant,"Quantum physics studies..."
  1. Decoding Data (Deserialization)

The decoder handles primitives, standard lists, and adaptive tabular arrays seamlessly.

import toon_serializer

toon_str = """
version: 1.0
users[2]{id,name,is_active}:
  1,Alice,true
  2,Bob,false
tags[3]: python, rust, go
"""

data = toon_serializer.loads(toon_str)

print(data["users"][0]) 
# {'id': 1, 'name': 'Alice', 'is_active': True}

print(data["tags"])
# ['python', 'rust', 'go']

Performance Notes

  • Encoder recursively checks for "uniformity" in lists. If a list contains mixed types, it gracefully falls back to a standard bulleted list.
  • Decoder uses a Pushback Iterator to parse line-by-line without loading the entire string into memory.
  • Adaptive Parsing when decoding tables, toon_serializer inspects the first row to generate a specialized converter function (e.g., "Column 1 is int, Column 2 is string"), speeding up parsing for the remaining rows.

Contributing

  1. Fork the repository.
  2. Create a feature branch.
  3. Add tests.
  4. Submit a Pull Request.

Metadata

Release files for toon_serializer 1.0.0

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

Source distribution (sdist)

Source distribution for toon_serializer 1.0.0
File Size Uploaded
toon_serializer-1.0.0.tar.gz 40.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for toon_serializer 1.0.0
File Interpreter ABI Platform
toon_serializer-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 52.9 kB

Release files / toon_serializer-1.0.0.tar.gz

Download URL toon_serializer-1.0.0.tar.gz
Size 40.9 kB
Tags Source
SHA-256 checksum
How to use checksums
8928a25f618558fa58a6651de9b0438257bf4568ca3c5d0967684be61505069b
BLAKE2b-256 checksum
How to use checksums
194b3ad0e56886fa207ac0d12c1ff9e1b6e43d364302b6dea8ed7c5c2b3334e3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.7

Release files / toon_serializer-1.0.0-py3-none-any.whl

Download URL toon_serializer-1.0.0-py3-none-any.whl
Size 12.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7e27e7f6b766758472ce4b8a019fa3ea6dc6277e8fbf9ea0a00ede76ee502af3
BLAKE2b-256 checksum
How to use checksums
139be643daf0ae261ac0b445b5f98c6afc3d29c5efba4fb56654f9db7240ad93
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.7

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

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