text2json-sdk 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.
- text2json_sdk-0.1.0/PKG-INFO +156 -0
- text2json_sdk-0.1.0/README.md +148 -0
- text2json_sdk-0.1.0/pyproject.toml +17 -0
- text2json_sdk-0.1.0/setup.cfg +4 -0
- text2json_sdk-0.1.0/text2json_sdk/__init__.py +4 -0
- text2json_sdk-0.1.0/text2json_sdk/core.py +55 -0
- text2json_sdk-0.1.0/text2json_sdk/exceptions.py +3 -0
- text2json_sdk-0.1.0/text2json_sdk.egg-info/PKG-INFO +156 -0
- text2json_sdk-0.1.0/text2json_sdk.egg-info/SOURCES.txt +9 -0
- text2json_sdk-0.1.0/text2json_sdk.egg-info/dependency_links.txt +1 -0
- text2json_sdk-0.1.0/text2json_sdk.egg-info/top_level.txt +2 -0
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: text2json-sdk
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Convert structured text data into JSON easily
|
|
5
|
+
Author-email: Gautam-Shah <gautm.shah1404@gmail.com>
|
|
6
|
+
Requires-Python: >=3.8
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
|
|
9
|
+
# Text2JSON SDK
|
|
10
|
+
|
|
11
|
+
A lightweight Python SDK to convert structured text (list-based data) into clean JSON format using predefined keys.
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## ๐ Installation
|
|
16
|
+
|
|
17
|
+
Install from PyPI:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
pip install text2json-sdk
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## ๐ Quick Start
|
|
26
|
+
|
|
27
|
+
```python
|
|
28
|
+
from text2json_sdk import Text2JSON
|
|
29
|
+
|
|
30
|
+
keys = ["Name", "Enrollment", "Department", "Location"]
|
|
31
|
+
|
|
32
|
+
data = [
|
|
33
|
+
["Gautam", "001", "Production", "Pune"],
|
|
34
|
+
["Dhruv", "002", "Production", "Gujarat"]
|
|
35
|
+
]
|
|
36
|
+
|
|
37
|
+
converter = Text2JSON(keys)
|
|
38
|
+
|
|
39
|
+
# Get Python object
|
|
40
|
+
result = converter.fill(data)
|
|
41
|
+
print(result)
|
|
42
|
+
|
|
43
|
+
# Get JSON string
|
|
44
|
+
json_result = converter.fill(data, as_json=True)
|
|
45
|
+
print(json_result)
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
## ๐ง How It Works
|
|
51
|
+
|
|
52
|
+
1. Define a list of keys (schema)
|
|
53
|
+
2. Provide structured data as list of rows
|
|
54
|
+
3. SDK maps each row to keys
|
|
55
|
+
4. Returns JSON-ready output
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
## ๐ฆ Example Output
|
|
60
|
+
|
|
61
|
+
```json
|
|
62
|
+
[
|
|
63
|
+
{
|
|
64
|
+
"Name": "Gautam",
|
|
65
|
+
"Enrollment": "001",
|
|
66
|
+
"Department": "Production",
|
|
67
|
+
"Location": "Pune"
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
"Name": "Dhruv",
|
|
71
|
+
"Enrollment": "002",
|
|
72
|
+
"Department": "Production",
|
|
73
|
+
"Location": "Gujarat"
|
|
74
|
+
}
|
|
75
|
+
]
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
## โ
Features
|
|
81
|
+
|
|
82
|
+
- Simple and intuitive API
|
|
83
|
+
- Converts list-based data into structured JSON
|
|
84
|
+
- Handles missing values automatically
|
|
85
|
+
- Input validation with clear errors
|
|
86
|
+
- Optional JSON string output
|
|
87
|
+
|
|
88
|
+
---
|
|
89
|
+
|
|
90
|
+
## โ ๏ธ Error Handling
|
|
91
|
+
|
|
92
|
+
The SDK raises `StructureError` in the following cases:
|
|
93
|
+
|
|
94
|
+
- Keys are not a list of strings
|
|
95
|
+
- Keys list is empty
|
|
96
|
+
- Data is not a list of lists
|
|
97
|
+
- Row contains too many values
|
|
98
|
+
- Row format is invalid
|
|
99
|
+
|
|
100
|
+
Example:
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
from text2json_sdk import Text2JSON
|
|
104
|
+
from text2json_sdk.exceptions import StructureError
|
|
105
|
+
|
|
106
|
+
try:
|
|
107
|
+
converter = Text2JSON(["Name", "Age"])
|
|
108
|
+
converter.fill([["Alice", 25, "Extra"]])
|
|
109
|
+
except StructureError as e:
|
|
110
|
+
print(e)
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
## ๐งช Development Setup
|
|
116
|
+
|
|
117
|
+
Clone the repository and install locally:
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
git clone <your-repo-url>
|
|
121
|
+
cd text2json_sdk
|
|
122
|
+
pip install -e .
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
Run tests (if added):
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
pytest
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
---
|
|
132
|
+
|
|
133
|
+
## Upload to PyPI:
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
twine upload dist/*
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
---
|
|
140
|
+
|
|
141
|
+
## ๐ Future Improvements
|
|
142
|
+
|
|
143
|
+
- CSV file support
|
|
144
|
+
- CLI tool (`text2json file.csv`)
|
|
145
|
+
- Schema validation
|
|
146
|
+
- Async support
|
|
147
|
+
- Integration with pandas
|
|
148
|
+
|
|
149
|
+
---
|
|
150
|
+
|
|
151
|
+
## ๐ก Philosophy
|
|
152
|
+
|
|
153
|
+
This SDK focuses on simplicity and developer experience:
|
|
154
|
+
|
|
155
|
+
> "Make structured data transformation effortless and readable."
|
|
156
|
+
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
# Text2JSON SDK
|
|
2
|
+
|
|
3
|
+
A lightweight Python SDK to convert structured text (list-based data) into clean JSON format using predefined keys.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## ๐ Installation
|
|
8
|
+
|
|
9
|
+
Install from PyPI:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pip install text2json-sdk
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## ๐ Quick Start
|
|
18
|
+
|
|
19
|
+
```python
|
|
20
|
+
from text2json_sdk import Text2JSON
|
|
21
|
+
|
|
22
|
+
keys = ["Name", "Enrollment", "Department", "Location"]
|
|
23
|
+
|
|
24
|
+
data = [
|
|
25
|
+
["Gautam", "001", "Production", "Pune"],
|
|
26
|
+
["Dhruv", "002", "Production", "Gujarat"]
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
converter = Text2JSON(keys)
|
|
30
|
+
|
|
31
|
+
# Get Python object
|
|
32
|
+
result = converter.fill(data)
|
|
33
|
+
print(result)
|
|
34
|
+
|
|
35
|
+
# Get JSON string
|
|
36
|
+
json_result = converter.fill(data, as_json=True)
|
|
37
|
+
print(json_result)
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## ๐ง How It Works
|
|
43
|
+
|
|
44
|
+
1. Define a list of keys (schema)
|
|
45
|
+
2. Provide structured data as list of rows
|
|
46
|
+
3. SDK maps each row to keys
|
|
47
|
+
4. Returns JSON-ready output
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
## ๐ฆ Example Output
|
|
52
|
+
|
|
53
|
+
```json
|
|
54
|
+
[
|
|
55
|
+
{
|
|
56
|
+
"Name": "Gautam",
|
|
57
|
+
"Enrollment": "001",
|
|
58
|
+
"Department": "Production",
|
|
59
|
+
"Location": "Pune"
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
"Name": "Dhruv",
|
|
63
|
+
"Enrollment": "002",
|
|
64
|
+
"Department": "Production",
|
|
65
|
+
"Location": "Gujarat"
|
|
66
|
+
}
|
|
67
|
+
]
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
## โ
Features
|
|
73
|
+
|
|
74
|
+
- Simple and intuitive API
|
|
75
|
+
- Converts list-based data into structured JSON
|
|
76
|
+
- Handles missing values automatically
|
|
77
|
+
- Input validation with clear errors
|
|
78
|
+
- Optional JSON string output
|
|
79
|
+
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
## โ ๏ธ Error Handling
|
|
83
|
+
|
|
84
|
+
The SDK raises `StructureError` in the following cases:
|
|
85
|
+
|
|
86
|
+
- Keys are not a list of strings
|
|
87
|
+
- Keys list is empty
|
|
88
|
+
- Data is not a list of lists
|
|
89
|
+
- Row contains too many values
|
|
90
|
+
- Row format is invalid
|
|
91
|
+
|
|
92
|
+
Example:
|
|
93
|
+
|
|
94
|
+
```python
|
|
95
|
+
from text2json_sdk import Text2JSON
|
|
96
|
+
from text2json_sdk.exceptions import StructureError
|
|
97
|
+
|
|
98
|
+
try:
|
|
99
|
+
converter = Text2JSON(["Name", "Age"])
|
|
100
|
+
converter.fill([["Alice", 25, "Extra"]])
|
|
101
|
+
except StructureError as e:
|
|
102
|
+
print(e)
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
---
|
|
106
|
+
|
|
107
|
+
## ๐งช Development Setup
|
|
108
|
+
|
|
109
|
+
Clone the repository and install locally:
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
git clone <your-repo-url>
|
|
113
|
+
cd text2json_sdk
|
|
114
|
+
pip install -e .
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Run tests (if added):
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
pytest
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
---
|
|
124
|
+
|
|
125
|
+
## Upload to PyPI:
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
twine upload dist/*
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
---
|
|
132
|
+
|
|
133
|
+
## ๐ Future Improvements
|
|
134
|
+
|
|
135
|
+
- CSV file support
|
|
136
|
+
- CLI tool (`text2json file.csv`)
|
|
137
|
+
- Schema validation
|
|
138
|
+
- Async support
|
|
139
|
+
- Integration with pandas
|
|
140
|
+
|
|
141
|
+
---
|
|
142
|
+
|
|
143
|
+
## ๐ก Philosophy
|
|
144
|
+
|
|
145
|
+
This SDK focuses on simplicity and developer experience:
|
|
146
|
+
|
|
147
|
+
> "Make structured data transformation effortless and readable."
|
|
148
|
+
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "text2json-sdk"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Convert structured text data into JSON easily"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.8"
|
|
7
|
+
authors = [
|
|
8
|
+
{ name = "Gautam-Shah", email = "gautm.shah1404@gmail.com" }
|
|
9
|
+
]
|
|
10
|
+
dependencies = []
|
|
11
|
+
|
|
12
|
+
[build-system]
|
|
13
|
+
requires = ["setuptools>=61.0"]
|
|
14
|
+
build-backend = "setuptools.build_meta"
|
|
15
|
+
|
|
16
|
+
[tool.setuptools.packages.find]
|
|
17
|
+
where = ["."]
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import json
|
|
2
|
+
from typing import List, Any
|
|
3
|
+
|
|
4
|
+
from .exceptions import StructureError
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class Text2JSON:
|
|
8
|
+
"""
|
|
9
|
+
Convert structured list data into JSON using predefined keys.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
def __init__(self, keys: List[str]):
|
|
13
|
+
if not isinstance(keys, list) or not all(isinstance(k, str) for k in keys):
|
|
14
|
+
raise StructureError("Keys must be a list of strings")
|
|
15
|
+
|
|
16
|
+
if len(keys) == 0:
|
|
17
|
+
raise StructureError("Keys list cannot be empty")
|
|
18
|
+
|
|
19
|
+
self.keys = [k.strip() for k in keys]
|
|
20
|
+
|
|
21
|
+
def fill(self, data: List[List[Any]], as_json: bool = False):
|
|
22
|
+
"""
|
|
23
|
+
Convert list of rows into structured JSON.
|
|
24
|
+
|
|
25
|
+
:param data: List of lists (rows)
|
|
26
|
+
:param as_json: If True, returns JSON string instead of Python object
|
|
27
|
+
:return: List of dictionaries OR JSON string
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
if not isinstance(data, list):
|
|
31
|
+
raise StructureError("Data must be a list of lists")
|
|
32
|
+
|
|
33
|
+
result = []
|
|
34
|
+
|
|
35
|
+
for idx, row in enumerate(data):
|
|
36
|
+
if not isinstance(row, list):
|
|
37
|
+
raise StructureError(f"Row {idx} is not a list")
|
|
38
|
+
|
|
39
|
+
# Normalize row values
|
|
40
|
+
row = [str(item).strip() for item in row]
|
|
41
|
+
|
|
42
|
+
# Handle missing values
|
|
43
|
+
if len(row) < len(self.keys):
|
|
44
|
+
row += [None] * (len(self.keys) - len(row))
|
|
45
|
+
|
|
46
|
+
# Handle extra values
|
|
47
|
+
if len(row) > len(self.keys):
|
|
48
|
+
raise StructureError(
|
|
49
|
+
f"Row {idx} has too many values. Expected {len(self.keys)}, got {len(row)}"
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
obj = dict(zip(self.keys, row))
|
|
53
|
+
result.append(obj)
|
|
54
|
+
|
|
55
|
+
return json.dumps(result, indent=2) if as_json else result
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: text2json-sdk
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Convert structured text data into JSON easily
|
|
5
|
+
Author-email: Gautam-Shah <gautm.shah1404@gmail.com>
|
|
6
|
+
Requires-Python: >=3.8
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
|
|
9
|
+
# Text2JSON SDK
|
|
10
|
+
|
|
11
|
+
A lightweight Python SDK to convert structured text (list-based data) into clean JSON format using predefined keys.
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## ๐ Installation
|
|
16
|
+
|
|
17
|
+
Install from PyPI:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
pip install text2json-sdk
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## ๐ Quick Start
|
|
26
|
+
|
|
27
|
+
```python
|
|
28
|
+
from text2json_sdk import Text2JSON
|
|
29
|
+
|
|
30
|
+
keys = ["Name", "Enrollment", "Department", "Location"]
|
|
31
|
+
|
|
32
|
+
data = [
|
|
33
|
+
["Gautam", "001", "Production", "Pune"],
|
|
34
|
+
["Dhruv", "002", "Production", "Gujarat"]
|
|
35
|
+
]
|
|
36
|
+
|
|
37
|
+
converter = Text2JSON(keys)
|
|
38
|
+
|
|
39
|
+
# Get Python object
|
|
40
|
+
result = converter.fill(data)
|
|
41
|
+
print(result)
|
|
42
|
+
|
|
43
|
+
# Get JSON string
|
|
44
|
+
json_result = converter.fill(data, as_json=True)
|
|
45
|
+
print(json_result)
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
## ๐ง How It Works
|
|
51
|
+
|
|
52
|
+
1. Define a list of keys (schema)
|
|
53
|
+
2. Provide structured data as list of rows
|
|
54
|
+
3. SDK maps each row to keys
|
|
55
|
+
4. Returns JSON-ready output
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
## ๐ฆ Example Output
|
|
60
|
+
|
|
61
|
+
```json
|
|
62
|
+
[
|
|
63
|
+
{
|
|
64
|
+
"Name": "Gautam",
|
|
65
|
+
"Enrollment": "001",
|
|
66
|
+
"Department": "Production",
|
|
67
|
+
"Location": "Pune"
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
"Name": "Dhruv",
|
|
71
|
+
"Enrollment": "002",
|
|
72
|
+
"Department": "Production",
|
|
73
|
+
"Location": "Gujarat"
|
|
74
|
+
}
|
|
75
|
+
]
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
## โ
Features
|
|
81
|
+
|
|
82
|
+
- Simple and intuitive API
|
|
83
|
+
- Converts list-based data into structured JSON
|
|
84
|
+
- Handles missing values automatically
|
|
85
|
+
- Input validation with clear errors
|
|
86
|
+
- Optional JSON string output
|
|
87
|
+
|
|
88
|
+
---
|
|
89
|
+
|
|
90
|
+
## โ ๏ธ Error Handling
|
|
91
|
+
|
|
92
|
+
The SDK raises `StructureError` in the following cases:
|
|
93
|
+
|
|
94
|
+
- Keys are not a list of strings
|
|
95
|
+
- Keys list is empty
|
|
96
|
+
- Data is not a list of lists
|
|
97
|
+
- Row contains too many values
|
|
98
|
+
- Row format is invalid
|
|
99
|
+
|
|
100
|
+
Example:
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
from text2json_sdk import Text2JSON
|
|
104
|
+
from text2json_sdk.exceptions import StructureError
|
|
105
|
+
|
|
106
|
+
try:
|
|
107
|
+
converter = Text2JSON(["Name", "Age"])
|
|
108
|
+
converter.fill([["Alice", 25, "Extra"]])
|
|
109
|
+
except StructureError as e:
|
|
110
|
+
print(e)
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
## ๐งช Development Setup
|
|
116
|
+
|
|
117
|
+
Clone the repository and install locally:
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
git clone <your-repo-url>
|
|
121
|
+
cd text2json_sdk
|
|
122
|
+
pip install -e .
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
Run tests (if added):
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
pytest
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
---
|
|
132
|
+
|
|
133
|
+
## Upload to PyPI:
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
twine upload dist/*
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
---
|
|
140
|
+
|
|
141
|
+
## ๐ Future Improvements
|
|
142
|
+
|
|
143
|
+
- CSV file support
|
|
144
|
+
- CLI tool (`text2json file.csv`)
|
|
145
|
+
- Schema validation
|
|
146
|
+
- Async support
|
|
147
|
+
- Integration with pandas
|
|
148
|
+
|
|
149
|
+
---
|
|
150
|
+
|
|
151
|
+
## ๐ก Philosophy
|
|
152
|
+
|
|
153
|
+
This SDK focuses on simplicity and developer experience:
|
|
154
|
+
|
|
155
|
+
> "Make structured data transformation effortless and readable."
|
|
156
|
+
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
pyproject.toml
|
|
3
|
+
text2json_sdk/__init__.py
|
|
4
|
+
text2json_sdk/core.py
|
|
5
|
+
text2json_sdk/exceptions.py
|
|
6
|
+
text2json_sdk.egg-info/PKG-INFO
|
|
7
|
+
text2json_sdk.egg-info/SOURCES.txt
|
|
8
|
+
text2json_sdk.egg-info/dependency_links.txt
|
|
9
|
+
text2json_sdk.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|