Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

msgspec-toon

TOON (Token-Oriented Object Notation) is a line-oriented text format that reduces repeated keys in uniform JSON-shaped data.

msgspec is a high-performance serialization and validation library whose typed Struct objects are a faster, lighter alternative to Pydantic models.

msgspec-toon is a native TOON 4.1 codec for Python. It decodes TOON text directly into msgspec.Struct objects. It does not build an intermediate dict and list tree.

Use it when tabular data must fit in a language model context window, but the application still needs typed Python objects and fast in-process conversion.

This is a beta release. The project passes the pinned TOON 4.1.1 corpus, but it does not yet support every type that msgspec.json supports.

Install

Install the public beta from PyPI:

uv add msgspec-toon

The package requires Python 3.13 or newer. Its only runtime dependency is the exact pin msgspec==0.21.1. Benchmark codecs and tokenizers are optional development dependencies. They are not installed with the library.

Decode TOON into a Struct

import msgspec
import msgspec_toon as toon


class Metadata(msgspec.Struct, frozen=True):
    alias: str
    region: str


class Worker(msgspec.Struct, frozen=True):
    pid: int
    provider: str
    metadata: Metadata


class Document(msgspec.Struct, frozen=True):
    workers: list[Worker]


wire = b"""workers[2]{pid,provider,metadata{alias,region}}:
  9007199254740993,claude,worker-a,west
  80916,claude,worker-b,east"""

decoder = toon.Decoder(Document)
document = decoder.decode(wire)

assert isinstance(document, Document)
assert document.workers[0].pid == 9007199254740993
assert toon.encode(document) == wire

The parser uses the target type while it reads the input. It constructs the final Struct objects directly. The G2 allocation proof records zero temporary built-in dictionaries and lists for this path.

Read and write TOON files

The codec accepts bytes, bytearray, memoryview, or str. Encoding returns bytes, so normal Python file APIs work without an adapter.

from pathlib import Path

import msgspec_toon as toon


source = Path("workers.toon")
target = Path("workers-copy.toon")

decoder = toon.Decoder(Document)
encoder = toon.Encoder()

value = decoder.decode(source.read_bytes())
target.write_bytes(encoder.encode(value))

The conversion itself does not open files, sockets, or subprocesses. Your application controls all I/O.

Use untyped values

Omit type when you need normal Python dictionaries and lists:

value = toon.decode(b"name: ada\nactive: true")
wire = toon.encode(value)

The public surface follows msgspec.json where support exists:

  • encode and decode
  • reusable Encoder and Decoder
  • enc_hook and dec_hook
  • strict decoding by default
  • msgspec-compatible encode, decode, and validation errors

TOON wire options are explicit:

toon.encode(value, delimiter="\t", indent=1)
toon.decode(wire, indent_size=1)

The functional and reusable decoders both accept float_hook:

from decimal import Decimal

value = toon.decode(b"1.25", float_hook=Decimal)
decoder = toon.Decoder(float_hook=Decimal)

assert value == decoder.decode(b"1.25") == Decimal("1.25")

The encoder supports msgspec-native date, time, UUID, Decimal, and Enum values. It normalizes these values before it calls enc_hook. Decimal values keep all their digits and trailing zeroes.

from decimal import Decimal
from uuid import UUID

toon.encode(Decimal("1.2300"))
# b'"1.2300"'

toon.encode(Decimal("1.2300"), decimal_format="number")
# b'1.2300'

toon.encode(UUID("12345678-1234-5678-1234-567812345678"), uuid_format="hex")
# b'"12345678123456781234567812345678"'

The codec does not implement sorted or deterministic output. Both encoder entry points raise NotImplementedError for these order values. They never ignore an accepted option.

Typed decode supports recursive Structs, array-like Structs, object-form tagged Struct unions, and permissive scalar conversion. Tagged array-like unions fail during plan construction. Set strict=False to accept the same bool, integer, and float string conversions as msgspec 0.21.1. Strict mode stays the default.

Non-string mapping keys are intentionally rejected in 0.2.0b1. See the mapping-key policy.

Why not wrap another TOON codec?

A wrapper must first convert a Struct into built-in containers. Typed decode must parse a built-in tree and then call msgspec.convert. Those extra trees can cost more than the codec work.

