pytoonio 0.1.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.
@@ -0,0 +1,13 @@
1
+ =======
2
+ Credits
3
+ =======
4
+
5
+ Development Lead
6
+ ----------------
7
+
8
+ * Mohit Prajapat <mohitdevelopment2001@gmail.com>
9
+
10
+ Contributors
11
+ ------------
12
+
13
+ None yet. Why not be the first?
@@ -0,0 +1 @@
1
+ Mohit Prajapat - @mohitprajapat2001
pytoonio-0.1.0/LICENCE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Mohit Prajapat
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,4 @@
1
+ include README.md
2
+ include LICENSE
3
+ include CONTRIBUTORS
4
+ recursive-include pytoonio *.py
@@ -0,0 +1,366 @@
1
+ Metadata-Version: 2.4
2
+ Name: pytoonio
3
+ Version: 0.1.0
4
+ Summary: Django OTP key generator and validator
5
+ Home-page: https://github.com/mohitprajapat2001/pytoonio
6
+ Author: Mohit Prajapat
7
+ Author-email: Mohit Prajapat <mohitdevelopment2001@gmail.com>
8
+ Project-URL: Homepage, https://github.com/mohitprajapat2001/pytoonio
9
+ Project-URL: Bug Tracker, https://github.com/mohitprajapat2001/pytoonio/issues
10
+ Requires-Python: >=3.10
11
+ Description-Content-Type: text/markdown
12
+ License-File: LICENCE
13
+ License-File: AUTHORS.rst
14
+ Dynamic: license-file
15
+
16
+ # PyToonIo
17
+
18
+ ![Python](https://img.shields.io/badge/Python-3.10%2B-green?style=for-the-badge&logo=python)
19
+ ![License](https://img.shields.io/badge/License-MIT-yellow?style=for-the-badge)
20
+ ![PyPI](https://img.shields.io/badge/PyPI-pytoonio-orange?style=for-the-badge&logo=pypi)
21
+
22
+ **A lightweight Python library for converting between JSON, XML, and TOON โ€” a modern,
23
+ human-friendly data format.**
24
+
25
+ ---
26
+
27
+ ## ๐Ÿš€ What is TOON?
28
+
29
+ **TOON** is a clean and expressive data format that focuses on:
30
+
31
+ - โœ… **Improved human readability** โ€” Easy to read and understand at a glance
32
+ - โœ… **Minimal syntax complexity** โ€” Less visual noise compared to JSON and XML
33
+ - โœ… **Easier manual editing** โ€” Friendly for developers and non-developers alike
34
+ - โœ… **Clear structure representation** โ€” Logical and consistent nesting
35
+
36
+ It aims to combine the structural clarity of JSON and XML while significantly reducing
37
+ visual clutter.
38
+
39
+ ---
40
+
41
+ ## โœจ Features
42
+
43
+ | Feature | Description |
44
+ | -------------- | ----------------------------------------- |
45
+ | ๐Ÿ”„ JSON โ†’ TOON | Convert any JSON data to the TOON format |
46
+ | ๐Ÿ”„ XML โ†’ TOON | Convert any XML data to the TOON format |
47
+ | ๐Ÿ”„ TOON โ†’ JSON | Parse TOON back into JSON |
48
+ | ๐Ÿ”„ TOON โ†’ XML | Parse TOON back into XML |
49
+ | ๐Ÿชถ Lightweight | Minimal dependencies, fast and efficient |
50
+ | ๐Ÿงฉ Simple API | Clean, intuitive API for easy integration |
51
+
52
+ ---
53
+
54
+ ## ๐Ÿ“ฆ Installation
55
+
56
+ Install pytoonio via pip:
57
+
58
+ ```bash
59
+ pip install pytoonio
60
+ ```
61
+
62
+ **Requirements:** Python 3.10+
63
+
64
+ ---
65
+
66
+ ## ๐Ÿง‘โ€๐Ÿ’ป Usage
67
+
68
+ ### Quick Start
69
+
70
+ ```python
71
+ from pytoonio import convert
72
+ ```
73
+
74
+ ---
75
+
76
+ ### ๐Ÿ”„ JSON โ†’ TOON
77
+
78
+ ```python
79
+ from pytoonio import convert
80
+
81
+ data = {
82
+ "users": [
83
+ {"id": 1001, "name": "Emma Wilson", "role": "admin"},
84
+ {"id": 1002, "name": "James Brown", "role": "editor"},
85
+ ],
86
+ "totalCount": 2,
87
+ "active": True,
88
+ }
89
+
90
+ toon = convert.json_to_toon(data)
91
+ print(toon)
92
+ ```
93
+
94
+ **Output:**
95
+
96
+ ```
97
+ users[2]{id,name,role}:
98
+ 1001,Emma Wilson,admin
99
+ 1002,James Brown,editor
100
+ totalCount: 2
101
+ active: true
102
+ ```
103
+
104
+ > ๐Ÿ”ท Lists of objects with **identical keys** use the compact `key[N]{headers}:`
105
+ > annotation. Each data row is comma-separated (using the configured delimiter).
106
+
107
+ ---
108
+
109
+ ### ๐Ÿ”„ TOON โ†’ JSON
110
+
111
+ ```python
112
+ from pytoonio import convert
113
+
114
+ toon = """
115
+ users[2]{id,name,role}:
116
+ 1001,Emma Wilson,admin
117
+ 1002,James Brown,editor
118
+ totalCount: 2
119
+ active: true
120
+ """
121
+
122
+ json_str = convert.toon_to_json(toon)
123
+ print(json_str)
124
+ # {"users": [{"id": 1001, ...}], "totalCount": 2, "active": true}
125
+
126
+ # Or as a Python dict
127
+ data = convert.toon_to_json(toon, as_string=False)
128
+ print(data["totalCount"]) # 2
129
+ ```
130
+
131
+ ---
132
+
133
+ ### ๐Ÿ”„ XML โ†’ TOON
134
+
135
+ ```python
136
+ from pytoonio import convert
137
+
138
+ xml = """
139
+ <company>
140
+ <name>TechCorp International</name>
141
+ <founded>2010</founded>
142
+ <headquarters>
143
+ <city>San Francisco</city>
144
+ <country>USA</country>
145
+ </headquarters>
146
+ </company>
147
+ """
148
+
149
+ toon = convert.xml_to_toon(xml)
150
+ print(toon)
151
+ ```
152
+
153
+ **Output:**
154
+
155
+ ```
156
+ company:
157
+ name: TechCorp International
158
+ founded: 2010
159
+ headquarters:
160
+ city: San Francisco
161
+ country: USA
162
+ ```
163
+
164
+ ---
165
+
166
+ ### ๐Ÿ”„ TOON โ†’ XML
167
+
168
+ ```python
169
+ from pytoonio import convert
170
+
171
+ toon = """
172
+ company:
173
+ name: TechCorp International
174
+ founded: 2010
175
+ headquarters:
176
+ city: San Francisco
177
+ country: USA
178
+ """
179
+
180
+ xml = convert.toon_to_xml(toon)
181
+ print(xml)
182
+ # <company><name>TechCorp International</name><founded>2010</founded>...</company>
183
+ ```
184
+
185
+ ---
186
+
187
+ ### โš™๏ธ Configuration Options
188
+
189
+ All conversion functions support two options:
190
+
191
+ | Option | Values | Default | Description |
192
+ | ----------- | ---------------------------- | --------- | ---------------------------- |
193
+ | `indent` | `2`, `4` | `2` | Spaces per indentation level |
194
+ | `delimiter` | `"comma"`, `"tab"`, `"pipe"` | `"comma"` | Separator for tabular data |
195
+
196
+ ```python
197
+ from pytoonio import convert
198
+
199
+ data = {
200
+ "products": [
201
+ {"id": "P001", "name": "Headphones", "price": 149.99},
202
+ {"id": "P002", "name": "Smart Watch", "price": 299.99},
203
+ ]
204
+ }
205
+
206
+ # 4-space indent + pipe delimiter
207
+ toon = convert.json_to_toon(data, indent=4, delimiter="pipe")
208
+ print(toon)
209
+ ```
210
+
211
+ **Output with `indent=4, delimiter="pipe"`:**
212
+
213
+ ```
214
+ products:
215
+ id | name | price
216
+ P001 | Headphones | 149.99
217
+ P002 | Smart Watch | 299.99
218
+ ```
219
+
220
+ **Output with `indent=2, delimiter="tab"`:**
221
+
222
+ ```
223
+ products:
224
+ id name price
225
+ P001 Headphones 149.99
226
+ P002 Smart Watch 299.99
227
+ ```
228
+
229
+ ---
230
+
231
+ ### ๐Ÿ—๏ธ Class-Based API
232
+
233
+ For more control, use the encoder/decoder classes directly:
234
+
235
+ ```python
236
+ from pytoonio.converters import JsonToToonEncoder, ToonToJsonDecoder
237
+ from pytoonio.converters import XmlToToonEncoder, ToonToXmlDecoder
238
+
239
+ # Reuse the same encoder instance
240
+ encoder = JsonToToonEncoder(indent=4, delimiter="pipe")
241
+
242
+ toon1 = encoder.encode({"name": "Alice", "age": 30})
243
+ toon2 = encoder.encode({"project": "pytoonio", "version": "0.0.1"})
244
+
245
+ # Decode with matching delimiter
246
+ decoder = ToonToJsonDecoder(delimiter="pipe")
247
+ data = decoder.decode(toon1)
248
+ ```
249
+
250
+ ---
251
+
252
+ ### ๐Ÿ“– TOON Format Reference
253
+
254
+ | Data | TOON Syntax |
255
+ | ---------------------------- | ------------------------------------ |
256
+ | Key-value | `key: value` |
257
+ | Nested object | Indented `key:` block |
258
+ | Primitive list (under a key) | `key: [item1, item2, item3]` |
259
+ | **Uniform object list** | `key[N]{col1,col2,...}:` + data rows |
260
+ | **Non-uniform object list** | `key[N]:` + `-` dash blocks |
261
+ | Null | `null` |
262
+ | Boolean | `true` / `false` |
263
+
264
+ **Uniform object list** โ€” all objects share the same keys:
265
+
266
+ ```
267
+ users[3]{id,name,role}:
268
+ 1,Alice,admin
269
+ 2,Bob,user
270
+ 3,Charlie,user
271
+ ```
272
+
273
+ **Non-uniform object list** โ€” objects have different keys:
274
+
275
+ ```
276
+ users[2]:
277
+ -
278
+ id: 1
279
+ name: Alice
280
+ email: alice@example.com
281
+ -
282
+ name: Charlie
283
+ email: charlie@example.com
284
+ role: user
285
+ ```
286
+
287
+ **Full example โ€” all TOON types:**
288
+
289
+ ```
290
+ name: Mohit
291
+ age: 25
292
+ active: true
293
+ score: null
294
+ skills: [Python, Django, REST]
295
+ analytics:
296
+ period: 2024-11
297
+ metrics:
298
+ pageViews: 125000
299
+ bounceRate: 42.5
300
+ topPages[3]{url,views,avgTime}:
301
+ /products,35000,180
302
+ /blog,28000,320
303
+ /pricing,22000,150
304
+ ```
305
+
306
+ ---
307
+
308
+ ### ๐Ÿงช Running Tests
309
+
310
+ ```bash
311
+ # Install dev dependencies
312
+ pip install pytest pytest-cov
313
+
314
+ # Run all tests
315
+ pytest
316
+
317
+ # Run with coverage report
318
+ pytest --cov=pytoonio --cov-report=term-missing
319
+ ```
320
+
321
+ ---
322
+
323
+ ## ๐Ÿ“Œ Project Information
324
+
325
+ | Field | Value |
326
+ | -------------- | -------------------------------------------------------------------------------------- |
327
+ | **Name** | pytoonio |
328
+ | **Version** | 0.0.1 |
329
+ | **Author** | Mohit Prajapat |
330
+ | **Email** | mohitdevelopment2001@gmail.com |
331
+ | **License** | MIT |
332
+ | **Python** | โ‰ฅ 3.10 |
333
+ | **Repository** | [github.com/mohitprajapat2001/pytoonio](https://github.com/mohitprajapat2001/pytoonio) |
334
+
335
+ ---
336
+
337
+ ## ๐Ÿค Contributing
338
+
339
+ Contributions are welcome! Feel free to:
340
+
341
+ 1. Fork the repository
342
+ 2. Create a feature branch (`git checkout -b feature/my-feature`)
343
+ 3. Commit your changes (`git commit -m 'Add my feature'`)
344
+ 4. Push to the branch (`git push origin feature/my-feature`)
345
+ 5. Open a Pull Request
346
+
347
+ Please read `CODE_OF_CONDUCT.md` for our community guidelines.
348
+
349
+ ---
350
+
351
+ ## ๐Ÿ“„ License
352
+
353
+ This project is licensed under the **MIT License** โ€” see the [LICENCE](LICENCE) file for
354
+ details.
355
+
356
+ ---
357
+
358
+ ## ๐Ÿ‘ฅ Authors & Contributors
359
+
360
+ See [AUTHORS.rst](AUTHORS.rst) and [CONTRIBUTORS](CONTRIBUTORS) for a full list.
361
+
362
+ ---
363
+
364
+ <div align="center">
365
+ Made with โค๏ธ by <a href="https://github.com/mohitprajapat2001">Mohit Prajapat</a>
366
+ </div>