string-schema 0.1.0__tar.gz → 0.1.1__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.
- {string_schema-0.1.0/string_schema.egg-info → string_schema-0.1.1}/PKG-INFO +44 -50
- {string_schema-0.1.0 → string_schema-0.1.1}/README.md +27 -27
- {string_schema-0.1.0 → string_schema-0.1.1}/docs/README.md +5 -5
- {string_schema-0.1.0 → string_schema-0.1.1}/docs/advanced-usage.md +34 -34
- {string_schema-0.1.0 → string_schema-0.1.1}/docs/api-reference.md +18 -18
- {string_schema-0.1.0 → string_schema-0.1.1}/docs/examples.md +11 -11
- {string_schema-0.1.0 → string_schema-0.1.1}/docs/faq.md +27 -20
- {string_schema-0.1.0 → string_schema-0.1.1}/docs/getting-started.md +10 -10
- {string_schema-0.1.0 → string_schema-0.1.1}/docs/pydantic-utilities.md +9 -9
- {string_schema-0.1.0 → string_schema-0.1.1}/docs/string-syntax.md +1 -1
- {string_schema-0.1.0 → string_schema-0.1.1}/docs/troubleshooting.md +44 -18
- {string_schema-0.1.0 → string_schema-0.1.1}/examples/demo.py +26 -22
- {string_schema-0.1.0 → string_schema-0.1.1}/examples/pydantic_utility_demo.py +3 -3
- string_schema-0.1.1/pyproject.toml +146 -0
- {string_schema-0.1.0 → string_schema-0.1.1}/setup.py +11 -13
- {string_schema-0.1.0/simple_schema → string_schema-0.1.1/string_schema}/__init__.py +2 -2
- string_schema-0.1.1/string_schema/py.typed +1 -0
- {string_schema-0.1.0 → string_schema-0.1.1/string_schema.egg-info}/PKG-INFO +44 -50
- string_schema-0.1.1/string_schema.egg-info/SOURCES.txt +24 -0
- {string_schema-0.1.0 → string_schema-0.1.1}/string_schema.egg-info/requires.txt +2 -1
- string_schema-0.1.1/string_schema.egg-info/top_level.txt +1 -0
- string_schema-0.1.0/simple_schema/core/__init__.py +0 -23
- string_schema-0.1.0/simple_schema/core/builders.py +0 -244
- string_schema-0.1.0/simple_schema/core/fields.py +0 -138
- string_schema-0.1.0/simple_schema/core/validators.py +0 -242
- string_schema-0.1.0/simple_schema/examples/__init__.py +0 -36
- string_schema-0.1.0/simple_schema/examples/presets.py +0 -345
- string_schema-0.1.0/simple_schema/examples/recipes.py +0 -380
- string_schema-0.1.0/simple_schema/integrations/__init__.py +0 -15
- string_schema-0.1.0/simple_schema/integrations/json_schema.py +0 -385
- string_schema-0.1.0/simple_schema/integrations/openapi.py +0 -484
- string_schema-0.1.0/simple_schema/integrations/pydantic.py +0 -662
- string_schema-0.1.0/simple_schema/integrations/reverse.py +0 -275
- string_schema-0.1.0/simple_schema/parsing/__init__.py +0 -16
- string_schema-0.1.0/simple_schema/parsing/optimizer.py +0 -246
- string_schema-0.1.0/simple_schema/parsing/string_parser.py +0 -703
- string_schema-0.1.0/simple_schema/parsing/syntax.py +0 -250
- string_schema-0.1.0/string_schema.egg-info/SOURCES.txt +0 -38
- string_schema-0.1.0/string_schema.egg-info/top_level.txt +0 -2
- {string_schema-0.1.0 → string_schema-0.1.1}/LICENSE +0 -0
- {string_schema-0.1.0 → string_schema-0.1.1}/MANIFEST.in +0 -0
- {string_schema-0.1.0 → string_schema-0.1.1}/setup.cfg +0 -0
- {string_schema-0.1.0/simple_schema → string_schema-0.1.1/string_schema}/utilities.py +0 -0
- {string_schema-0.1.0 → string_schema-0.1.1}/string_schema.egg-info/dependency_links.txt +0 -0
|
@@ -1,33 +1,35 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: string-schema
|
|
3
|
-
Version: 0.1.
|
|
4
|
-
Summary: A simple, LLM-friendly schema definition library
|
|
5
|
-
Home-page: https://github.com/xychenmsn/
|
|
6
|
-
Author:
|
|
7
|
-
Author-email: xychen@msn.com
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
Project-URL:
|
|
11
|
-
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: A simple, LLM-friendly schema definition library for converting string syntax to structured schemas
|
|
5
|
+
Home-page: https://github.com/xychenmsn/string-schema
|
|
6
|
+
Author: Michael Chen
|
|
7
|
+
Author-email: Michael Chen <xychen@msn.com>
|
|
8
|
+
Maintainer-email: Michael Chen <xychen@msn.com>
|
|
9
|
+
License: MIT
|
|
10
|
+
Project-URL: Homepage, https://github.com/xychenmsn/string-schema
|
|
11
|
+
Project-URL: Documentation, https://github.com/xychenmsn/string-schema#readme
|
|
12
|
+
Project-URL: Repository, https://github.com/xychenmsn/string-schema
|
|
13
|
+
Project-URL: Bug Reports, https://github.com/xychenmsn/string-schema/issues
|
|
14
|
+
Project-URL: Changelog, https://github.com/xychenmsn/string-schema/releases
|
|
15
|
+
Keywords: schema,validation,json,llm,ai,data-extraction,pydantic
|
|
12
16
|
Classifier: Development Status :: 3 - Alpha
|
|
13
17
|
Classifier: Intended Audience :: Developers
|
|
14
18
|
Classifier: License :: OSI Approved :: MIT License
|
|
15
19
|
Classifier: Operating System :: OS Independent
|
|
16
20
|
Classifier: Programming Language :: Python :: 3
|
|
17
|
-
Classifier: Programming Language :: Python :: 3.8
|
|
18
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
19
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
20
21
|
Classifier: Programming Language :: Python :: 3.11
|
|
21
22
|
Classifier: Programming Language :: Python :: 3.12
|
|
22
23
|
Classifier: Programming Language :: Python :: 3.13
|
|
23
24
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
24
25
|
Classifier: Topic :: Text Processing :: Markup
|
|
25
26
|
Classifier: Topic :: Utilities
|
|
26
|
-
|
|
27
|
+
Classifier: Typing :: Typed
|
|
28
|
+
Requires-Python: >=3.11
|
|
27
29
|
Description-Content-Type: text/markdown
|
|
28
30
|
License-File: LICENSE
|
|
29
31
|
Requires-Dist: pydantic>=2.0.0
|
|
30
|
-
Requires-Dist:
|
|
32
|
+
Requires-Dist: email-validator>=2.0.0
|
|
31
33
|
Provides-Extra: dev
|
|
32
34
|
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
33
35
|
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
|
|
@@ -35,25 +37,17 @@ Requires-Dist: black>=22.0.0; extra == "dev"
|
|
|
35
37
|
Requires-Dist: isort>=5.0.0; extra == "dev"
|
|
36
38
|
Requires-Dist: flake8>=5.0.0; extra == "dev"
|
|
37
39
|
Requires-Dist: mypy>=1.0.0; extra == "dev"
|
|
40
|
+
Requires-Dist: pre-commit>=2.20.0; extra == "dev"
|
|
38
41
|
Provides-Extra: docs
|
|
39
42
|
Requires-Dist: sphinx>=5.0.0; extra == "docs"
|
|
40
43
|
Requires-Dist: sphinx-rtd-theme>=1.0.0; extra == "docs"
|
|
41
44
|
Requires-Dist: myst-parser>=0.18.0; extra == "docs"
|
|
42
45
|
Dynamic: author
|
|
43
|
-
Dynamic: author-email
|
|
44
|
-
Dynamic: classifier
|
|
45
|
-
Dynamic: description
|
|
46
|
-
Dynamic: description-content-type
|
|
47
46
|
Dynamic: home-page
|
|
48
|
-
Dynamic: keywords
|
|
49
47
|
Dynamic: license-file
|
|
50
|
-
Dynamic: project-url
|
|
51
|
-
Dynamic: provides-extra
|
|
52
|
-
Dynamic: requires-dist
|
|
53
48
|
Dynamic: requires-python
|
|
54
|
-
Dynamic: summary
|
|
55
49
|
|
|
56
|
-
#
|
|
50
|
+
# String Schema
|
|
57
51
|
|
|
58
52
|
A simple, LLM-friendly schema definition library for Python that converts intuitive string syntax into structured data schemas.
|
|
59
53
|
|
|
@@ -62,13 +56,13 @@ A simple, LLM-friendly schema definition library for Python that converts intuit
|
|
|
62
56
|
### Installation
|
|
63
57
|
|
|
64
58
|
```bash
|
|
65
|
-
pip install
|
|
59
|
+
pip install string-schema
|
|
66
60
|
```
|
|
67
61
|
|
|
68
62
|
### 30-Second Example
|
|
69
63
|
|
|
70
64
|
```python
|
|
71
|
-
from
|
|
65
|
+
from string_schema import string_to_json_schema
|
|
72
66
|
|
|
73
67
|
# Define a schema with simple, readable syntax
|
|
74
68
|
schema = string_to_json_schema("name:string, email:email, age:int?")
|
|
@@ -89,7 +83,7 @@ print(schema)
|
|
|
89
83
|
### Create Pydantic Models Directly
|
|
90
84
|
|
|
91
85
|
```python
|
|
92
|
-
from
|
|
86
|
+
from string_schema import string_to_model
|
|
93
87
|
|
|
94
88
|
# Create Pydantic model from string syntax
|
|
95
89
|
UserModel = string_to_model("name:string, email:email, age:int?")
|
|
@@ -99,9 +93,9 @@ user = UserModel(name="Alice", email="alice@example.com")
|
|
|
99
93
|
print(user.model_dump_json()) # {"name": "Alice", "email": "alice@example.com"}
|
|
100
94
|
```
|
|
101
95
|
|
|
102
|
-
## 🎯 What
|
|
96
|
+
## 🎯 What String Schema Does
|
|
103
97
|
|
|
104
|
-
|
|
98
|
+
String Schema takes human-readable text descriptions and converts them into structured schemas for data validation, extraction, and API documentation. Perfect for LLM data extraction, API development, and configuration validation.
|
|
105
99
|
|
|
106
100
|
**Input:** Human-readable string syntax
|
|
107
101
|
**Output:** JSON Schema, Pydantic models, or OpenAPI specifications
|
|
@@ -164,7 +158,7 @@ Simple Schema takes human-readable text descriptions and converts them into stru
|
|
|
164
158
|
### ✅ Validate Data
|
|
165
159
|
|
|
166
160
|
```python
|
|
167
|
-
from
|
|
161
|
+
from string_schema import validate_to_dict, validate_to_model
|
|
168
162
|
|
|
169
163
|
# Example raw data (from API, user input, etc.)
|
|
170
164
|
raw_data = {
|
|
@@ -187,7 +181,7 @@ print(user_model.age) # 25 - Converted to int
|
|
|
187
181
|
### 🎨 Function Decorators
|
|
188
182
|
|
|
189
183
|
```python
|
|
190
|
-
from
|
|
184
|
+
from string_schema import returns_dict, returns_model
|
|
191
185
|
import uuid
|
|
192
186
|
|
|
193
187
|
# Auto-validate function returns to dicts
|
|
@@ -217,7 +211,7 @@ print(user_model.name) # "Bob" - Full type safety
|
|
|
217
211
|
### 🌐 FastAPI Integration
|
|
218
212
|
|
|
219
213
|
```python
|
|
220
|
-
from
|
|
214
|
+
from string_schema import string_to_model, returns_dict
|
|
221
215
|
|
|
222
216
|
# Create models for FastAPI
|
|
223
217
|
UserRequest = string_to_model("name:string, email:email")
|
|
@@ -237,7 +231,7 @@ def create_user_endpoint(user: UserRequest):
|
|
|
237
231
|
### 🌱 Simple Example - Basic User Data
|
|
238
232
|
|
|
239
233
|
```python
|
|
240
|
-
from
|
|
234
|
+
from string_schema import string_to_json_schema
|
|
241
235
|
|
|
242
236
|
# Define schema using intuitive string syntax
|
|
243
237
|
schema = string_to_json_schema("""
|
|
@@ -289,7 +283,7 @@ print(schema) # Full JSON Schema ready for validation
|
|
|
289
283
|
### 🐍 Pydantic Models (Python Classes)
|
|
290
284
|
|
|
291
285
|
```python
|
|
292
|
-
from
|
|
286
|
+
from string_schema import string_to_model
|
|
293
287
|
|
|
294
288
|
# Direct conversion: String syntax → Pydantic model
|
|
295
289
|
UserModel = string_to_model("name:string, email:email, active:bool")
|
|
@@ -302,7 +296,7 @@ print(user.model_dump_json()) # {"name": "John Doe", "email": "john@example.com
|
|
|
302
296
|
### 🔧 Code Generation (For Templates & Tools)
|
|
303
297
|
|
|
304
298
|
```python
|
|
305
|
-
from
|
|
299
|
+
from string_schema import string_to_model_code
|
|
306
300
|
|
|
307
301
|
# Generate Pydantic model code as a string
|
|
308
302
|
code = string_to_model_code("User", "name:string, email:email, active:bool")
|
|
@@ -325,7 +319,7 @@ with open('models.py', 'w') as f:
|
|
|
325
319
|
### 🌐 OpenAPI Schemas (API Documentation)
|
|
326
320
|
|
|
327
321
|
```python
|
|
328
|
-
from
|
|
322
|
+
from string_schema import string_to_openapi
|
|
329
323
|
|
|
330
324
|
# Direct conversion: String syntax → OpenAPI schema
|
|
331
325
|
openapi_schema = string_to_openapi("name:string, email:email")
|
|
@@ -342,14 +336,14 @@ print(openapi_schema)
|
|
|
342
336
|
|
|
343
337
|
## 🔄 Reverse Conversions (Universal Schema Converter)
|
|
344
338
|
|
|
345
|
-
|
|
339
|
+
String Schema provides complete bidirectional conversion between all schema formats!
|
|
346
340
|
|
|
347
341
|
> **⚠️ Information Loss Notice**: Reverse conversions (from JSON Schema/OpenAPI/Pydantic back to string syntax) may lose some information due to format differences. However, the resulting schemas are designed to cover the most common use cases and maintain functional equivalence for typical validation scenarios.
|
|
348
342
|
|
|
349
343
|
### 🔍 Schema Introspection
|
|
350
344
|
|
|
351
345
|
```python
|
|
352
|
-
from
|
|
346
|
+
from string_schema import model_to_string, string_to_model
|
|
353
347
|
|
|
354
348
|
# Create a model first
|
|
355
349
|
UserModel = string_to_model("name:string, email:email, active:bool")
|
|
@@ -363,9 +357,9 @@ print(f"Model schema: {schema_string}")
|
|
|
363
357
|
### 📦 Migration & Import
|
|
364
358
|
|
|
365
359
|
```python
|
|
366
|
-
from
|
|
360
|
+
from string_schema import json_schema_to_string
|
|
367
361
|
|
|
368
|
-
# Example: Convert existing JSON Schema to
|
|
362
|
+
# Example: Convert existing JSON Schema to String Schema syntax
|
|
369
363
|
json_schema = {
|
|
370
364
|
"type": "object",
|
|
371
365
|
"properties": {
|
|
@@ -384,7 +378,7 @@ print(f"Converted: {simple_syntax}")
|
|
|
384
378
|
### 🔧 Schema Comparison & Analysis
|
|
385
379
|
|
|
386
380
|
```python
|
|
387
|
-
from
|
|
381
|
+
from string_schema import string_to_model, model_to_string
|
|
388
382
|
|
|
389
383
|
# Create two versions of a model
|
|
390
384
|
UserV1 = string_to_model("name:string, email:email")
|
|
@@ -426,7 +420,7 @@ print(f"V2: {v2_str}") # "name:string, email:email, active:bool"
|
|
|
426
420
|
## ✅ Validation
|
|
427
421
|
|
|
428
422
|
```python
|
|
429
|
-
from
|
|
423
|
+
from string_schema import validate_string_syntax
|
|
430
424
|
|
|
431
425
|
# Validate your schema syntax
|
|
432
426
|
result = validate_string_syntax("name:string, email:email, age:int?")
|
|
@@ -446,7 +440,7 @@ print(f"Errors: {bad_result['errors']}") # ['Unknown type: invalid_type']
|
|
|
446
440
|
### 🤖 LLM Data Extraction
|
|
447
441
|
|
|
448
442
|
```python
|
|
449
|
-
from
|
|
443
|
+
from string_schema import string_to_json_schema
|
|
450
444
|
|
|
451
445
|
# Define what data to extract
|
|
452
446
|
schema = string_to_json_schema("company:string, employees:[{name:string, email:email}], founded:int?")
|
|
@@ -456,7 +450,7 @@ schema = string_to_json_schema("company:string, employees:[{name:string, email:e
|
|
|
456
450
|
### 🔧 FastAPI Development
|
|
457
451
|
|
|
458
452
|
```python
|
|
459
|
-
from
|
|
453
|
+
from string_schema import string_to_model
|
|
460
454
|
|
|
461
455
|
# Create model for FastAPI
|
|
462
456
|
UserModel = string_to_model("name:string, email:email")
|
|
@@ -470,7 +464,7 @@ async def create_user(user: UserModel):
|
|
|
470
464
|
### 🏗️ Code Generation & Templates
|
|
471
465
|
|
|
472
466
|
```python
|
|
473
|
-
from
|
|
467
|
+
from string_schema import string_to_model_code
|
|
474
468
|
|
|
475
469
|
# Generate model code
|
|
476
470
|
code = string_to_model_code("User", "name:string, email:email")
|
|
@@ -485,7 +479,7 @@ with open('user_model.py', 'w') as f:
|
|
|
485
479
|
### 📋 Configuration Validation
|
|
486
480
|
|
|
487
481
|
```python
|
|
488
|
-
from
|
|
482
|
+
from string_schema import string_to_json_schema
|
|
489
483
|
|
|
490
484
|
# Validate app configuration
|
|
491
485
|
config_schema = string_to_json_schema("database:{host:string, port:int}, debug:bool")
|
|
@@ -505,8 +499,8 @@ Ready-to-use schema examples are available in the `examples/` directory:
|
|
|
505
499
|
|
|
506
500
|
```python
|
|
507
501
|
# Import example schemas if needed
|
|
508
|
-
from
|
|
509
|
-
from
|
|
502
|
+
from string_schema.examples.presets import user_schema, product_schema
|
|
503
|
+
from string_schema.examples.recipes import create_ecommerce_product_schema
|
|
510
504
|
|
|
511
505
|
# Or better yet, use string syntax directly:
|
|
512
506
|
user_schema = string_to_json_schema("name:string, email:email, age:int?")
|
|
@@ -529,7 +523,7 @@ pytest tests/
|
|
|
529
523
|
Contributions are welcome! The codebase is well-organized and documented:
|
|
530
524
|
|
|
531
525
|
```
|
|
532
|
-
|
|
526
|
+
string_schema/
|
|
533
527
|
├── core/ # Core functionality (fields, builders, validators)
|
|
534
528
|
├── parsing/ # String parsing and syntax
|
|
535
529
|
├── integrations/ # Pydantic, JSON Schema, OpenAPI
|
|
@@ -542,4 +536,4 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
|
|
|
542
536
|
|
|
543
537
|
---
|
|
544
538
|
|
|
545
|
-
**
|
|
539
|
+
**String Schema** - Making data validation simple, intuitive, and LLM-friendly! 🚀
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#
|
|
1
|
+
# String Schema
|
|
2
2
|
|
|
3
3
|
A simple, LLM-friendly schema definition library for Python that converts intuitive string syntax into structured data schemas.
|
|
4
4
|
|
|
@@ -7,13 +7,13 @@ A simple, LLM-friendly schema definition library for Python that converts intuit
|
|
|
7
7
|
### Installation
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
|
-
pip install
|
|
10
|
+
pip install string-schema
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
### 30-Second Example
|
|
14
14
|
|
|
15
15
|
```python
|
|
16
|
-
from
|
|
16
|
+
from string_schema import string_to_json_schema
|
|
17
17
|
|
|
18
18
|
# Define a schema with simple, readable syntax
|
|
19
19
|
schema = string_to_json_schema("name:string, email:email, age:int?")
|
|
@@ -34,7 +34,7 @@ print(schema)
|
|
|
34
34
|
### Create Pydantic Models Directly
|
|
35
35
|
|
|
36
36
|
```python
|
|
37
|
-
from
|
|
37
|
+
from string_schema import string_to_model
|
|
38
38
|
|
|
39
39
|
# Create Pydantic model from string syntax
|
|
40
40
|
UserModel = string_to_model("name:string, email:email, age:int?")
|
|
@@ -44,9 +44,9 @@ user = UserModel(name="Alice", email="alice@example.com")
|
|
|
44
44
|
print(user.model_dump_json()) # {"name": "Alice", "email": "alice@example.com"}
|
|
45
45
|
```
|
|
46
46
|
|
|
47
|
-
## 🎯 What
|
|
47
|
+
## 🎯 What String Schema Does
|
|
48
48
|
|
|
49
|
-
|
|
49
|
+
String Schema takes human-readable text descriptions and converts them into structured schemas for data validation, extraction, and API documentation. Perfect for LLM data extraction, API development, and configuration validation.
|
|
50
50
|
|
|
51
51
|
**Input:** Human-readable string syntax
|
|
52
52
|
**Output:** JSON Schema, Pydantic models, or OpenAPI specifications
|
|
@@ -109,7 +109,7 @@ Simple Schema takes human-readable text descriptions and converts them into stru
|
|
|
109
109
|
### ✅ Validate Data
|
|
110
110
|
|
|
111
111
|
```python
|
|
112
|
-
from
|
|
112
|
+
from string_schema import validate_to_dict, validate_to_model
|
|
113
113
|
|
|
114
114
|
# Example raw data (from API, user input, etc.)
|
|
115
115
|
raw_data = {
|
|
@@ -132,7 +132,7 @@ print(user_model.age) # 25 - Converted to int
|
|
|
132
132
|
### 🎨 Function Decorators
|
|
133
133
|
|
|
134
134
|
```python
|
|
135
|
-
from
|
|
135
|
+
from string_schema import returns_dict, returns_model
|
|
136
136
|
import uuid
|
|
137
137
|
|
|
138
138
|
# Auto-validate function returns to dicts
|
|
@@ -162,7 +162,7 @@ print(user_model.name) # "Bob" - Full type safety
|
|
|
162
162
|
### 🌐 FastAPI Integration
|
|
163
163
|
|
|
164
164
|
```python
|
|
165
|
-
from
|
|
165
|
+
from string_schema import string_to_model, returns_dict
|
|
166
166
|
|
|
167
167
|
# Create models for FastAPI
|
|
168
168
|
UserRequest = string_to_model("name:string, email:email")
|
|
@@ -182,7 +182,7 @@ def create_user_endpoint(user: UserRequest):
|
|
|
182
182
|
### 🌱 Simple Example - Basic User Data
|
|
183
183
|
|
|
184
184
|
```python
|
|
185
|
-
from
|
|
185
|
+
from string_schema import string_to_json_schema
|
|
186
186
|
|
|
187
187
|
# Define schema using intuitive string syntax
|
|
188
188
|
schema = string_to_json_schema("""
|
|
@@ -234,7 +234,7 @@ print(schema) # Full JSON Schema ready for validation
|
|
|
234
234
|
### 🐍 Pydantic Models (Python Classes)
|
|
235
235
|
|
|
236
236
|
```python
|
|
237
|
-
from
|
|
237
|
+
from string_schema import string_to_model
|
|
238
238
|
|
|
239
239
|
# Direct conversion: String syntax → Pydantic model
|
|
240
240
|
UserModel = string_to_model("name:string, email:email, active:bool")
|
|
@@ -247,7 +247,7 @@ print(user.model_dump_json()) # {"name": "John Doe", "email": "john@example.com
|
|
|
247
247
|
### 🔧 Code Generation (For Templates & Tools)
|
|
248
248
|
|
|
249
249
|
```python
|
|
250
|
-
from
|
|
250
|
+
from string_schema import string_to_model_code
|
|
251
251
|
|
|
252
252
|
# Generate Pydantic model code as a string
|
|
253
253
|
code = string_to_model_code("User", "name:string, email:email, active:bool")
|
|
@@ -270,7 +270,7 @@ with open('models.py', 'w') as f:
|
|
|
270
270
|
### 🌐 OpenAPI Schemas (API Documentation)
|
|
271
271
|
|
|
272
272
|
```python
|
|
273
|
-
from
|
|
273
|
+
from string_schema import string_to_openapi
|
|
274
274
|
|
|
275
275
|
# Direct conversion: String syntax → OpenAPI schema
|
|
276
276
|
openapi_schema = string_to_openapi("name:string, email:email")
|
|
@@ -287,14 +287,14 @@ print(openapi_schema)
|
|
|
287
287
|
|
|
288
288
|
## 🔄 Reverse Conversions (Universal Schema Converter)
|
|
289
289
|
|
|
290
|
-
|
|
290
|
+
String Schema provides complete bidirectional conversion between all schema formats!
|
|
291
291
|
|
|
292
292
|
> **⚠️ Information Loss Notice**: Reverse conversions (from JSON Schema/OpenAPI/Pydantic back to string syntax) may lose some information due to format differences. However, the resulting schemas are designed to cover the most common use cases and maintain functional equivalence for typical validation scenarios.
|
|
293
293
|
|
|
294
294
|
### 🔍 Schema Introspection
|
|
295
295
|
|
|
296
296
|
```python
|
|
297
|
-
from
|
|
297
|
+
from string_schema import model_to_string, string_to_model
|
|
298
298
|
|
|
299
299
|
# Create a model first
|
|
300
300
|
UserModel = string_to_model("name:string, email:email, active:bool")
|
|
@@ -308,9 +308,9 @@ print(f"Model schema: {schema_string}")
|
|
|
308
308
|
### 📦 Migration & Import
|
|
309
309
|
|
|
310
310
|
```python
|
|
311
|
-
from
|
|
311
|
+
from string_schema import json_schema_to_string
|
|
312
312
|
|
|
313
|
-
# Example: Convert existing JSON Schema to
|
|
313
|
+
# Example: Convert existing JSON Schema to String Schema syntax
|
|
314
314
|
json_schema = {
|
|
315
315
|
"type": "object",
|
|
316
316
|
"properties": {
|
|
@@ -329,7 +329,7 @@ print(f"Converted: {simple_syntax}")
|
|
|
329
329
|
### 🔧 Schema Comparison & Analysis
|
|
330
330
|
|
|
331
331
|
```python
|
|
332
|
-
from
|
|
332
|
+
from string_schema import string_to_model, model_to_string
|
|
333
333
|
|
|
334
334
|
# Create two versions of a model
|
|
335
335
|
UserV1 = string_to_model("name:string, email:email")
|
|
@@ -371,7 +371,7 @@ print(f"V2: {v2_str}") # "name:string, email:email, active:bool"
|
|
|
371
371
|
## ✅ Validation
|
|
372
372
|
|
|
373
373
|
```python
|
|
374
|
-
from
|
|
374
|
+
from string_schema import validate_string_syntax
|
|
375
375
|
|
|
376
376
|
# Validate your schema syntax
|
|
377
377
|
result = validate_string_syntax("name:string, email:email, age:int?")
|
|
@@ -391,7 +391,7 @@ print(f"Errors: {bad_result['errors']}") # ['Unknown type: invalid_type']
|
|
|
391
391
|
### 🤖 LLM Data Extraction
|
|
392
392
|
|
|
393
393
|
```python
|
|
394
|
-
from
|
|
394
|
+
from string_schema import string_to_json_schema
|
|
395
395
|
|
|
396
396
|
# Define what data to extract
|
|
397
397
|
schema = string_to_json_schema("company:string, employees:[{name:string, email:email}], founded:int?")
|
|
@@ -401,7 +401,7 @@ schema = string_to_json_schema("company:string, employees:[{name:string, email:e
|
|
|
401
401
|
### 🔧 FastAPI Development
|
|
402
402
|
|
|
403
403
|
```python
|
|
404
|
-
from
|
|
404
|
+
from string_schema import string_to_model
|
|
405
405
|
|
|
406
406
|
# Create model for FastAPI
|
|
407
407
|
UserModel = string_to_model("name:string, email:email")
|
|
@@ -415,7 +415,7 @@ async def create_user(user: UserModel):
|
|
|
415
415
|
### 🏗️ Code Generation & Templates
|
|
416
416
|
|
|
417
417
|
```python
|
|
418
|
-
from
|
|
418
|
+
from string_schema import string_to_model_code
|
|
419
419
|
|
|
420
420
|
# Generate model code
|
|
421
421
|
code = string_to_model_code("User", "name:string, email:email")
|
|
@@ -430,7 +430,7 @@ with open('user_model.py', 'w') as f:
|
|
|
430
430
|
### 📋 Configuration Validation
|
|
431
431
|
|
|
432
432
|
```python
|
|
433
|
-
from
|
|
433
|
+
from string_schema import string_to_json_schema
|
|
434
434
|
|
|
435
435
|
# Validate app configuration
|
|
436
436
|
config_schema = string_to_json_schema("database:{host:string, port:int}, debug:bool")
|
|
@@ -450,8 +450,8 @@ Ready-to-use schema examples are available in the `examples/` directory:
|
|
|
450
450
|
|
|
451
451
|
```python
|
|
452
452
|
# Import example schemas if needed
|
|
453
|
-
from
|
|
454
|
-
from
|
|
453
|
+
from string_schema.examples.presets import user_schema, product_schema
|
|
454
|
+
from string_schema.examples.recipes import create_ecommerce_product_schema
|
|
455
455
|
|
|
456
456
|
# Or better yet, use string syntax directly:
|
|
457
457
|
user_schema = string_to_json_schema("name:string, email:email, age:int?")
|
|
@@ -474,7 +474,7 @@ pytest tests/
|
|
|
474
474
|
Contributions are welcome! The codebase is well-organized and documented:
|
|
475
475
|
|
|
476
476
|
```
|
|
477
|
-
|
|
477
|
+
string_schema/
|
|
478
478
|
├── core/ # Core functionality (fields, builders, validators)
|
|
479
479
|
├── parsing/ # String parsing and syntax
|
|
480
480
|
├── integrations/ # Pydantic, JSON Schema, OpenAPI
|
|
@@ -487,4 +487,4 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
|
|
|
487
487
|
|
|
488
488
|
---
|
|
489
489
|
|
|
490
|
-
**
|
|
490
|
+
**String Schema** - Making data validation simple, intuitive, and LLM-friendly! 🚀
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
#
|
|
1
|
+
# String Schema Documentation
|
|
2
2
|
|
|
3
|
-
Welcome to the
|
|
3
|
+
Welcome to the String Schema documentation! This directory contains comprehensive documentation for the String Schema library.
|
|
4
4
|
|
|
5
5
|
## 🎯 Status: Production Ready
|
|
6
6
|
|
|
@@ -50,9 +50,9 @@ Welcome to the Simple Schema documentation! This directory contains comprehensiv
|
|
|
50
50
|
|
|
51
51
|
## Key Features
|
|
52
52
|
|
|
53
|
-
|
|
53
|
+
String Schema provides:
|
|
54
54
|
|
|
55
|
-
- **Intuitive Syntax**: Define schemas using simple, readable syntax
|
|
55
|
+
- **Intuitive Syntax**: Define schemas using simple, readable string syntax
|
|
56
56
|
- **LLM-Optimized**: Designed to work seamlessly with Large Language Models
|
|
57
57
|
- **Multiple Formats**: Export to JSON Schema, Pydantic models, OpenAPI specs
|
|
58
58
|
- **Rich Validation**: Comprehensive validation with detailed error reporting
|
|
@@ -72,4 +72,4 @@ See the main repository for contribution guidelines and development setup.
|
|
|
72
72
|
|
|
73
73
|
## License
|
|
74
74
|
|
|
75
|
-
|
|
75
|
+
String Schema is released under the MIT License. See the LICENSE file for details.
|