Python port of the TOON encoder, producing a concise, human-readable data format.
Project description
PyTOON
PyTOON is a Python port of the excellent toon project by Johann Schopplich. It converts arbitrary Python data structures into the same concise, human-readable text representation produced by the original TypeScript encoder.
The goal of this repository is feature parity with the source project while offering a first-class experience for Python applications and tooling.
Features
- Normalises native Python types (dicts, lists, dataclasses, sets,
datetime, numeric edge cases, etc.) to a JSON-like value space before encoding. - Produces the familiar Toon text format with support for inline arrays, tabular object arrays, and deeply nested structures.
- Configurable indentation, row delimiter (
',','|','\t'), and optional length marker flag ([#N]style headers). - Safe string quoting and escaping rules that match the upstream implementation.
- Lightweight dependency-free package targeting Python 3.8+.
Installation
pip install pytoon
If you are working from this repository, install it in editable mode:
pip install -e .
Quick Start
from pytoon import encode
payload = {
"user": {
"id": 123,
"name": "Ada",
"tags": ["reading", "gaming"],
"active": True,
"prefs": [],
}
}
print(encode(payload))
Output:
user:
id: 123
name: Ada
tags[2]: reading,gaming
active: true
prefs[0]:
Options
encode accepts an optional EncodeOptions dictionary that mirrors the TypeScript API:
from pytoon import encode, DELIMITERS
encode(
{"items": [{"id": 1, "name": "Ada"}, {"id": 2, "name": "Bob"}]},
{
"indent": 4,
"delimiter": DELIMITERS["pipe"], # or ',' / '\t'
"length_marker": "#", # renders headers as [#N]
},
)
Output:
items[#2|]{id|name}:
1|Ada
2|Bob
Testing
Tests are implemented with Python's standard unittest framework:
python3 -m unittest discover -s tests
To ensure behaviour matches upstream, we recommend porting and expanding the fixture coverage found in docs/toon-main/test/index.test.ts.
Project Structure
pytoon/– Core encoder modules (constants,normalize,primitives,encoders,writer).tests/– Unit tests that exercise key encoding scenarios.
Versioning & Compatibility
PyTOON targets Python 3.8+ and strives to remain aligned with the latest upstream toon behaviour. Breaking changes to the text format will only occur alongside upstream updates and will be noted in release notes.
Contributing
Contributions are welcome! To get started:
- Fork and clone the repository.
- Create a virtual environment for Python 3.8 or newer.
- Install in editable mode with testing extras:
pip install -e .. - Run
python3 -m unittest discover -s testsbefore submitting a pull request.
When porting behaviour from the TypeScript project, please include links or references to the corresponding upstream implementation and tests for easier review.
License
PyTOON retains the licensing of the original toon project. Refer to LICENSE for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pytoon_encoder-0.1.0.tar.gz.
File metadata
- Download URL: pytoon_encoder-0.1.0.tar.gz
- Upload date:
- Size: 11.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f5b1501a2233c582f5140a119638243d8343e3746d3e842c70ea136c9ce69900
|
|
| MD5 |
1ccca0f79f7917cc361dc6375481bb53
|
|
| BLAKE2b-256 |
80ad66bb71734f41217e4e48c2c19815946d31a74be177202b0ac23656469407
|
File details
Details for the file pytoon_encoder-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pytoon_encoder-0.1.0-py3-none-any.whl
- Upload date:
- Size: 10.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4beea14f4399790023c4750a01a1b3719b4e5533cf325f44997bfc02b1c3cd05
|
|
| MD5 |
738e186369cb73e2a454fd92c75bc1e2
|
|
| BLAKE2b-256 |
5e16789646eaca7f5f104bde859e8f7dd0d7d0b4c798afd5623a58fe34a034b1
|