Project Format target Typed msgspec path Integration model
msgspec-toon TOON 4.1.1 corpus Direct Struct encode and decode Native, in process
toon-rust TOON 3.0 No Python msgspec path Rust library and CLI
toons 0.7.0 Earlier TOON grammar Built-in tree Python Rust extension
python-toon 0.1.3 Earlier TOON grammar to_builtins / convert Pure Python and CLI

TOON 4 nested field groups are important. They let a uniform nested record use one tabular header:

workers[2]{pid,provider,metadata{alias,region}}:
  20324,claude,worker-a,west
  80916,claude,worker-b,east

Older encoders can fall back to a larger entry form for the same data.

Tokens and speed

Empirical speed-token Pareto set

The figure shows absolute end-to-end time against absolute o200k_base token count. Pareto status is calculated separately for each payload shape and record count. Lines connect the same implementation across record counts. They show workload scaling, not an unmeasured continuous Pareto curve.

The generated benchmark report also publishes the detailed axes:

  • Direct encode, decode, and total time for each measured codec.
  • Absolute token counts, including compact JSON, under tiktoken o200k_base.

The report crosses four payload shapes with four record counts. Canonical TOON uses more tokens than compact JSON for the measured irregular shapes.

All timing rows come from one session and one release build. The estimator is the mean across ten independent worker processes. It never reports the minimum. The raw evidence is in the conformance/report.json file.

Conformance and safety

  • All 538 pinned TOON 4.1.1 fixtures pass in both directions.
  • Typed decode creates no intermediate built-in container tree.
  • Integers keep Python precision and do not route through float.
  • Errors contain coordinates and static messages, never input payload text.
  • Malformed input must return an error. It must not panic or terminate Python.
  • Canonical output is byte-locked by tests.

The generated support matrix in the conformance/report.json file lists supported, rejected, and not-yet-supported msgspec features. Unsupported behavior fails clearly. It does not silently return a different value.

Optional msgspec Struct fast path

The stock package reads Struct fields through msgspec's public Python attributes. This is the compatible path for msgspec==0.21.1.

The repository also contains a versioned Struct-access capsule proposal for msgspec. You can build the same codec against that patch in an isolated environment:

make fastpath-build
make fastpath-check
make fastpath-bench
.venv-fastpath/bin/python

This workflow fetches a hash-pinned msgspec commit, applies the preserved patch, and builds both release wheels. It does not modify the normal .venv. The build fails unless the capsule path is active. Published wheels do not depend on the unreleased API.

Develop and reproduce

Use uv for all Python environment work:

uv sync --locked                         # library and developer tools
make build                              # release extension in .venv
make check                              # Rust and Python checks
make qualify                            # canonical release gate and evidence
uv run python conformance/run.py        # pinned 538-fixture corpus
make g2                                 # allocation proof in a separate build

uv sync --group bench --locked           # opt in to benchmark packages
make bench                              # same-run codec and typed ladders
make public-report                      # raw JSON, R charts, and BENCHMARKS.md

make public-report uses the host Rscript, ggplot2, jsonlite, and scales. It does not install R or add R packages to the Python environment. The release guide documents installed-artifact verification and Trusted Publishing.

License

MIT

Metadata

Release files for msgspec-toon 0.2.0b2

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

Source distribution (sdist)

Source distribution for msgspec-toon 0.2.0b2
File Size Uploaded
msgspec_toon-0.2.0b2.tar.gz 66.1 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for msgspec-toon 0.2.0b2
File
msgspec_toon-0.2.0b2-cp314-cp314t-win_arm64.whl CPython 3.14 CPython 3.14 free-threading Windows ARM64 Details
msgspec_toon-0.2.0b2-cp314-cp314t-win_amd64.whl CPython 3.14 CPython 3.14 free-threading Windows x86-64 Details
msgspec_toon-0.2.0b2-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.14 CPython 3.14 free-threading Linux glibc 2.17+ x86-64 Details
msgspec_toon-0.2.0b2-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.14 CPython 3.14 free-threading Linux glibc 2.17+ ARM64 Details
msgspec_toon-0.2.0b2-cp314-cp314t-macosx_11_0_arm64.whl CPython 3.14 CPython 3.14 free-threading macOS 11.0+ ARM64 Details
msgspec_toon-0.2.0b2-cp314-cp314t-macosx_10_12_x86_64.whl CPython 3.14 CPython 3.14 free-threading macOS 10.12+ x86-64 Details
msgspec_toon-0.2.0b2-cp313-abi3-win_arm64.whl CPython 3.13 abi3 Windows ARM64 Details
msgspec_toon-0.2.0b2-cp313-abi3-win_amd64.whl CPython 3.13 abi3 Windows x86-64 Details
msgspec_toon-0.2.0b2-cp313-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.13 abi3 Linux glibc 2.17+ x86-64 Details
msgspec_toon-0.2.0b2-cp313-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.13 abi3 Linux glibc 2.17+ ARM64 Details
msgspec_toon-0.2.0b2-cp313-abi3-macosx_11_0_arm64.whl CPython 3.13 abi3 macOS 11.0+ ARM64 Details
msgspec_toon-0.2.0b2-cp313-abi3-macosx_10_12_x86_64.whl CPython 3.13 abi3 macOS 10.12+ x86-64 Details

