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)

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

Codec elapsed times

Absolute token counts

The generated benchmark report publishes both 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.1.0b3

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.1.0b3
File Size Uploaded
msgspec_toon-0.1.0b3.tar.gz 57.6 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for msgspec-toon 0.1.0b3
File
msgspec_toon-0.1.0b3-cp314-cp314t-win_arm64.whl CPython 3.14 CPython 3.14 free-threading Windows ARM64 Details
msgspec_toon-0.1.0b3-cp314-cp314t-win_amd64.whl CPython 3.14 CPython 3.14 free-threading Windows x86-64 Details
msgspec_toon-0.1.0b3-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.1.0b3-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.1.0b3-cp314-cp314t-macosx_11_0_arm64.whl CPython 3.14 CPython 3.14 free-threading macOS 11.0+ ARM64 Details
msgspec_toon-0.1.0b3-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.1.0b3-cp313-abi3-win_arm64.whl CPython 3.13 abi3 Windows ARM64 Details
msgspec_toon-0.1.0b3-cp313-abi3-win_amd64.whl CPython 3.13 abi3 Windows x86-64 Details
msgspec_toon-0.1.0b3-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.1.0b3-cp313-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.13 abi3 Linux glibc 2.17+ ARM64 Details
msgspec_toon-0.1.0b3-cp313-abi3-macosx_11_0_arm64.whl CPython 3.13 abi3 macOS 11.0+ ARM64 Details
msgspec_toon-0.1.0b3-cp313-abi3-macosx_10_12_x86_64.whl CPython 3.13 abi3 macOS 10.12+ x86-64 Details

Total release size: 3.8 MB

Release files / msgspec_toon-0.1.0b3.tar.gz

Download URL msgspec_toon-0.1.0b3.tar.gz
Size 57.6 kB
Tags Source
SHA-256 checksum
How to use checksums
79cab68a6fea933c5f781a8ae013e117d6be644f2f0be24e85a67a93772d1f15
BLAKE2b-256 checksum
How to use checksums
995275f889b4b8e3b59aa7d84e65bf9a2b583e8d800f9ee8ddce37cb2179b10b
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 9, 2026.

Transparency log

Release files / msgspec_toon-0.1.0b3-cp314-cp314t-win_arm64.whl

Download URL msgspec_toon-0.1.0b3-cp314-cp314t-win_arm64.whl
Size 252.2 kB
Tags CPython 3.14 CPython 3.14 free-threading Windows ARM64
SHA-256 checksum
How to use checksums
fdb98004d6ba2df5ae414a5d9c0f19914a6e90494248d799555014687bf1af92
BLAKE2b-256 checksum
How to use checksums
56e45c9b5b530ea111e5cc5c2964ca99133936a632a3cabe0d43d34bb461dfce
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 9, 2026.

Transparency log

Release files / msgspec_toon-0.1.0b3-cp314-cp314t-win_amd64.whl

Download URL msgspec_toon-0.1.0b3-cp314-cp314t-win_amd64.whl
Size 261.8 kB
Tags CPython 3.14 CPython 3.14 free-threading Windows x86-64
SHA-256 checksum
How to use checksums
b3147cddff5887d15133d0c4025f27e13cf700e96d5cf6cc378fabf59c6d90ff
BLAKE2b-256 checksum
How to use checksums
3d31bad7557315894637f9c014ebd7ddd67d01d099218a153e5ed95b91510f78
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 9, 2026.

Transparency log

Release files / msgspec_toon-0.1.0b3-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL msgspec_toon-0.1.0b3-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 354.6 kB
Tags CPython 3.14 CPython 3.14 free-threading Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
c8421a1823e5793c7a6aa5867c6bfdbc9d7f5221d34cd4d4d9f0eacdf84d462e
BLAKE2b-256 checksum
How to use checksums
6541c7703bc0560a99696a209cdeeef7745a1e500a3bf3dd58e877c6c1940ef6
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 9, 2026.

Transparency log

Release files / msgspec_toon-0.1.0b3-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL msgspec_toon-0.1.0b3-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 338.2 kB
Tags CPython 3.14 CPython 3.14 free-threading Linux glibc 2.17+ ARM64
SHA-256 checksum
How to use checksums
477fca1e66fe315d367050895316cad18efadeee7cdf9e4a291ed762157211de
BLAKE2b-256 checksum
How to use checksums
e9f7261f3976b9fbfb7b11a7990de2b90697ee2c9f64ea34cfe608ff7bca52f4
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 9, 2026.

Transparency log

