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.
- pytoonio-0.1.0/AUTHORS.rst +13 -0
- pytoonio-0.1.0/CONTRIBUTORS +1 -0
- pytoonio-0.1.0/LICENCE +21 -0
- pytoonio-0.1.0/MANIFEST.in +4 -0
- pytoonio-0.1.0/PKG-INFO +366 -0
- pytoonio-0.1.0/README.md +351 -0
- pytoonio-0.1.0/pyproject.toml +16 -0
- pytoonio-0.1.0/pytoonio/__init__.py +73 -0
- pytoonio-0.1.0/pytoonio/constants.py +77 -0
- pytoonio-0.1.0/pytoonio/convert.py +141 -0
- pytoonio-0.1.0/pytoonio/converters/__init__.py +22 -0
- pytoonio-0.1.0/pytoonio/converters/base.py +97 -0
- pytoonio-0.1.0/pytoonio/converters/json_converter.py +685 -0
- pytoonio-0.1.0/pytoonio/converters/xml_converter.py +323 -0
- pytoonio-0.1.0/pytoonio/exceptions.py +70 -0
- pytoonio-0.1.0/pytoonio/utils.py +243 -0
- pytoonio-0.1.0/pytoonio.egg-info/PKG-INFO +366 -0
- pytoonio-0.1.0/pytoonio.egg-info/SOURCES.txt +23 -0
- pytoonio-0.1.0/pytoonio.egg-info/dependency_links.txt +1 -0
- pytoonio-0.1.0/pytoonio.egg-info/top_level.txt +1 -0
- pytoonio-0.1.0/setup.cfg +44 -0
- pytoonio-0.1.0/tests/test_json_converter.py +293 -0
- pytoonio-0.1.0/tests/test_utils.py +327 -0
- pytoonio-0.1.0/tests/test_xml_converter.py +246 -0
|
@@ -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.
|
pytoonio-0.1.0/PKG-INFO
ADDED
|
@@ -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
|
+

|
|
19
|
+

|
|
20
|
+

|
|
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>
|