datoon
smart structured-data→TOON gateway — converts only when it actually saves tokens
Before/After • Install • What You Get • How It Works • Benchmarks • Full install guide
Raw structured data is often verbose in LLM prompts. TOON can save tokens — but blind conversion can also make payloads worse. datoon adds a decision layer: convert when structure and savings justify it, skip when they don't, and always explain why.
Supports JSON, CSV, JSONL, YAML, XML, Parquet, Avro, ORC, Excel, and Apple Numbers — auto-detected from file extension.
Before / After
Same data. Right format. Always explained.
Token counts on this page come from tiktoken:o200k_base. Three rows barely clear the 15% threshold; savings grow with the table. Uniform payloads in the benchmarks save 22–28%, and 100–300-row query results cost Claude about half the input tokens of JSON objects.
Install
# core (JSON, CSV, JSONL, XML — no extra deps)
uv add datoon
pip install datoon
# with YAML support
pip install "datoon[yaml]"
# with Excel support
pip install "datoon[excel]"
# with Parquet / ORC / Avro support
pip install "datoon[columnar]"
# with Apple Numbers support
pip install "datoon[numbers]"
# with tiktoken-based token counting
pip install "datoon[tokens]"
# with Claude token counting (Anthropic API) / Hugging Face tokenizers
pip install "datoon[claude]"
pip install "datoon[hf]"
# everything
pip install "datoon[all]"
Requires Python 3.12+. TOON conversion is pure Python (official toon-format encoder, installed automatically) — no Node.js needed.
For the Claude Code plugin and Codex → INSTALL.md.
What You Get
| What | |
|---|---|
datoon CLI |
Auto-gate any supported format → TOON from terminal or scripts |
| Python API | convert_json_for_llm(), convert_data_for_llm() + read_tabular() for any LLM pipeline |
| Claude Code Plugin | /datoon in-session trigger, installs from GitHub in one command |
| Codex Plugin | Marketplace plugin — structured-data mode for Codex |
Supported input formats
| Format | Extension | Extra needed |
|---|---|---|
| JSON | .json |
— |
| JSONL | .jsonl, .ndjson |
— |
| CSV | .csv |
— |
| XML | .xml |
— |
| YAML | .yaml, .yml |
datoon[yaml] |
| Excel | .xlsx, .xls |
datoon[excel] |
| Parquet | .parquet |
datoon[columnar] |
| Avro | .avro |
datoon[columnar] |
| ORC | .orc |
datoon[columnar] |
| Apple Numbers | .numbers |
datoon[numbers] |
How It Works
- Detect format — from
--formatflag, file extension, or default to JSON for stdin - Read + normalize — parse source into list of row dicts; serialize to compact JSON
- Analyze structure — uniform object arrays? acceptable depth? minimum rows?
- Gate early — non-candidates skip before any TOON encoding
- Convert + estimate — TOON encoder runs in-process, token savings calculated
- Gate savings — below threshold → return JSON; above → return TOON with report
Every path returns a ConversionReport with decision, reason, token estimates, and the tokenizer that produced them. Pipelines never get silent surprises.
Choosing a tokenizer
Token estimates drive the savings gate, so pick the counter that fits the job. Pass one spec with --tokenizer, ConversionConfig(tokenizer=...), or the DATOON_TOKENIZER environment variable; in Python any callable str -> int works too.
| Spec | Counts with | Needs |
|---|---|---|
auto (default) |
tiktoken:o200k_base when tiktoken is installed, else chars:3 |
— |
chars / chars:<N> |
ceil(len(text) / N), default N = 3 |
— |
tiktoken / tiktoken:<encoding> |
tiktoken, default o200k_base |
datoon[tokens] |
claude:<model-id> |
Anthropic token counting API for that model | datoon[claude], Anthropic credentials (e.g. ANTHROPIC_API_KEY) |
hf:<repo-id> |
Hugging Face tokenizers tokenizer from the Hub |
datoon[hf] |
| a callable (Python) | your own function, reported as custom |
— |
Use the local counters (auto, chars, tiktoken) to gate payloads at runtime: they are fast and run locally (tiktoken fetches its encoding file once on first use). Use claude: or hf: in benchmarks and evals where counts for the target model matter. claude: makes network calls, and Anthropic documents its counts as estimates. Only auto falls back silently: an explicit spec with a missing package fails with an error that names the extra to install, and claude: without Anthropic credentials fails too. Every report records the resolved name in tokenizer.
Quick Start
JSON (stdin):
echo '{"users":[{"id":1,"name":"Ada"},{"id":2,"name":"Lin"},{"id":3,"name":"Grace"}]}' | datoon --report-stdout
CSV (auto-detected from extension):
datoon data.csv --report-stdout
JSONL:
datoon data.jsonl -o output.toon
YAML (requires datoon[yaml]):
datoon data.yaml --report-stdout
Parquet (requires datoon[columnar]):
datoon data.parquet --report ./report.json
Explicit format override:
datoon --format csv < data.csv --report-stdout
Force conversion (bypass gating — for experiments):
datoon data.json --force --report-stdout
Python API
JSON conversion:
from datoon import convert_json_for_llm, ConversionConfig, DatoonError
config = ConversionConfig(min_savings_ratio=0.15, max_depth=6, min_uniform_rows=3)
try:
outcome = convert_json_for_llm(raw_json, config)
except DatoonError as exc:
raise
# outcome.payload_text — TOON or original JSON
# outcome.report.decision — "convert" | "skip"
# outcome.report.reason — human-readable explanation
send_to_model(outcome.payload_text)
Any format via read_tabular:
from pathlib import Path
from datoon import read_tabular, convert_data_for_llm
# text formats: csv, jsonl, yaml, xml
rows = read_tabular("csv", text=csv_string)
# binary formats: excel, parquet, orc, avro, numbers
rows = read_tabular("parquet", path=Path("data.parquet"))
# takes Python data directly; dates, decimals and bytes are serialised for you
outcome = convert_data_for_llm(rows)
send_to_model(outcome.payload_text)
Structure-only analysis:
from datoon.analyzer import analyze_payload
from datoon.models import ConversionConfig
analysis = analyze_payload(parsed_data, ConversionConfig())
print(analysis.is_candidate, analysis.reason)
Claude Code Plugin
Install directly from GitHub:
claude plugin marketplace add andrii-su/datoon
claude plugin install datoon@datoon
Trigger in-session:
/datoon
convert this JSON to TOON if it saves tokens
use datoon mode for structured data
CLI Reference
| Flag | Default | Description |
|---|---|---|
--format |
auto | Input format: json, csv, jsonl, yaml, xml, excel, parquet, avro, orc, numbers |
--force |
false |
Bypass gating and minimum savings threshold |
--min-savings |
0.15 |
Minimum relative token savings required |
--max-depth |
6 |
Maximum nesting depth for auto-conversion |
--min-uniform-rows |
3 |
Minimum rows in uniform object arrays |
--sheet |
0 |
Worksheet index for Excel / Numbers input |
--table |
0 |
Table index within a Numbers sheet |
--tokenizer <spec> |
$DATOON_TOKENIZER, else auto |
Token counter for estimates — see Choosing a tokenizer |
--report <path> |
— | Write JSON conversion report to file |
--report-stdout |
— | Print JSON conversion report to stderr |
-o <path> |
stdout | Output file path |
--version |
— | Print version and exit |
Format is auto-detected from file extension. Use --format to override or when reading from stdin.
Benchmarks
PYTHONPATH=src python benchmarks/run.py --dry-run
PYTHONPATH=src python benchmarks/run.py --tokenizer tiktoken
PYTHONPATH=src python benchmarks/run.py --formats --tokenizer tiktoken --update-readme
Both tables below are counted with tiktoken:o200k_base. The chars counter is a length heuristic and reports larger savings on the same payloads.
Auto mode against forced conversion
Forced conversion makes two of the five payloads larger (orders-nested, mixed-non-uniform). Auto mode skips those two, converts the other three, and returns a reason for every decision.
| Dataset | JSON | TOON (forced) | Raw Saved | Auto | Auto Tokens | Auto Saved |
|---|---|---|---|---|---|---|
| users-small | 54 | 40 | 25.9% | convert | 40 | 25.9% |
| events-medium | 219 | 162 | 26.0% | convert | 162 | 26.0% |
| orders-nested | 106 | 116 | -9.4% | skip | 106 | 0.0% |
| mixed-non-uniform | 35 | 47 | -34.3% | skip | 35 | 0.0% |
| metrics-wide | 142 | 103 | 27.5% | convert | 103 | 27.5% |
| Average | 111 | 94 | 7.1% | 3/5 convert | 89 | 15.9% |
Forced conversion succeeded for 5/5 payloads.
Format conversion benchmark
Token savings when converting from common structured formats (CSV, JSONL, XML, YAML). Baseline is the JSON representation of the same data — what an LLM would receive without datoon.
| Dataset | Format | JSON Tokens | TOON (forced) | Auto | Auto Tokens | Auto Saved |
|---|---|---|---|---|---|---|
| users-csv | csv | 51 | 39 | convert | 39 | 23.5% |
| events-jsonl | jsonl | 216 | 161 | convert | 161 | 25.5% |
| catalog-xml | xml | 94 | 73 | convert | 73 | 22.3% |
| metrics-yaml | yaml | 139 | 102 | convert | 102 | 26.6% |
| Average | — | 125 | 94 | 4/4 convert | 94 | 24.5% |
Forced conversion succeeded for 4/4 payloads.
Reading accuracy
Fewer tokens only help if the model still reads the data correctly. benchmarks/format_eval/ gives a Claude model the same query result as JSON objects, a markdown table and TOON, then asks six questions per table with answers computed in Python (row count, cell lookup, filtered count, maximum, difference, NULL count).
24 synthetic tables of 100–300 rows and 4–30 columns, one API call per table and format. Input tokens are real API usage.
| Model | Format | Correct answers | 95% interval | Input tokens vs JSON objects |
|---|---|---|---|---|
| Claude Sonnet 5.5 | JSON objects | 142/144 (98.6%) | 95.1–99.6% | 100% |
| Claude Sonnet 5.5 | markdown | 142/144 (98.6%) | 95.1–99.6% | 60% |
| Claude Sonnet 5.5 | TOON | 143/144 (99.3%) | 96.2–99.9% | 50% |
| Claude Haiku 5.5 | JSON objects | 134/144 (93.1%) | 87.7–96.2% | 100% |
| Claude Haiku 5.5 | markdown | 136/144 (94.4%) | 89.4–97.2% | 60% |
| Claude Haiku 5.5 | TOON | 130/138 (94.2%) | 89.0–97.0% | 50% |
The intervals overlap: these runs show no accuracy difference between formats, and TOON halves the input tokens. One Haiku TOON reply was cut off at the output limit, so its six answers are not graded. Sonnet is close to the ceiling on this set, so a 1–2 point gap between formats would go unseen.
An earlier with-skill / without-skill agent comparison is kept in benchmarks/agent_skill_eval/; its token figures predate the selectable tokenizers.
Development
Contributor workflow: CONTRIBUTING.md. Maintainer/agent notes: CLAUDE.md.
Setup:
uv sync --extra dev
uvx pre-commit install
Tests:
pytest
Skill sync + plugin metadata:
python scripts/validate_skill_sync.py
python scripts/validate_plugin_metadata.py
Links
- INSTALL.md — full install matrix, all targets, per-agent detail
- CONTRIBUTING.md — contributor workflow
- CLAUDE.md — maintainer guide for agents
- CHANGELOG.md — release history
- SECURITY.md — vulnerability reporting
- Live docs —
docs/ - Issues — bugs, features, questions
License
MIT
Metadata
Release files for datoon 3.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| datoon-3.1.0.tar.gz | 232.8 kB | With provenance | Details for datoon-3.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| datoon-3.1.0-py3-none-any.whl | Python 3 | none | any | Details for datoon-3.1.0-py3-none-any.whl |
Total release size: 262.2 kB
Release files / datoon-3.1.0.tar.gz
| Download URL | datoon-3.1.0.tar.gz |
|---|---|
| Size | 232.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c7c06ecd6a20cef79f59ea34102fac745f91200e3cb1080bddcce93d469b92cf
|
|
BLAKE2b-256 checksum How to use checksums |
5eb21c3ca7a9d3c092b326e8341c547136520ab4cbde280e6b8b8ab8fced954f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 12, 2026.
Transparency logRelease files / datoon-3.1.0-py3-none-any.whl
| Download URL | datoon-3.1.0-py3-none-any.whl |
|---|---|
| Size | 29.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d0443f7f27348ca6e87fdfbbe6ce0f7c9306150edb6129f2a020dd459389a5a2
|
|
BLAKE2b-256 checksum How to use checksums |
78846efd40cab926dbca5bc7db320956c7b23486b024033a0a50db78bb9c0fe5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 12, 2026.
Transparency logSecurity for datoon 3.1.0
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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for datoon-3.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 12, 2026.
Transparency logA 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.