Release files / msgspec_toon-0.1.0b3-cp314-cp314t-macosx_11_0_arm64.whl

Download URL msgspec_toon-0.1.0b3-cp314-cp314t-macosx_11_0_arm64.whl
Size 320.2 kB
Tags CPython 3.14 CPython 3.14 free-threading macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
e705b7cde857a7a34ebfc8514c810a4d6f23ebad402540b3f95dffda6f2bd264
BLAKE2b-256 checksum
How to use checksums
609d7de7488f33216f0f5f2c2d15e7ab9e4a6b8f920ec2038d9f91661bb2aed6
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 9, 2026.

Transparency log

Release files / msgspec_toon-0.1.0b3-cp314-cp314t-macosx_10_12_x86_64.whl

Download URL msgspec_toon-0.1.0b3-cp314-cp314t-macosx_10_12_x86_64.whl
Size 334.7 kB
Tags CPython 3.14 CPython 3.14 free-threading macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
4d1d7b61172402078061644cfa1bf50e6868654ce86fa6ee3763ad55519438a7
BLAKE2b-256 checksum
How to use checksums
0f31cb56f83387c3539bf5eaba6a2a8a4fbc7f80566d49f9444726bee2df7f5d
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 9, 2026.

Transparency log

Release files / msgspec_toon-0.1.0b3-cp313-abi3-win_arm64.whl

Download URL msgspec_toon-0.1.0b3-cp313-abi3-win_arm64.whl
Size 252.6 kB
Tags CPython 3.13 Windows ARM64 abi3
SHA-256 checksum
How to use checksums
68c5c2d59d83259776b36f505f2b89f40fa3d4393a69cadb868da373d958ad45
BLAKE2b-256 checksum
How to use checksums
55e7833ddcbc84da1b5474c97d5c8f26209540f68469ea61c7c74ef2421a15fd
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 9, 2026.

Transparency log

Release files / msgspec_toon-0.1.0b3-cp313-abi3-win_amd64.whl

Download URL msgspec_toon-0.1.0b3-cp313-abi3-win_amd64.whl
Size 261.9 kB
Tags CPython 3.13 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
c96c76bd20babe746f222dd5d7aa47edd585d9b691783c3471b863630f481f74
BLAKE2b-256 checksum
How to use checksums
8728e4ad8c6589aa5be2252c73c6b48e848417c86f80f7f5c4017b1808d67fe9
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 9, 2026.

Transparency log

Release files / msgspec_toon-0.1.0b3-cp313-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL msgspec_toon-0.1.0b3-cp313-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 354.5 kB
Tags CPython 3.13 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
9ec307e2fbf3266347de8d0015316de9e3fdcd34019d72b44add2df22ea17337
BLAKE2b-256 checksum
How to use checksums
020f9ec45c98d882d7f7f54727f04d82bb76d55ac7a4a990a1837655c53b0f41
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 9, 2026.

Transparency log

Release files / msgspec_toon-0.1.0b3-cp313-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL msgspec_toon-0.1.0b3-cp313-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 338.6 kB
Tags CPython 3.13 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
05c14deb6a448cd6a878ca5d34305aadd8addb729f595d41dfd8bc205d198fa5
BLAKE2b-256 checksum
How to use checksums
2d091c3b9f8af93827efa7ed85c69ed6a2622e02d9389572e757bfde0c5b9f4e
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 9, 2026.

Transparency log

Release files / msgspec_toon-0.1.0b3-cp313-abi3-macosx_11_0_arm64.whl

Download URL msgspec_toon-0.1.0b3-cp313-abi3-macosx_11_0_arm64.whl
Size 320.7 kB
Tags CPython 3.13 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
12ce1b4ca1cc67a9af895e3b91fafd4324eee0c96d68c0d251be9868c7e1b00d
BLAKE2b-256 checksum
How to use checksums
e682d5d18d4b70769893e5a6fd60b5211ec1f2bb74ae84db445fae716f8f5c64
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 9, 2026.

Transparency log

Release files / msgspec_toon-0.1.0b3-cp313-abi3-macosx_10_12_x86_64.whl

Download URL msgspec_toon-0.1.0b3-cp313-abi3-macosx_10_12_x86_64.whl
Size 335.0 kB
Tags CPython 3.13 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
4f74e732d6bc919404e9ffc06b34beda638c60d8f28439ac2edc12785000bb4c
BLAKE2b-256 checksum
How to use checksums
d36e2ce27ecac1ac20b53375e2fe4fd948ab07ff3cf96f9e1e7ce4fcf5581f35
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 9, 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