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

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.2.0b1

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.0b1
File Size Uploaded
msgspec_toon-0.2.0b1.tar.gz 65.9 kB Details

Built distributions (wheels)

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

Download URL msgspec_toon-0.2.0b1.tar.gz
Size 65.9 kB
Tags Source
SHA-256 checksum
How to use checksums
69ef41a9afca5395cb630f9a290ab3bb72ea171dca3fedd4761143d47deca9c3
BLAKE2b-256 checksum
How to use checksums
e7ab3df0e31a03e39f437cd9345c96263d92f71abcd37cdc540a292edbfcdf9c
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.0b1-cp314-cp314t-win_arm64.whl

Download URL msgspec_toon-0.2.0b1-cp314-cp314t-win_arm64.whl
Size 277.0 kB
Tags CPython 3.14 CPython 3.14 free-threading Windows ARM64
SHA-256 checksum
How to use checksums
0c4ae4dc720e30d241f03ec7a03b2dd616962e6d614a5c728c26870d6d2b3d36
BLAKE2b-256 checksum
How to use checksums
02228440f8824523d0b5b00ddb6981fdfdbda4da7c521c584021b02536c4f758
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.0b1-cp314-cp314t-win_amd64.whl

Download URL msgspec_toon-0.2.0b1-cp314-cp314t-win_amd64.whl
Size 288.7 kB
Tags CPython 3.14 CPython 3.14 free-threading Windows x86-64
SHA-256 checksum
How to use checksums
c64a7e2fd698781237eff2fad1d11e511a7be49ee0099dc107eaf5dd4aeb6e4c
BLAKE2b-256 checksum
How to use checksums
d8b7cb30eb69330577b0a9e3fb367b42fc9c5d60e970c8643a94137fcfc18a18
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.0b1-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL msgspec_toon-0.2.0b1-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 381.6 kB
Tags CPython 3.14 CPython 3.14 free-threading Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
7996b31264bb43442336cf696289ec761c62b0e3427cb8ed2ff801abb48b85a8
BLAKE2b-256 checksum
How to use checksums
4be33d4c6ccffc1e23715480b9d42f5272ef9d168cb0544c956ea87f4cb687f2
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.0b1-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL msgspec_toon-0.2.0b1-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 361.5 kB
Tags CPython 3.14 CPython 3.14 free-threading Linux glibc 2.17+ ARM64
SHA-256 checksum
How to use checksums
27fdf9acc8f78e88c0b582b3cc868a6042a1ea30fa25298b2a015854ab85e5e6
BLAKE2b-256 checksum
How to use checksums
1513200ec350d0f17e2a872f50cfbb32018f664f9d5db4bac66bd856ac6bfb06
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.0b1-cp314-cp314t-macosx_11_0_arm64.whl

Download URL msgspec_toon-0.2.0b1-cp314-cp314t-macosx_11_0_arm64.whl
Size 343.4 kB
Tags CPython 3.14 CPython 3.14 free-threading macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
e4485c7a79ee33286554eee860926e4ab2baa9af0d36a7e9816412221fb53fbf
BLAKE2b-256 checksum
How to use checksums
0a05ce0f71d725744b533d255eb24205b51e6c24be2d75f1492e37f2db74634f
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.0b1-cp314-cp314t-macosx_10_12_x86_64.whl

Download URL msgspec_toon-0.2.0b1-cp314-cp314t-macosx_10_12_x86_64.whl
Size 361.5 kB
Tags CPython 3.14 CPython 3.14 free-threading macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
7db9aad662af25b690d8bfdb97e01559719f6cbbedc17057169663995c82ff31
BLAKE2b-256 checksum
How to use checksums
788f8559f08d0b9be36f4e046e80ab16ecc40a8e6a157fd00142483b4ff29c70
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.0b1-cp313-abi3-win_arm64.whl

Download URL msgspec_toon-0.2.0b1-cp313-abi3-win_arm64.whl
Size 276.9 kB
Tags CPython 3.13 Windows ARM64 abi3
SHA-256 checksum
How to use checksums
15b21b25dc69cebf1a84d73331d9bd760d69d1b39fe6c008aeeaa3e1b9bc37a5
BLAKE2b-256 checksum
How to use checksums
279b5fb5b954fbb62dd94f1a9802653c2a85c53a8313458f7e680f24cc132978
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.0b1-cp313-abi3-win_amd64.whl

Download URL msgspec_toon-0.2.0b1-cp313-abi3-win_amd64.whl
Size 288.4 kB
Tags CPython 3.13 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
e1f702fabeb054e6985a9552b30df54d901353d2d59799ba03d134925caf6373
BLAKE2b-256 checksum
How to use checksums
18d5b932c5ce50a164fe87b64408a43893ee01c4c3c3c5b0c34376dec01a0cb6
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.0b1-cp313-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL msgspec_toon-0.2.0b1-cp313-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 381.0 kB
Tags CPython 3.13 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
e660a162cd88dcaabd9f2897d3531b4cdef9cd9fd9b8736d93f010508070c4cc
BLAKE2b-256 checksum
How to use checksums
dab555e9a6cb0aaed3789bd8dc57fb23c14a243a5b7aaf466c5225cbd186d884
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.0b1-cp313-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL msgspec_toon-0.2.0b1-cp313-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 361.9 kB
Tags CPython 3.13 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
401c8a4cca14a098d8625a05e5a853a8ed6628b90b19174396026c6e53f09252
BLAKE2b-256 checksum
How to use checksums
a199ddfaf2bcde587fd3d49d195d2d8e80693590ccba9a94bb31bdd7368e22df
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.0b1-cp313-abi3-macosx_11_0_arm64.whl

Download URL msgspec_toon-0.2.0b1-cp313-abi3-macosx_11_0_arm64.whl
Size 343.8 kB
Tags CPython 3.13 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
23899a0b286e2218e53a58da61713770c1941501aeff5290f7c5a9fbcbc10e69
BLAKE2b-256 checksum
How to use checksums
ec3fe1a3ebfc0857441638daf361644ce5fe2effa650dfdb14301fcf8c374738
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.0b1-cp313-abi3-macosx_10_12_x86_64.whl

Download URL msgspec_toon-0.2.0b1-cp313-abi3-macosx_10_12_x86_64.whl
Size 361.9 kB
Tags CPython 3.13 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
5b8c55eab6952b37112e7447e82c1cfac5359d45d41a4b6e1cf9e28be0bf885a
BLAKE2b-256 checksum
How to use checksums
d6e81d3f5f3ad82b499feb204ca8d9fe375a37fd1587106ca79ec7d53e636f37
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