Total release size: 4.1 MB

Release files / msgspec_toon-0.2.0b2.tar.gz

Download URL msgspec_toon-0.2.0b2.tar.gz
Size 66.1 kB
Tags Source
SHA-256 checksum
How to use checksums
734ac6ae019e6aa6d92a4863f55ada1633defe8ebd3463f6eacddfbcb55b3bbc
BLAKE2b-256 checksum
How to use checksums
17fd41d69b37839208a310e89106ff4915869768b8bea9e36210d5dc4324d6ce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Aug 10, 2026.

Transparency log

Release files / msgspec_toon-0.2.0b2-cp314-cp314t-win_arm64.whl

Download URL msgspec_toon-0.2.0b2-cp314-cp314t-win_arm64.whl
Size 277.1 kB
Tags CPython 3.14 CPython 3.14 free-threading Windows ARM64
SHA-256 checksum
How to use checksums
ec22b9375ffc9f15079485715452ed2771a5126f2e3733c8741c54c0fdff4721
BLAKE2b-256 checksum
How to use checksums
7b4c98e4baaa5fc25f6764f2002c803748c82e10520b9a57b46ae24225f759d5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Aug 10, 2026.

Transparency log

Release files / msgspec_toon-0.2.0b2-cp314-cp314t-win_amd64.whl

Download URL msgspec_toon-0.2.0b2-cp314-cp314t-win_amd64.whl
Size 288.8 kB
Tags CPython 3.14 CPython 3.14 free-threading Windows x86-64
SHA-256 checksum
How to use checksums
cac3eb77616c142dd160011282cb3b4277d1f04706c345a4dd0b6d85e04e65dd
BLAKE2b-256 checksum
How to use checksums
70964d691e036702deaa19005b9fbba103e9fc15eb01c4620385086bcc73e270
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Aug 10, 2026.

Transparency log

Release files / msgspec_toon-0.2.0b2-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL msgspec_toon-0.2.0b2-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 381.5 kB
Tags CPython 3.14 CPython 3.14 free-threading Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
3cef2954ef4d393db5fbaa62f094cb349f59d5fe17eaaac413af9317056859f9
BLAKE2b-256 checksum
How to use checksums
1cc6b072ba95b030d7de8f58ba0871ee53237684c825e37c0bd3ef143a172e87
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Aug 10, 2026.

Transparency log

Release files / msgspec_toon-0.2.0b2-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL msgspec_toon-0.2.0b2-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 361.6 kB
Tags CPython 3.14 CPython 3.14 free-threading Linux glibc 2.17+ ARM64
SHA-256 checksum
How to use checksums
ad34ea408c23788f4dd4d95a1afb4634f135a18ddad257a40fbea988ed9adf38
BLAKE2b-256 checksum
How to use checksums
eee2fd3d99b01046cb3b11c805f5775e1c47e4c287282ae44f82c7519ed0ec0e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Aug 10, 2026.

Transparency log

Release files / msgspec_toon-0.2.0b2-cp314-cp314t-macosx_11_0_arm64.whl

