toon-convertor 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- toon_convertor-1.0.0/LICENSE +21 -0
- toon_convertor-1.0.0/PKG-INFO +294 -0
- toon_convertor-1.0.0/README.md +242 -0
- toon_convertor-1.0.0/pyproject.toml +48 -0
- toon_convertor-1.0.0/setup.cfg +4 -0
- toon_convertor-1.0.0/tests/test_toon.py +537 -0
- toon_convertor-1.0.0/toon/__init__.py +184 -0
- toon_convertor-1.0.0/toon/cli.py +98 -0
- toon_convertor-1.0.0/toon/core.py +440 -0
- toon_convertor-1.0.0/toon/exceptions.py +16 -0
- toon_convertor-1.0.0/toon_convertor.egg-info/PKG-INFO +294 -0
- toon_convertor-1.0.0/toon_convertor.egg-info/SOURCES.txt +14 -0
- toon_convertor-1.0.0/toon_convertor.egg-info/dependency_links.txt +1 -0
- toon_convertor-1.0.0/toon_convertor.egg-info/entry_points.txt +2 -0
- toon_convertor-1.0.0/toon_convertor.egg-info/requires.txt +3 -0
- toon_convertor-1.0.0/toon_convertor.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 toon contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: toon-convertor
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: TOON – Token Optimised Object Notation. A compact, human-readable alternative to JSON.
|
|
5
|
+
Author: Ajinkya Sonar
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2025 toon contributors
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
|
|
28
|
+
Project-URL: Homepage, https://github.com/ajinkyasonar7/toon-converter
|
|
29
|
+
Project-URL: Repository, https://github.com/ajinkyasonar7/toon-converter
|
|
30
|
+
Project-URL: Issues, https://github.com/ajinkyasonar7/toon-converter/issues
|
|
31
|
+
Keywords: json,serialization,toon,token,format,notation,parser,llm,ai
|
|
32
|
+
Classifier: Development Status :: 4 - Beta
|
|
33
|
+
Classifier: Intended Audience :: Developers
|
|
34
|
+
Classifier: Intended Audience :: Science/Research
|
|
35
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
36
|
+
Classifier: Operating System :: OS Independent
|
|
37
|
+
Classifier: Programming Language :: Python :: 3
|
|
38
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
39
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
40
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
41
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
42
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
43
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
44
|
+
Classifier: Topic :: Text Processing :: Markup
|
|
45
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
46
|
+
Requires-Python: >=3.8
|
|
47
|
+
Description-Content-Type: text/markdown
|
|
48
|
+
License-File: LICENSE
|
|
49
|
+
Provides-Extra: dev
|
|
50
|
+
Requires-Dist: pytest>=7; extra == "dev"
|
|
51
|
+
Dynamic: license-file
|
|
52
|
+
|
|
53
|
+
# 🎯 TOON — Token Optimised Object Notation
|
|
54
|
+
|
|
55
|
+
[](https://badge.fury.io/py/toon-convertor)
|
|
56
|
+
[](https://pypi.org/project/toon-convertor/)
|
|
57
|
+
[](LICENSE)
|
|
58
|
+
|
|
59
|
+
**TOON** is a compact, human-readable data format designed as a token-efficient alternative to JSON.
|
|
60
|
+
It is object-oriented, whitespace-aware, and fully round-trips with JSON.
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
## Why TOON?
|
|
65
|
+
|
|
66
|
+
| Feature | JSON | TOON |
|
|
67
|
+
|---|---|---|
|
|
68
|
+
| Key quotes required | ✅ Yes | ❌ No |
|
|
69
|
+
| Brace/comma noise | ✅ High | ❌ Minimal |
|
|
70
|
+
| Comments | ❌ No | ✅ Yes (`#`) |
|
|
71
|
+
| Typed objects | ❌ No | ✅ `@TypeName` |
|
|
72
|
+
| Multiline strings | ❌ Awkward | ✅ `|` block |
|
|
73
|
+
| Token count | Higher | **~15–30% fewer** |
|
|
74
|
+
| Round-trip with JSON | — | ✅ Lossless |
|
|
75
|
+
|
|
76
|
+
### Token comparison
|
|
77
|
+
|
|
78
|
+
```json
|
|
79
|
+
{"name": "Alice", "age": 30, "active": true, "city": "Berlin"}
|
|
80
|
+
```
|
|
81
|
+
vs
|
|
82
|
+
```toon
|
|
83
|
+
name: Alice
|
|
84
|
+
age: 30
|
|
85
|
+
active: true
|
|
86
|
+
city: Berlin
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
> TOON is especially useful in LLM prompts, config files, and API responses where token count matters.
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
## Installation
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
pip install toon-convertor
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
---
|
|
100
|
+
|
|
101
|
+
## Quick Start
|
|
102
|
+
|
|
103
|
+
```python
|
|
104
|
+
import toon
|
|
105
|
+
|
|
106
|
+
# --- Serialize Python → TOON ---
|
|
107
|
+
data = {
|
|
108
|
+
"name": "Alice",
|
|
109
|
+
"age": 30,
|
|
110
|
+
"active": True,
|
|
111
|
+
"skills": ["Python", "LangChain", "RAG"],
|
|
112
|
+
"address": {"city": "Berlin", "country": "Germany"},
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
toon_str = toon.dumps(data)
|
|
116
|
+
print(toon_str)
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Output:
|
|
120
|
+
```
|
|
121
|
+
name: Alice
|
|
122
|
+
age: 30
|
|
123
|
+
active: true
|
|
124
|
+
skills: [Python, LangChain, RAG]
|
|
125
|
+
address:
|
|
126
|
+
city: Berlin
|
|
127
|
+
country: Germany
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
```python
|
|
131
|
+
# --- Deserialize TOON → Python ---
|
|
132
|
+
obj = toon.loads(toon_str)
|
|
133
|
+
print(obj["name"]) # Alice
|
|
134
|
+
print(obj["age"]) # 25
|
|
135
|
+
print(obj["active"]) # True
|
|
136
|
+
|
|
137
|
+
# --- JSON ↔ TOON conversion ---
|
|
138
|
+
import json
|
|
139
|
+
|
|
140
|
+
json_str = json.dumps(data)
|
|
141
|
+
toon_str = toon.from_json(json_str) # JSON → TOON
|
|
142
|
+
back_json = toon.to_json(toon_str) # TOON → JSON
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
---
|
|
146
|
+
|
|
147
|
+
## TOON Format Specification
|
|
148
|
+
|
|
149
|
+
### Key-Value Pairs
|
|
150
|
+
```toon
|
|
151
|
+
name: Alice
|
|
152
|
+
age: 30
|
|
153
|
+
score: 98.6
|
|
154
|
+
active: true
|
|
155
|
+
nothing: null
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### Strings (quotes only when needed)
|
|
159
|
+
```toon
|
|
160
|
+
city: Berlin
|
|
161
|
+
full_name: "Alice Smith"
|
|
162
|
+
bio: "Software Engineer"
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### Nested Objects
|
|
166
|
+
```toon
|
|
167
|
+
# Indented block
|
|
168
|
+
address:
|
|
169
|
+
city: Berlin
|
|
170
|
+
pin: 10115
|
|
171
|
+
|
|
172
|
+
# Inline object
|
|
173
|
+
point: {x: 10, y: 20}
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
### Arrays
|
|
177
|
+
```toon
|
|
178
|
+
# Inline (simple values)
|
|
179
|
+
tags: [python, llm, rag]
|
|
180
|
+
scores: [98, 87, 76]
|
|
181
|
+
|
|
182
|
+
# Multi-line
|
|
183
|
+
skills:
|
|
184
|
+
- Python
|
|
185
|
+
- LangChain
|
|
186
|
+
- FastAPI
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### Typed Objects (OO feature)
|
|
190
|
+
```toon
|
|
191
|
+
@Person
|
|
192
|
+
name: Alice
|
|
193
|
+
age: 30
|
|
194
|
+
role: "Engineer"
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
Parsed as:
|
|
198
|
+
```python
|
|
199
|
+
{"__type__": "Person", "name": "Alice", "age": 30, "role": "Engineer"}
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
### Comments
|
|
203
|
+
```toon
|
|
204
|
+
# Full-line comment
|
|
205
|
+
name: Alice # inline comment
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
### Multiline Strings
|
|
209
|
+
```toon
|
|
210
|
+
bio: |
|
|
211
|
+
Software Engineer based in Berlin.
|
|
212
|
+
Loves open source and clean code.
|
|
213
|
+
Building great tools daily.
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
### Type Inference
|
|
217
|
+
|
|
218
|
+
| TOON value | Python type |
|
|
219
|
+
|---|---|
|
|
220
|
+
| `42` | `int` |
|
|
221
|
+
| `3.14` | `float` |
|
|
222
|
+
| `true` / `false` | `bool` |
|
|
223
|
+
| `null` / `none` / `~` | `None` |
|
|
224
|
+
| `"hello"` | `str` |
|
|
225
|
+
| `hello` (bare) | `str` |
|
|
226
|
+
|
|
227
|
+
---
|
|
228
|
+
|
|
229
|
+
## API Reference
|
|
230
|
+
|
|
231
|
+
### `toon.loads(s)`
|
|
232
|
+
Parse a TOON string → Python object.
|
|
233
|
+
|
|
234
|
+
### `toon.load(fp)`
|
|
235
|
+
Parse TOON from a file-like object.
|
|
236
|
+
|
|
237
|
+
### `toon.dumps(obj, *, indent=2)`
|
|
238
|
+
Serialize Python object → TOON string.
|
|
239
|
+
|
|
240
|
+
### `toon.dump(obj, fp, *, indent=2)`
|
|
241
|
+
Serialize Python object → write to file.
|
|
242
|
+
|
|
243
|
+
### `toon.from_json(json_str, *, indent=2)`
|
|
244
|
+
Convert JSON string → TOON string.
|
|
245
|
+
|
|
246
|
+
### `toon.to_json(toon_str, *, indent=None, sort_keys=False)`
|
|
247
|
+
Convert TOON string → JSON string.
|
|
248
|
+
|
|
249
|
+
---
|
|
250
|
+
|
|
251
|
+
## CLI
|
|
252
|
+
|
|
253
|
+
TOON ships with a command-line tool:
|
|
254
|
+
|
|
255
|
+
```bash
|
|
256
|
+
# Convert TOON → JSON
|
|
257
|
+
toon to-json data.toon
|
|
258
|
+
toon to-json data.toon --indent 4
|
|
259
|
+
toon to-json data.toon --compact
|
|
260
|
+
|
|
261
|
+
# Convert JSON → TOON
|
|
262
|
+
toon from-json data.json
|
|
263
|
+
|
|
264
|
+
# Pipe support
|
|
265
|
+
cat data.json | toon from-json
|
|
266
|
+
cat data.toon | toon to-json
|
|
267
|
+
|
|
268
|
+
# Validate TOON
|
|
269
|
+
toon validate data.toon
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
---
|
|
273
|
+
|
|
274
|
+
## Use Cases
|
|
275
|
+
|
|
276
|
+
- **LLM prompts** — fewer tokens, same information
|
|
277
|
+
- **Config files** — more readable than JSON, less strict than YAML
|
|
278
|
+
- **API responses** — compact alternative where bandwidth matters
|
|
279
|
+
- **Data interchange** — anywhere JSON is used but verbosity is a cost
|
|
280
|
+
|
|
281
|
+
---
|
|
282
|
+
|
|
283
|
+
## Contributing
|
|
284
|
+
|
|
285
|
+
1. Fork the repo
|
|
286
|
+
2. `pip install -e ".[dev]"`
|
|
287
|
+
3. Run tests: `pytest`
|
|
288
|
+
4. Submit a PR!
|
|
289
|
+
|
|
290
|
+
---
|
|
291
|
+
|
|
292
|
+
## License
|
|
293
|
+
|
|
294
|
+
MIT © toon contributors
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
# 🎯 TOON — Token Optimised Object Notation
|
|
2
|
+
|
|
3
|
+
[](https://badge.fury.io/py/toon-convertor)
|
|
4
|
+
[](https://pypi.org/project/toon-convertor/)
|
|
5
|
+
[](LICENSE)
|
|
6
|
+
|
|
7
|
+
**TOON** is a compact, human-readable data format designed as a token-efficient alternative to JSON.
|
|
8
|
+
It is object-oriented, whitespace-aware, and fully round-trips with JSON.
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## Why TOON?
|
|
13
|
+
|
|
14
|
+
| Feature | JSON | TOON |
|
|
15
|
+
|---|---|---|
|
|
16
|
+
| Key quotes required | ✅ Yes | ❌ No |
|
|
17
|
+
| Brace/comma noise | ✅ High | ❌ Minimal |
|
|
18
|
+
| Comments | ❌ No | ✅ Yes (`#`) |
|
|
19
|
+
| Typed objects | ❌ No | ✅ `@TypeName` |
|
|
20
|
+
| Multiline strings | ❌ Awkward | ✅ `|` block |
|
|
21
|
+
| Token count | Higher | **~15–30% fewer** |
|
|
22
|
+
| Round-trip with JSON | — | ✅ Lossless |
|
|
23
|
+
|
|
24
|
+
### Token comparison
|
|
25
|
+
|
|
26
|
+
```json
|
|
27
|
+
{"name": "Alice", "age": 30, "active": true, "city": "Berlin"}
|
|
28
|
+
```
|
|
29
|
+
vs
|
|
30
|
+
```toon
|
|
31
|
+
name: Alice
|
|
32
|
+
age: 30
|
|
33
|
+
active: true
|
|
34
|
+
city: Berlin
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
> TOON is especially useful in LLM prompts, config files, and API responses where token count matters.
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
## Installation
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
pip install toon-convertor
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
## Quick Start
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
import toon
|
|
53
|
+
|
|
54
|
+
# --- Serialize Python → TOON ---
|
|
55
|
+
data = {
|
|
56
|
+
"name": "Alice",
|
|
57
|
+
"age": 30,
|
|
58
|
+
"active": True,
|
|
59
|
+
"skills": ["Python", "LangChain", "RAG"],
|
|
60
|
+
"address": {"city": "Berlin", "country": "Germany"},
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
toon_str = toon.dumps(data)
|
|
64
|
+
print(toon_str)
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Output:
|
|
68
|
+
```
|
|
69
|
+
name: Alice
|
|
70
|
+
age: 30
|
|
71
|
+
active: true
|
|
72
|
+
skills: [Python, LangChain, RAG]
|
|
73
|
+
address:
|
|
74
|
+
city: Berlin
|
|
75
|
+
country: Germany
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
# --- Deserialize TOON → Python ---
|
|
80
|
+
obj = toon.loads(toon_str)
|
|
81
|
+
print(obj["name"]) # Alice
|
|
82
|
+
print(obj["age"]) # 25
|
|
83
|
+
print(obj["active"]) # True
|
|
84
|
+
|
|
85
|
+
# --- JSON ↔ TOON conversion ---
|
|
86
|
+
import json
|
|
87
|
+
|
|
88
|
+
json_str = json.dumps(data)
|
|
89
|
+
toon_str = toon.from_json(json_str) # JSON → TOON
|
|
90
|
+
back_json = toon.to_json(toon_str) # TOON → JSON
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
## TOON Format Specification
|
|
96
|
+
|
|
97
|
+
### Key-Value Pairs
|
|
98
|
+
```toon
|
|
99
|
+
name: Alice
|
|
100
|
+
age: 30
|
|
101
|
+
score: 98.6
|
|
102
|
+
active: true
|
|
103
|
+
nothing: null
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### Strings (quotes only when needed)
|
|
107
|
+
```toon
|
|
108
|
+
city: Berlin
|
|
109
|
+
full_name: "Alice Smith"
|
|
110
|
+
bio: "Software Engineer"
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### Nested Objects
|
|
114
|
+
```toon
|
|
115
|
+
# Indented block
|
|
116
|
+
address:
|
|
117
|
+
city: Berlin
|
|
118
|
+
pin: 10115
|
|
119
|
+
|
|
120
|
+
# Inline object
|
|
121
|
+
point: {x: 10, y: 20}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### Arrays
|
|
125
|
+
```toon
|
|
126
|
+
# Inline (simple values)
|
|
127
|
+
tags: [python, llm, rag]
|
|
128
|
+
scores: [98, 87, 76]
|
|
129
|
+
|
|
130
|
+
# Multi-line
|
|
131
|
+
skills:
|
|
132
|
+
- Python
|
|
133
|
+
- LangChain
|
|
134
|
+
- FastAPI
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### Typed Objects (OO feature)
|
|
138
|
+
```toon
|
|
139
|
+
@Person
|
|
140
|
+
name: Alice
|
|
141
|
+
age: 30
|
|
142
|
+
role: "Engineer"
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
Parsed as:
|
|
146
|
+
```python
|
|
147
|
+
{"__type__": "Person", "name": "Alice", "age": 30, "role": "Engineer"}
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### Comments
|
|
151
|
+
```toon
|
|
152
|
+
# Full-line comment
|
|
153
|
+
name: Alice # inline comment
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### Multiline Strings
|
|
157
|
+
```toon
|
|
158
|
+
bio: |
|
|
159
|
+
Software Engineer based in Berlin.
|
|
160
|
+
Loves open source and clean code.
|
|
161
|
+
Building great tools daily.
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### Type Inference
|
|
165
|
+
|
|
166
|
+
| TOON value | Python type |
|
|
167
|
+
|---|---|
|
|
168
|
+
| `42` | `int` |
|
|
169
|
+
| `3.14` | `float` |
|
|
170
|
+
| `true` / `false` | `bool` |
|
|
171
|
+
| `null` / `none` / `~` | `None` |
|
|
172
|
+
| `"hello"` | `str` |
|
|
173
|
+
| `hello` (bare) | `str` |
|
|
174
|
+
|
|
175
|
+
---
|
|
176
|
+
|
|
177
|
+
## API Reference
|
|
178
|
+
|
|
179
|
+
### `toon.loads(s)`
|
|
180
|
+
Parse a TOON string → Python object.
|
|
181
|
+
|
|
182
|
+
### `toon.load(fp)`
|
|
183
|
+
Parse TOON from a file-like object.
|
|
184
|
+
|
|
185
|
+
### `toon.dumps(obj, *, indent=2)`
|
|
186
|
+
Serialize Python object → TOON string.
|
|
187
|
+
|
|
188
|
+
### `toon.dump(obj, fp, *, indent=2)`
|
|
189
|
+
Serialize Python object → write to file.
|
|
190
|
+
|
|
191
|
+
### `toon.from_json(json_str, *, indent=2)`
|
|
192
|
+
Convert JSON string → TOON string.
|
|
193
|
+
|
|
194
|
+
### `toon.to_json(toon_str, *, indent=None, sort_keys=False)`
|
|
195
|
+
Convert TOON string → JSON string.
|
|
196
|
+
|
|
197
|
+
---
|
|
198
|
+
|
|
199
|
+
## CLI
|
|
200
|
+
|
|
201
|
+
TOON ships with a command-line tool:
|
|
202
|
+
|
|
203
|
+
```bash
|
|
204
|
+
# Convert TOON → JSON
|
|
205
|
+
toon to-json data.toon
|
|
206
|
+
toon to-json data.toon --indent 4
|
|
207
|
+
toon to-json data.toon --compact
|
|
208
|
+
|
|
209
|
+
# Convert JSON → TOON
|
|
210
|
+
toon from-json data.json
|
|
211
|
+
|
|
212
|
+
# Pipe support
|
|
213
|
+
cat data.json | toon from-json
|
|
214
|
+
cat data.toon | toon to-json
|
|
215
|
+
|
|
216
|
+
# Validate TOON
|
|
217
|
+
toon validate data.toon
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
---
|
|
221
|
+
|
|
222
|
+
## Use Cases
|
|
223
|
+
|
|
224
|
+
- **LLM prompts** — fewer tokens, same information
|
|
225
|
+
- **Config files** — more readable than JSON, less strict than YAML
|
|
226
|
+
- **API responses** — compact alternative where bandwidth matters
|
|
227
|
+
- **Data interchange** — anywhere JSON is used but verbosity is a cost
|
|
228
|
+
|
|
229
|
+
---
|
|
230
|
+
|
|
231
|
+
## Contributing
|
|
232
|
+
|
|
233
|
+
1. Fork the repo
|
|
234
|
+
2. `pip install -e ".[dev]"`
|
|
235
|
+
3. Run tests: `pytest`
|
|
236
|
+
4. Submit a PR!
|
|
237
|
+
|
|
238
|
+
---
|
|
239
|
+
|
|
240
|
+
## License
|
|
241
|
+
|
|
242
|
+
MIT © toon contributors
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "toon-convertor"
|
|
7
|
+
version = "1.0.0"
|
|
8
|
+
description = "TOON – Token Optimised Object Notation. A compact, human-readable alternative to JSON."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = { file = "LICENSE" }
|
|
11
|
+
authors = [{ name = "Ajinkya Sonar" }]
|
|
12
|
+
requires-python = ">=3.8"
|
|
13
|
+
dependencies = []
|
|
14
|
+
keywords = ["json", "serialization", "toon", "token", "format", "notation", "parser", "llm", "ai"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 4 - Beta",
|
|
17
|
+
"Intended Audience :: Developers",
|
|
18
|
+
"Intended Audience :: Science/Research",
|
|
19
|
+
"License :: OSI Approved :: MIT License",
|
|
20
|
+
"Operating System :: OS Independent",
|
|
21
|
+
"Programming Language :: Python :: 3",
|
|
22
|
+
"Programming Language :: Python :: 3.8",
|
|
23
|
+
"Programming Language :: Python :: 3.9",
|
|
24
|
+
"Programming Language :: Python :: 3.10",
|
|
25
|
+
"Programming Language :: Python :: 3.11",
|
|
26
|
+
"Programming Language :: Python :: 3.12",
|
|
27
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
28
|
+
"Topic :: Text Processing :: Markup",
|
|
29
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
[project.optional-dependencies]
|
|
33
|
+
dev = ["pytest>=7"]
|
|
34
|
+
|
|
35
|
+
[project.urls]
|
|
36
|
+
Homepage = "https://github.com/ajinkyasonar7/toon-converter"
|
|
37
|
+
Repository = "https://github.com/ajinkyasonar7/toon-converter"
|
|
38
|
+
Issues = "https://github.com/ajinkyasonar7/toon-converter/issues"
|
|
39
|
+
|
|
40
|
+
[project.scripts]
|
|
41
|
+
toon = "toon.cli:main"
|
|
42
|
+
|
|
43
|
+
[tool.setuptools.packages.find]
|
|
44
|
+
where = ["."]
|
|
45
|
+
include = ["toon*"]
|
|
46
|
+
|
|
47
|
+
[tool.pytest.ini_options]
|
|
48
|
+
testpaths = ["tests"]
|