toonify 0.0.1__py3-none-any.whl

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.
@@ -0,0 +1,383 @@
1
+ Metadata-Version: 2.4
2
+ Name: toonify
3
+ Version: 0.0.1
4
+ Summary: TOON (Token-Oriented Object Notation) - A compact, human-readable serialization format for LLMs
5
+ Project-URL: Homepage, https://github.com/toon-format/toon
6
+ Project-URL: Repository, https://github.com/toon-format/toon
7
+ Project-URL: Documentation, https://github.com/toon-format/toon#readme
8
+ Author: TOON Format Contributors
9
+ License: MIT
10
+ License-File: LICENSE
11
+ Keywords: csv,json,llm,serialization,token-efficient,toon
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.8
17
+ Classifier: Programming Language :: Python :: 3.9
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
22
+ Classifier: Topic :: Text Processing
23
+ Requires-Python: >=3.8
24
+ Requires-Dist: tiktoken>=0.5.0
25
+ Provides-Extra: dev
26
+ Requires-Dist: pytest-cov>=4.0.0; extra == 'dev'
27
+ Requires-Dist: pytest>=7.0.0; extra == 'dev'
28
+ Description-Content-Type: text/markdown
29
+
30
+ # TOON (Token-Oriented Object Notation)
31
+
32
+ A compact, human-readable serialization format designed for passing structured data to Large Language Models with significantly reduced token usage.
33
+
34
+ [![Python Version](https://img.shields.io/badge/python-3.8+-blue.svg)](https://www.python.org/downloads/)
35
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
36
+
37
+ ## Overview
38
+
39
+ TOON achieves **CSV-like compactness** while adding **explicit structure**, making it ideal for:
40
+ - Reducing token costs in LLM API calls
41
+ - Improving context window efficiency
42
+ - Maintaining human readability
43
+ - Preserving data structure and types
44
+
45
+ ### Key Features
46
+
47
+ - ✅ **Compact**: 30-60% smaller than JSON for structured data
48
+ - ✅ **Readable**: Clean, indentation-based syntax
49
+ - ✅ **Structured**: Preserves nested objects and arrays
50
+ - ✅ **Type-safe**: Supports strings, numbers, booleans, null
51
+ - ✅ **Flexible**: Multiple delimiter options (comma, tab, pipe)
52
+ - ✅ **Smart**: Automatic tabular format for uniform arrays
53
+ - ✅ **Efficient**: Key folding for deeply nested objects
54
+
55
+ ## Installation
56
+
57
+ ```bash
58
+ pip install toon-format
59
+ ```
60
+
61
+ For development:
62
+ ```bash
63
+ pip install toon-format[dev]
64
+ ```
65
+
66
+ ## Quick Start
67
+
68
+ ### Python API
69
+
70
+ ```python
71
+ from toon import encode, decode
72
+
73
+ # Encode Python dict to TOON
74
+ data = {
75
+ 'users': [
76
+ {'id': 1, 'name': 'Alice', 'role': 'admin'},
77
+ {'id': 2, 'name': 'Bob', 'role': 'user'}
78
+ ]
79
+ }
80
+
81
+ toon_string = encode(data)
82
+ print(toon_string)
83
+ # Output:
84
+ # users[2]{id,name,role}:
85
+ # 1,Alice,admin
86
+ # 2,Bob,user
87
+
88
+ # Decode TOON back to Python
89
+ result = decode(toon_string)
90
+ assert result == data
91
+ ```
92
+
93
+ ### Command Line
94
+
95
+ ```bash
96
+ # Encode JSON to TOON
97
+ toon input.json -o output.toon
98
+
99
+ # Decode TOON to JSON
100
+ toon input.toon -o output.json
101
+
102
+ # Use with pipes
103
+ cat data.json | toon -e > data.toon
104
+
105
+ # Show token statistics
106
+ toon data.json --stats
107
+ ```
108
+
109
+ ## TOON Format Specification
110
+
111
+ ### Basic Syntax
112
+
113
+ ```toon
114
+ # Simple key-value pairs
115
+ name: Alice
116
+ age: 30
117
+ active: true
118
+ ```
119
+
120
+ ### Arrays
121
+
122
+ **Primitive arrays** (inline):
123
+ ```toon
124
+ numbers: [1,2,3,4,5]
125
+ tags: [python,serialization,llm]
126
+ ```
127
+
128
+ **Tabular arrays** (uniform objects with header):
129
+ ```toon
130
+ users[3]{id,name,email}:
131
+ 1,Alice,alice@example.com
132
+ 2,Bob,bob@example.com
133
+ 3,Charlie,charlie@example.com
134
+ ```
135
+
136
+ **List arrays** (non-uniform or nested):
137
+ ```toon
138
+ items[2]:
139
+ value1
140
+ value2
141
+ ```
142
+
143
+ ### Nested Objects
144
+
145
+ ```toon
146
+ user:
147
+ name: Alice
148
+ profile:
149
+ age: 30
150
+ city: NYC
151
+ ```
152
+
153
+ ### Quoting Rules
154
+
155
+ Strings are quoted only when necessary:
156
+ - Contains special characters (`,`, `:`, `"`, newlines)
157
+ - Has leading/trailing whitespace
158
+ - Looks like a literal (`true`, `false`, `null`)
159
+ - Is empty
160
+
161
+ ```toon
162
+ simple: Alice
163
+ quoted: "Hello, World"
164
+ escaped: "He said \"hello\""
165
+ multiline: "Line 1\nLine 2"
166
+ ```
167
+
168
+ ## API Reference
169
+
170
+ ### `encode(data, options=None)`
171
+
172
+ Convert Python object to TOON string.
173
+
174
+ **Parameters:**
175
+ - `data`: Python dict or list
176
+ - `options`: Optional dict with:
177
+ - `delimiter`: `'comma'` (default), `'tab'`, or `'pipe'`
178
+ - `indent`: Number of spaces per level (default: 2)
179
+ - `key_folding`: `'off'` (default) or `'safe'`
180
+ - `flatten_depth`: Max depth for key folding (default: None)
181
+
182
+ **Example:**
183
+ ```python
184
+ toon = encode(data, {
185
+ 'delimiter': 'tab',
186
+ 'indent': 4,
187
+ 'key_folding': 'safe'
188
+ })
189
+ ```
190
+
191
+ ### `decode(toon_string, options=None)`
192
+
193
+ Convert TOON string to Python object.
194
+
195
+ **Parameters:**
196
+ - `toon_string`: TOON formatted string
197
+ - `options`: Optional dict with:
198
+ - `strict`: Validate structure strictly (default: True)
199
+ - `expand_paths`: `'off'` (default) or `'safe'`
200
+ - `default_delimiter`: Default delimiter (default: `','`)
201
+
202
+ **Example:**
203
+ ```python
204
+ data = decode(toon_string, {
205
+ 'expand_paths': 'safe',
206
+ 'strict': False
207
+ })
208
+ ```
209
+
210
+ ## CLI Usage
211
+
212
+ ```
213
+ usage: toon [-h] [-o OUTPUT] [-e] [-d] [--delimiter {comma,tab,pipe}]
214
+ [--indent INDENT] [--stats] [--no-strict]
215
+ [--key-folding {off,safe}] [--flatten-depth DEPTH]
216
+ [--expand-paths {off,safe}]
217
+ [input]
218
+
219
+ TOON (Token-Oriented Object Notation) - Convert between JSON and TOON formats
220
+
221
+ positional arguments:
222
+ input Input file path (or "-" for stdin)
223
+
224
+ optional arguments:
225
+ -h, --help show this help message and exit
226
+ -o, --output OUTPUT Output file path (default: stdout)
227
+ -e, --encode Force encode mode (JSON to TOON)
228
+ -d, --decode Force decode mode (TOON to JSON)
229
+ --delimiter {comma,tab,pipe}
230
+ Array delimiter (default: comma)
231
+ --indent INDENT Indentation size (default: 2)
232
+ --stats Show token statistics
233
+ --no-strict Disable strict validation (decode only)
234
+ --key-folding {off,safe}
235
+ Key folding mode (encode only)
236
+ --flatten-depth DEPTH Maximum key folding depth (encode only)
237
+ --expand-paths {off,safe}
238
+ Path expansion mode (decode only)
239
+ ```
240
+
241
+ ## Advanced Features
242
+
243
+ ### Key Folding
244
+
245
+ Collapse single-key chains into dotted paths:
246
+
247
+ ```python
248
+ data = {
249
+ 'response': {
250
+ 'data': {
251
+ 'user': {
252
+ 'name': 'Alice'
253
+ }
254
+ }
255
+ }
256
+ }
257
+
258
+ # With key_folding='safe'
259
+ toon = encode(data, {'key_folding': 'safe'})
260
+ # Output: response.data.user.name: Alice
261
+ ```
262
+
263
+ ### Path Expansion
264
+
265
+ Expand dotted keys into nested objects:
266
+
267
+ ```python
268
+ toon = 'user.profile.age: 30'
269
+
270
+ # With expand_paths='safe'
271
+ data = decode(toon, {'expand_paths': 'safe'})
272
+ # Result: {'user': {'profile': {'age': 30}}}
273
+ ```
274
+
275
+ ### Custom Delimiters
276
+
277
+ Choose the delimiter that best fits your data:
278
+
279
+ ```python
280
+ # Tab delimiter (better for spreadsheet-like data)
281
+ toon = encode(data, {'delimiter': 'tab'})
282
+
283
+ # Pipe delimiter (when data contains commas)
284
+ toon = encode(data, {'delimiter': 'pipe'})
285
+ ```
286
+
287
+ ## Format Comparison
288
+
289
+ ### JSON vs TOON
290
+
291
+ **JSON** (225 bytes):
292
+ ```json
293
+ {
294
+ "users": [
295
+ {"id": 1, "name": "Alice", "role": "admin"},
296
+ {"id": 2, "name": "Bob", "role": "user"},
297
+ {"id": 3, "name": "Charlie", "role": "guest"}
298
+ ]
299
+ }
300
+ ```
301
+
302
+ **TOON** (90 bytes, **60% reduction**):
303
+ ```toon
304
+ users[3]{id,name,role}:
305
+ 1,Alice,admin
306
+ 2,Bob,user
307
+ 3,Charlie,guest
308
+ ```
309
+
310
+ ### When to Use TOON
311
+
312
+ **Use TOON when:**
313
+ - ✅ Passing data to LLM APIs (reduce token costs)
314
+ - ✅ Working with uniform tabular data
315
+ - ✅ Context window is limited
316
+ - ✅ Human readability matters
317
+
318
+ **Use JSON when:**
319
+ - ❌ Maximum compatibility is required
320
+ - ❌ Data is highly irregular/nested
321
+ - ❌ Working with existing JSON-only tools
322
+
323
+ ## Development
324
+
325
+ ### Setup
326
+
327
+ ```bash
328
+ git clone https://github.com/VinciGit00/toon.git
329
+ cd toon
330
+ pip install -e .[dev]
331
+ ```
332
+
333
+ ### Running Tests
334
+
335
+ ```bash
336
+ pytest
337
+ pytest --cov=toon --cov-report=term-missing
338
+ ```
339
+
340
+ ### Running Examples
341
+
342
+ ```bash
343
+ python examples/basic_usage.py
344
+ python examples/advanced_features.py
345
+ ```
346
+
347
+ ## Performance
348
+
349
+ TOON typically achieves:
350
+ - **30-60% size reduction** vs JSON for structured data
351
+ - **40-70% token reduction** with tabular data
352
+ - **Minimal overhead** in encoding/decoding (<1ms for typical payloads)
353
+
354
+ ## Contributing
355
+
356
+ Contributions are welcome! Please:
357
+
358
+ 1. Fork the repository
359
+ 2. Create a feature branch (`git checkout -b feature/amazing-feature`)
360
+ 3. Make your changes with tests
361
+ 4. Run tests (`pytest`)
362
+ 5. Commit your changes (`git commit -m 'Add amazing feature'`)
363
+ 6. Push to the branch (`git push origin feature/amazing-feature`)
364
+ 7. Open a Pull Request
365
+
366
+ ## License
367
+
368
+ MIT License - see [LICENSE](LICENSE) file for details.
369
+
370
+ ## Credits
371
+
372
+ Python implementation inspired by the TypeScript TOON library at [toon-format/toon](https://github.com/toon-format/toon).
373
+
374
+ ## Links
375
+
376
+ - **GitHub**: https://github.com/VinciGit00/toon
377
+ - **PyPI**: https://pypi.org/project/toon-format/
378
+ - **Documentation**: https://github.com/VinciGit00/toon#readme
379
+ - **Format Spec**: https://github.com/toon-format/toon
380
+
381
+ ---
382
+
383
+ Made with ❤️ by the TOON Format Contributors
@@ -0,0 +1,11 @@
1
+ toon/__init__.py,sha256=Jsy5-LdqSq-ber_jWRreFpyNCYvuKjxZyeeHGYCAQl0,469
2
+ toon/cli.py,sha256=R1m-7P4frqxpBw25gcKnioT-e6DVvEToQU8r8zZFNqo,8214
3
+ toon/constants.py,sha256=A3OVWzTk2M2_yAqIL3qFCFWXKwijK3kmADURpwjjHEk,731
4
+ toon/decoder.py,sha256=IOUuhQXRt5x9hKXJtEBoufHrKRAMCmSCDZPKJxd_dhk,10562
5
+ toon/encoder.py,sha256=t98S_DnCEwKQUFy9cZZxd9Nx0aTpfkjn7dfS87zYqK0,10671
6
+ toon/utils.py,sha256=sgBfrEas6Gg27pvLnPMdYVd78ym5BuAIbDp00XPZTRk,6061
7
+ toonify-0.0.1.dist-info/METADATA,sha256=jNbMNeaDa1D4tVfmt4b4BjPBWy6WJGB0IeRxmA_7zmQ,9053
8
+ toonify-0.0.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
9
+ toonify-0.0.1.dist-info/entry_points.txt,sha256=ZUzG68bcKJR2xCJbszMhzon861v-NFbYQBpez7S2n98,39
10
+ toonify-0.0.1.dist-info/licenses/LICENSE,sha256=xY5Os1KQ8MSScfGgL1bWbgMR-gZHQHRPlnN9Ev1ezI8,1081
11
+ toonify-0.0.1.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.27.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ toon = toon.cli:main
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 TOON Format 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.