string-schema 0.1.2__py3-none-any.whl → 0.1.4__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.
- string_schema/core/__init__.py +23 -0
- string_schema/core/builders.py +244 -0
- string_schema/core/fields.py +138 -0
- string_schema/core/validators.py +242 -0
- string_schema/examples/__init__.py +36 -0
- string_schema/examples/presets.py +345 -0
- string_schema/examples/recipes.py +380 -0
- string_schema/integrations/__init__.py +15 -0
- string_schema/integrations/json_schema.py +385 -0
- string_schema/integrations/openapi.py +484 -0
- string_schema/integrations/pydantic.py +662 -0
- string_schema/integrations/reverse.py +275 -0
- string_schema/parsing/__init__.py +16 -0
- string_schema/parsing/optimizer.py +246 -0
- string_schema/parsing/string_parser.py +703 -0
- string_schema/parsing/syntax.py +250 -0
- string_schema/utilities.py +3 -3
- {string_schema-0.1.2.dist-info → string_schema-0.1.4.dist-info}/METADATA +1 -1
- string_schema-0.1.4.dist-info/RECORD +24 -0
- string_schema-0.1.2.dist-info/RECORD +0 -8
- {string_schema-0.1.2.dist-info → string_schema-0.1.4.dist-info}/WHEEL +0 -0
- {string_schema-0.1.2.dist-info → string_schema-0.1.4.dist-info}/licenses/LICENSE +0 -0
- {string_schema-0.1.2.dist-info → string_schema-0.1.4.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Syntax definitions and examples for String Schema string parsing
|
|
3
|
+
|
|
4
|
+
Contains examples and documentation for the string-based schema syntax.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from typing import Dict, Any
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
# Enhanced examples with all new features
|
|
11
|
+
STRING_SCHEMA_EXAMPLES = {
|
|
12
|
+
"simple_arrays": {
|
|
13
|
+
"description": "Simple arrays of basic types (FIXED BUG!)",
|
|
14
|
+
"schema_string": "[string]",
|
|
15
|
+
"prompt_example": "Extract tags: python, javascript, react, vue"
|
|
16
|
+
},
|
|
17
|
+
|
|
18
|
+
"typed_arrays": {
|
|
19
|
+
"description": "Arrays with specific types",
|
|
20
|
+
"schema_string": "[email]",
|
|
21
|
+
"prompt_example": "Extract emails: john@example.com, jane@company.org"
|
|
22
|
+
},
|
|
23
|
+
|
|
24
|
+
"constrained_arrays": {
|
|
25
|
+
"description": "Arrays with size constraints",
|
|
26
|
+
"schema_string": "[string](max=5)",
|
|
27
|
+
"prompt_example": "Extract up to 5 tags: python, machine learning, AI, data science"
|
|
28
|
+
},
|
|
29
|
+
|
|
30
|
+
"object_arrays": {
|
|
31
|
+
"description": "Arrays of objects with constraints",
|
|
32
|
+
"schema_string": "[{name:string, email:email}](min=1,max=10)",
|
|
33
|
+
"prompt_example": "Extract contacts: John Doe (john@example.com), Jane Smith (jane@company.org)"
|
|
34
|
+
},
|
|
35
|
+
|
|
36
|
+
"special_types": {
|
|
37
|
+
"description": "Special type hints for LLMs",
|
|
38
|
+
"schema_string": "name:string, email:email, website:url?, created:datetime",
|
|
39
|
+
"prompt_example": "User: John Doe, email john@example.com, website https://johndoe.com, created 2024-01-15"
|
|
40
|
+
},
|
|
41
|
+
|
|
42
|
+
"enums": {
|
|
43
|
+
"description": "Enum types for clear choices",
|
|
44
|
+
"schema_string": "name:string, status:enum(active,inactive,pending), priority:choice(low,medium,high)",
|
|
45
|
+
"prompt_example": "Task: Fix bug, status active, priority high"
|
|
46
|
+
},
|
|
47
|
+
|
|
48
|
+
"union_types": {
|
|
49
|
+
"description": "Union types for flexible data",
|
|
50
|
+
"schema_string": "id:string|uuid, value:string|int, content:string|null",
|
|
51
|
+
"prompt_example": "Record: id abc123, value 42, content null"
|
|
52
|
+
},
|
|
53
|
+
|
|
54
|
+
"nested_objects": {
|
|
55
|
+
"description": "Complex nested structures",
|
|
56
|
+
"schema_string": "{user:{name:string, contact:{email:email, phones:[phone]?}}, metadata:{created:datetime, tags:[string](max=5)?}}",
|
|
57
|
+
"prompt_example": "User John Doe, email john@example.com, phone +1-555-0123, created 2024-01-15, tags: developer, python"
|
|
58
|
+
},
|
|
59
|
+
|
|
60
|
+
"comprehensive_example": {
|
|
61
|
+
"description": "All features combined",
|
|
62
|
+
"schema_string": "[{name:string(min=1,max=100), emails:[email](min=1,max=2), role:enum(admin,user,guest), profile:{bio:text?, social:[url]?}?, active:bool, last_login:datetime?}](min=1,max=20)",
|
|
63
|
+
"prompt_example": "Users: John Doe (john@example.com, admin, active, last login 2024-01-15), Jane Smith (jane@company.org, user, bio: Developer)"
|
|
64
|
+
},
|
|
65
|
+
|
|
66
|
+
"alternative_syntax": {
|
|
67
|
+
"description": "Alternative array syntax",
|
|
68
|
+
"schema_string": "tags:array(string,max=5), contacts:list(email,min=1)",
|
|
69
|
+
"prompt_example": "Tags: python, react, nodejs. Contacts: john@example.com, jane@company.org"
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def get_string_schema_examples() -> Dict[str, Dict[str, Any]]:
|
|
75
|
+
"""Get all enhanced string schema examples"""
|
|
76
|
+
return STRING_SCHEMA_EXAMPLES.copy()
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def print_string_schema_examples():
|
|
80
|
+
"""Print all enhanced string schema examples with new features"""
|
|
81
|
+
print("🚀 Enhanced String Schema Examples:")
|
|
82
|
+
print("=" * 60)
|
|
83
|
+
|
|
84
|
+
for name, example in STRING_SCHEMA_EXAMPLES.items():
|
|
85
|
+
print(f"\n📝 {name.upper().replace('_', ' ')}")
|
|
86
|
+
print(f"Description: {example['description']}")
|
|
87
|
+
print(f"Schema: {example['schema_string']}")
|
|
88
|
+
print(f"Prompt: {example['prompt_example']}")
|
|
89
|
+
print("-" * 40)
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def get_syntax_help() -> str:
|
|
93
|
+
"""Get comprehensive syntax help for string schemas"""
|
|
94
|
+
return """
|
|
95
|
+
🚀 String Schema String Syntax Guide
|
|
96
|
+
|
|
97
|
+
## Basic Types
|
|
98
|
+
- string, str, text → String type
|
|
99
|
+
- int, integer → Integer type
|
|
100
|
+
- number, float → Number type
|
|
101
|
+
- bool, boolean → Boolean type
|
|
102
|
+
|
|
103
|
+
## Special Types (with format hints)
|
|
104
|
+
- email → Email validation
|
|
105
|
+
- url, uri → URL validation
|
|
106
|
+
- datetime → DateTime parsing
|
|
107
|
+
- date → Date parsing
|
|
108
|
+
- uuid → UUID validation
|
|
109
|
+
- phone → Phone formatting
|
|
110
|
+
|
|
111
|
+
## Field Definitions
|
|
112
|
+
- name → String field (default)
|
|
113
|
+
- name:string → Explicit string field
|
|
114
|
+
- age:int → Integer field
|
|
115
|
+
- email:email → Email field with validation
|
|
116
|
+
- website:url? → Optional URL field
|
|
117
|
+
|
|
118
|
+
## Arrays
|
|
119
|
+
- [string] → Array of strings
|
|
120
|
+
- [email] → Array of emails
|
|
121
|
+
- [int] → Array of integers
|
|
122
|
+
- [{name, email}] → Array of objects
|
|
123
|
+
|
|
124
|
+
## Array Constraints
|
|
125
|
+
- [string](max=5) → Max 5 items
|
|
126
|
+
- [email](min=1,max=3) → 1-3 items required
|
|
127
|
+
- [{name,email}](min=1,max=10) → 1-10 objects
|
|
128
|
+
|
|
129
|
+
## Alternative Array Syntax
|
|
130
|
+
- tags:array(string,max=5) → Array with constraints
|
|
131
|
+
- contacts:list(email,min=1) → List with constraints
|
|
132
|
+
|
|
133
|
+
## Enums
|
|
134
|
+
- status:enum(active,inactive,pending)
|
|
135
|
+
- priority:choice(low,medium,high)
|
|
136
|
+
- category:select(tech,business,personal)
|
|
137
|
+
|
|
138
|
+
## Union Types
|
|
139
|
+
- id:string|uuid → String or UUID
|
|
140
|
+
- value:string|int → String or integer
|
|
141
|
+
- response:string|null → Nullable field
|
|
142
|
+
|
|
143
|
+
## Constraints
|
|
144
|
+
- name:string(min=1,max=100) → String length
|
|
145
|
+
- age:int(min=0,max=120) → Integer range
|
|
146
|
+
- rating:float(min=1.0,max=5.0) → Float range
|
|
147
|
+
|
|
148
|
+
## Objects
|
|
149
|
+
- {name:string, age:int} → Simple object
|
|
150
|
+
- user:{name, email, phone?} → Nested object
|
|
151
|
+
|
|
152
|
+
## Complex Examples
|
|
153
|
+
```
|
|
154
|
+
# E-commerce product
|
|
155
|
+
{
|
|
156
|
+
name:string(min=1,max=200),
|
|
157
|
+
price:number(min=0),
|
|
158
|
+
category:enum(electronics,clothing,books),
|
|
159
|
+
images:[url](max=5)?,
|
|
160
|
+
reviews:[{rating:int(1,5), comment:text}](max=10)?
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
# User management
|
|
164
|
+
[{
|
|
165
|
+
id:string|uuid,
|
|
166
|
+
profile:{name:string, email:email, phone:phone?},
|
|
167
|
+
status:enum(active,inactive,suspended),
|
|
168
|
+
permissions:[string]?
|
|
169
|
+
}](min=1,max=100)
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
## Tips
|
|
173
|
+
- Use ? for optional fields
|
|
174
|
+
- Add constraints for better LLM guidance
|
|
175
|
+
- Use special types for validation
|
|
176
|
+
- Combine features for complex schemas
|
|
177
|
+
"""
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
def validate_syntax_example(example_name: str) -> bool:
|
|
181
|
+
"""Validate that a syntax example is properly formatted"""
|
|
182
|
+
if example_name not in STRING_SCHEMA_EXAMPLES:
|
|
183
|
+
return False
|
|
184
|
+
|
|
185
|
+
example = STRING_SCHEMA_EXAMPLES[example_name]
|
|
186
|
+
required_keys = ['description', 'schema_string', 'prompt_example']
|
|
187
|
+
|
|
188
|
+
return all(key in example for key in required_keys)
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
def get_syntax_patterns() -> Dict[str, str]:
|
|
192
|
+
"""Get common syntax patterns for reference"""
|
|
193
|
+
return {
|
|
194
|
+
"simple_field": "name:type",
|
|
195
|
+
"optional_field": "name:type?",
|
|
196
|
+
"constrained_field": "name:type(min=1,max=100)",
|
|
197
|
+
"enum_field": "name:enum(value1,value2,value3)",
|
|
198
|
+
"union_field": "name:type1|type2|type3",
|
|
199
|
+
"simple_array": "[type]",
|
|
200
|
+
"constrained_array": "[type](min=1,max=5)",
|
|
201
|
+
"object_array": "[{field1:type1, field2:type2}]",
|
|
202
|
+
"nested_object": "name:{field1:type1, field2:type2}",
|
|
203
|
+
"alternative_array": "name:array(type,max=5)"
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
# Built-in enhanced schema generators for string syntax
|
|
208
|
+
def user_string_schema(include_email: bool = True, include_phone: bool = False,
|
|
209
|
+
include_profile: bool = False) -> str:
|
|
210
|
+
"""Generate enhanced user schema string"""
|
|
211
|
+
parts = ["name:string(min=1,max=100)", "age:int(min=13,max=120)"]
|
|
212
|
+
|
|
213
|
+
if include_email:
|
|
214
|
+
parts.append("email:email")
|
|
215
|
+
if include_phone:
|
|
216
|
+
parts.append("phone:phone?")
|
|
217
|
+
if include_profile:
|
|
218
|
+
parts.append("bio:text(max=500)?")
|
|
219
|
+
parts.append("avatar:url?")
|
|
220
|
+
|
|
221
|
+
return ", ".join(parts)
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
def product_string_schema(include_price: bool = True, include_description: bool = True,
|
|
225
|
+
include_images: bool = False, include_reviews: bool = False) -> str:
|
|
226
|
+
"""Generate enhanced product schema string"""
|
|
227
|
+
parts = ["name:string(min=1,max=200)", "category:enum(electronics,clothing,books,home,sports)"]
|
|
228
|
+
|
|
229
|
+
if include_price:
|
|
230
|
+
parts.append("price:number(min=0)")
|
|
231
|
+
if include_description:
|
|
232
|
+
parts.append("description:text(max=1000)?")
|
|
233
|
+
if include_images:
|
|
234
|
+
parts.append("images:[url](max=5)?")
|
|
235
|
+
if include_reviews:
|
|
236
|
+
parts.append("reviews:[{rating:int(1,5), comment:text(max=500)}](max=10)?")
|
|
237
|
+
|
|
238
|
+
return ", ".join(parts)
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
def contact_string_schema(include_company: bool = False, include_social: bool = False) -> str:
|
|
242
|
+
"""Generate enhanced contact schema string"""
|
|
243
|
+
parts = ["name:string(min=1,max=100)", "emails:[email](min=1,max=3)", "phones:[phone]?"]
|
|
244
|
+
|
|
245
|
+
if include_company:
|
|
246
|
+
parts.append("company:{name:string, role:string?, department:string?}?")
|
|
247
|
+
if include_social:
|
|
248
|
+
parts.append("social:{linkedin:url?, twitter:url?, github:url?}?")
|
|
249
|
+
|
|
250
|
+
return ", ".join(parts)
|
string_schema/utilities.py
CHANGED
|
@@ -93,7 +93,7 @@ def string_to_model(schema_str: str, name: Optional[str] = None) -> Type[BaseMod
|
|
|
93
93
|
if items_schema.get('type') == 'object':
|
|
94
94
|
# Array of objects: create nested model for items
|
|
95
95
|
from .integrations.pydantic import create_pydantic_from_json_schema
|
|
96
|
-
ItemModel = create_pydantic_from_json_schema(f"{name}Item"
|
|
96
|
+
ItemModel = create_pydantic_from_json_schema(items_schema, f"{name}Item")
|
|
97
97
|
|
|
98
98
|
# Create the array model using RootModel
|
|
99
99
|
class ArrayModel(RootModel[List[ItemModel]]):
|
|
@@ -125,7 +125,7 @@ def string_to_model(schema_str: str, name: Optional[str] = None) -> Type[BaseMod
|
|
|
125
125
|
if items_schema.get('type') == 'object':
|
|
126
126
|
# Array of objects: create nested model for items
|
|
127
127
|
from .integrations.pydantic import create_pydantic_from_json_schema
|
|
128
|
-
ItemModel = create_pydantic_from_json_schema(f"{name}Item"
|
|
128
|
+
ItemModel = create_pydantic_from_json_schema(items_schema, f"{name}Item")
|
|
129
129
|
|
|
130
130
|
# Create constraints for the array
|
|
131
131
|
constraints = {}
|
|
@@ -159,7 +159,7 @@ def string_to_model(schema_str: str, name: Optional[str] = None) -> Type[BaseMod
|
|
|
159
159
|
else:
|
|
160
160
|
# Regular object schema
|
|
161
161
|
from .integrations.pydantic import create_pydantic_from_json_schema
|
|
162
|
-
return create_pydantic_from_json_schema(
|
|
162
|
+
return create_pydantic_from_json_schema(json_schema, name)
|
|
163
163
|
|
|
164
164
|
except Exception as e:
|
|
165
165
|
raise ValueError(f"Failed to create model from schema '{schema_str}': {str(e)}") from e
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
string_schema/__init__.py,sha256=J0_B0TNO0AK_piEcT5gFFHllywjx16DTP59ps_Fp-WU,4052
|
|
2
|
+
string_schema/py.typed,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
|
3
|
+
string_schema/utilities.py,sha256=iLyqCKFd0qTL13xyZvt3Dia2-gjZCjHyDVVm59GxLK4,19918
|
|
4
|
+
string_schema/core/__init__.py,sha256=jeukkZ1WoCSXrBafumHVH2GkCJ6QjnkH_jAr3DESFio,481
|
|
5
|
+
string_schema/core/builders.py,sha256=AHDTqtCnSe5ZN-DwedisqXqktjgl6nypd-mebucjI3k,7809
|
|
6
|
+
string_schema/core/fields.py,sha256=iLUR-w3pZCr7OkQHhb2DFkVLtObnpyJ_mEUdc0qAqXY,5534
|
|
7
|
+
string_schema/core/validators.py,sha256=6inSZGou0zKpN47ttVWOxWsN-nPN3EewUNRacB9UUkA,8303
|
|
8
|
+
string_schema/examples/__init__.py,sha256=wmdWey3ggt3yXG2XQygfHeghq-P31VdTkoqyki_qY1k,639
|
|
9
|
+
string_schema/examples/presets.py,sha256=T7OQOsvVrPrzS2_1C6Hls17neeIGOBfVs0xOkZehaSQ,14642
|
|
10
|
+
string_schema/examples/recipes.py,sha256=bOX0zH-m5NVYFnfBIGzxag1BpNexe6OPJ55ssn0oZKs,15095
|
|
11
|
+
string_schema/integrations/__init__.py,sha256=yLRtfeVEDntULjMXKv_TWKXh860lKnQzCMMYcZvOr90,323
|
|
12
|
+
string_schema/integrations/json_schema.py,sha256=cNr9chGc5RSfFLNXJCTH1ZOVd91OH9oeaAvf_Nqy8Zs,12627
|
|
13
|
+
string_schema/integrations/openapi.py,sha256=bUHzJWOZEDtXs0R6493jAhA0-PrKwaUTkDW5UWE6-nI,15637
|
|
14
|
+
string_schema/integrations/pydantic.py,sha256=hYrnl2hKcmbp7ypEINqn065dpLaCWxb39T1A8va1YrM,21818
|
|
15
|
+
string_schema/integrations/reverse.py,sha256=qN8OCRjaH0nerZFrljAnvFLjZjo9gln2H-HBiaevLoI,9023
|
|
16
|
+
string_schema/parsing/__init__.py,sha256=dFW68DqJIwP4w_aYaZMjjVK15X7tCv8A0SPqmIgGEjQ,411
|
|
17
|
+
string_schema/parsing/optimizer.py,sha256=Ofte8Tb7sKmdEv7RrVIEBQ4Qqr-Whanp1vh8BakcOgw,8479
|
|
18
|
+
string_schema/parsing/string_parser.py,sha256=-a_143fjNkxcRu24JdpqA6GltR7a_2AUXPNgHsbwYv4,24989
|
|
19
|
+
string_schema/parsing/syntax.py,sha256=RO3BIAnWfDBupowOnoJocHtAe-kwE-SgRWXKknVwGdg,8900
|
|
20
|
+
string_schema-0.1.4.dist-info/licenses/LICENSE,sha256=wCD2KBeSlVSkJy0apl6zmVj04uw97UJhRRi-en_3Qfk,1065
|
|
21
|
+
string_schema-0.1.4.dist-info/METADATA,sha256=Lmn3NN4QK2vRxNZiyqnyc9mAQSwDyAdcWYBkxjdlrm4,18246
|
|
22
|
+
string_schema-0.1.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
23
|
+
string_schema-0.1.4.dist-info/top_level.txt,sha256=1uTmLPYIRrCDVxUW1fDFRMaWvGO48NRcGmbW4oq89I0,14
|
|
24
|
+
string_schema-0.1.4.dist-info/RECORD,,
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
string_schema/__init__.py,sha256=J0_B0TNO0AK_piEcT5gFFHllywjx16DTP59ps_Fp-WU,4052
|
|
2
|
-
string_schema/py.typed,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
|
3
|
-
string_schema/utilities.py,sha256=nrJ7sIcr52eG6ZfgTW1r0_sPny4OS-EU9Rd2KqGfu3s,19918
|
|
4
|
-
string_schema-0.1.2.dist-info/licenses/LICENSE,sha256=wCD2KBeSlVSkJy0apl6zmVj04uw97UJhRRi-en_3Qfk,1065
|
|
5
|
-
string_schema-0.1.2.dist-info/METADATA,sha256=n-KG5et4L0gd0D154TrL0qVkozKV7o1lvX0qzQEAh7o,18246
|
|
6
|
-
string_schema-0.1.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
7
|
-
string_schema-0.1.2.dist-info/top_level.txt,sha256=1uTmLPYIRrCDVxUW1fDFRMaWvGO48NRcGmbW4oq89I0,14
|
|
8
|
-
string_schema-0.1.2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|