Download URL msgspec_toon-0.2.0b2-cp314-cp314t-macosx_11_0_arm64.whl
Size 343.5 kB
Tags CPython 3.14 CPython 3.14 free-threading macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
1306af56dd64226c77e6851e2ee478a6bc7120255f8ce7ecb1aede68ade0270b
BLAKE2b-256 checksum
How to use checksums
b5ec834239da19910b19afd24395a4fc08e0dbe8550a897e7fd9686136e6f939
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Aug 10, 2026.

Transparency log

Release files / msgspec_toon-0.2.0b2-cp314-cp314t-macosx_10_12_x86_64.whl

Download URL msgspec_toon-0.2.0b2-cp314-cp314t-macosx_10_12_x86_64.whl
Size 361.6 kB
Tags CPython 3.14 CPython 3.14 free-threading macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
bacf7f3bc2d1e990e8df302b36b8d72590a4bd256f3f540297e334a20974ef58
BLAKE2b-256 checksum
How to use checksums
25db6db633c78e03eb08b1f5de9646f38b3f105c083e1ea26f8ec2a757f389ae
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Aug 10, 2026.

Transparency log

Release files / msgspec_toon-0.2.0b2-cp313-abi3-win_arm64.whl

Download URL msgspec_toon-0.2.0b2-cp313-abi3-win_arm64.whl
Size 277.0 kB
Tags CPython 3.13 Windows ARM64 abi3
SHA-256 checksum
How to use checksums
e9394c2d77672a768d7751c5590e7760904e34a73e1b4da96ca7ca529ac9907c
BLAKE2b-256 checksum
How to use checksums
cfe5e7a69c8aeb96850043486d3d49d76f65483c156fa42983972f3e1442eab6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Aug 10, 2026.

Transparency log

Release files / msgspec_toon-0.2.0b2-cp313-abi3-win_amd64.whl

Download URL msgspec_toon-0.2.0b2-cp313-abi3-win_amd64.whl
Size 288.5 kB
Tags CPython 3.13 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
94d29926581b861e5cbb0983a185e93102fe5ad74eca5927ad35fb23951c6cd0
BLAKE2b-256 checksum
How to use checksums
e8454664c53f44ea17cb2f14f2fe7234cfb54969263aa754dd58ce410f770a38
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Aug 10, 2026.

Transparency log

Release files / msgspec_toon-0.2.0b2-cp313-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL msgspec_toon-0.2.0b2-cp313-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 380.9 kB
Tags CPython 3.13 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
d169c4a379b48a6d9e071f7a1aedcb86c0e7b2a95c9411d1276722e3dd8902dd
BLAKE2b-256 checksum
How to use checksums
3daea5ee4af143679829eea84bd5df1efdf55ef2d76e4674da10d82c282e4337
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Aug 10, 2026.

Transparency log

Release files / msgspec_toon-0.2.0b2-cp313-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL msgspec_toon-0.2.0b2-cp313-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 362.0 kB
Tags CPython 3.13 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
47f885b2fa65757e998971037e30083b1a8f8461fee4875e041d0be86e15028a
BLAKE2b-256 checksum
How to use checksums
815c89c2af6b2bfb00fb8bf63415bfb2e99f8ef4aa7577707db3394f71d4d26e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Aug 10, 2026.

Transparency log

Release files / msgspec_toon-0.2.0b2-cp313-abi3-macosx_11_0_arm64.whl

Download URL msgspec_toon-0.2.0b2-cp313-abi3-macosx_11_0_arm64.whl
Size 343.9 kB
Tags CPython 3.13 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
96f1997dc9056d67bf3f68bb7a1ad8199f9f678a81a088ffd9567549739f1cef
BLAKE2b-256 checksum
How to use checksums
6be822fe73ae33b8cda7ba3066f3d1d7fa549082825540bdbb7f86fcaaa23ce0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Aug 10, 2026.

Transparency log

Release files / msgspec_toon-0.2.0b2-cp313-abi3-macosx_10_12_x86_64.whl

Download URL msgspec_toon-0.2.0b2-cp313-abi3-macosx_10_12_x86_64.whl
Size 362.0 kB
Tags CPython 3.13 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
c17d81176d046cc259dfc57b021be8e8d05bbd7b112ac44afff66b295fcc204f
BLAKE2b-256 checksum
How to use checksums
a85bd3bc397b4b41a3b3b65c6ef9d4551a402ef0ea4bce1ef2669f79ae1416df
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Aug 10, 2026.

Transparency log
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