string-schema 0.1.0__tar.gz → 0.1.2__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.2}/PKG-INFO +44 -51
- {string_schema-0.1.0 → string_schema-0.1.2}/README.md +27 -27
- {string_schema-0.1.0 → string_schema-0.1.2}/docs/README.md +5 -5
- {string_schema-0.1.0 → string_schema-0.1.2}/docs/advanced-usage.md +34 -34
- {string_schema-0.1.0 → string_schema-0.1.2}/docs/api-reference.md +18 -18
- {string_schema-0.1.0 → string_schema-0.1.2}/docs/examples.md +11 -11
- {string_schema-0.1.0 → string_schema-0.1.2}/docs/faq.md +27 -20
- {string_schema-0.1.0 → string_schema-0.1.2}/docs/getting-started.md +10 -10
- {string_schema-0.1.0 → string_schema-0.1.2}/docs/pydantic-utilities.md +9 -9
- {string_schema-0.1.0 → string_schema-0.1.2}/docs/string-syntax.md +1 -1
- {string_schema-0.1.0 → string_schema-0.1.2}/docs/troubleshooting.md +44 -18
- {string_schema-0.1.0 → string_schema-0.1.2}/examples/demo.py +26 -22
- {string_schema-0.1.0 → string_schema-0.1.2}/examples/pydantic_utility_demo.py +3 -3
- string_schema-0.1.2/pyproject.toml +145 -0
- {string_schema-0.1.0 → string_schema-0.1.2}/setup.py +11 -14
- {string_schema-0.1.0/simple_schema → string_schema-0.1.2/string_schema}/__init__.py +2 -2
- string_schema-0.1.2/string_schema/py.typed +1 -0
- {string_schema-0.1.0 → string_schema-0.1.2/string_schema.egg-info}/PKG-INFO +44 -51
- string_schema-0.1.2/string_schema.egg-info/SOURCES.txt +24 -0
- {string_schema-0.1.0 → string_schema-0.1.2}/string_schema.egg-info/requires.txt +2 -1
- string_schema-0.1.2/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.2}/LICENSE +0 -0
- {string_schema-0.1.0 → string_schema-0.1.2}/MANIFEST.in +0 -0
- {string_schema-0.1.0 → string_schema-0.1.2}/setup.cfg +0 -0
- {string_schema-0.1.0/simple_schema → string_schema-0.1.2/string_schema}/utilities.py +0 -0
- {string_schema-0.1.0 → string_schema-0.1.2}/string_schema.egg-info/dependency_links.txt +0 -0
|
@@ -1,33 +1,34 @@
|
|
|
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.2
|
|
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-Expression: 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
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
15
18
|
Classifier: Operating System :: OS Independent
|
|
16
19
|
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
20
|
Classifier: Programming Language :: Python :: 3.11
|
|
21
21
|
Classifier: Programming Language :: Python :: 3.12
|
|
22
22
|
Classifier: Programming Language :: Python :: 3.13
|
|
23
23
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
24
24
|
Classifier: Topic :: Text Processing :: Markup
|
|
25
25
|
Classifier: Topic :: Utilities
|
|
26
|
-
|
|
26
|
+
Classifier: Typing :: Typed
|
|
27
|
+
Requires-Python: >=3.11
|
|
27
28
|
Description-Content-Type: text/markdown
|
|
28
29
|
License-File: LICENSE
|
|
29
30
|
Requires-Dist: pydantic>=2.0.0
|
|
30
|
-
Requires-Dist:
|
|
31
|
+
Requires-Dist: email-validator>=2.0.0
|
|
31
32
|
Provides-Extra: dev
|
|
32
33
|
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
33
34
|
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
|
|
@@ -35,25 +36,17 @@ Requires-Dist: black>=22.0.0; extra == "dev"
|
|
|
35
36
|
Requires-Dist: isort>=5.0.0; extra == "dev"
|
|
36
37
|
Requires-Dist: flake8>=5.0.0; extra == "dev"
|
|
37
38
|
Requires-Dist: mypy>=1.0.0; extra == "dev"
|
|
39
|
+
Requires-Dist: pre-commit>=2.20.0; extra == "dev"
|
|
38
40
|
Provides-Extra: docs
|
|
39
41
|
Requires-Dist: sphinx>=5.0.0; extra == "docs"
|
|
40
42
|
Requires-Dist: sphinx-rtd-theme>=1.0.0; extra == "docs"
|
|
41
43
|
Requires-Dist: myst-parser>=0.18.0; extra == "docs"
|
|
42
44
|
Dynamic: author
|
|
43
|
-
Dynamic: author-email
|
|
44
|
-
Dynamic: classifier
|
|
45
|
-
Dynamic: description
|
|
46
|
-
Dynamic: description-content-type
|
|
47
45
|
Dynamic: home-page
|
|
48
|
-
Dynamic: keywords
|
|
49
46
|
Dynamic: license-file
|
|
50
|
-
Dynamic: project-url
|
|
51
|
-
Dynamic: provides-extra
|
|
52
|
-
Dynamic: requires-dist
|
|
53
47
|
Dynamic: requires-python
|
|
54
|
-
Dynamic: summary
|
|
55
48
|
|
|
56
|
-
#
|
|
49
|
+
# String Schema
|
|
57
50
|
|
|
58
51
|
A simple, LLM-friendly schema definition library for Python that converts intuitive string syntax into structured data schemas.
|
|
59
52
|
|
|
@@ -62,13 +55,13 @@ A simple, LLM-friendly schema definition library for Python that converts intuit
|
|
|
62
55
|
### Installation
|
|
63
56
|
|
|
64
57
|
```bash
|
|
65
|
-
pip install
|
|
58
|
+
pip install string-schema
|
|
66
59
|
```
|
|
67
60
|
|
|
68
61
|
### 30-Second Example
|
|
69
62
|
|
|
70
63
|
```python
|
|
71
|
-
from
|
|
64
|
+
from string_schema import string_to_json_schema
|
|
72
65
|
|
|
73
66
|
# Define a schema with simple, readable syntax
|
|
74
67
|
schema = string_to_json_schema("name:string, email:email, age:int?")
|
|
@@ -89,7 +82,7 @@ print(schema)
|
|
|
89
82
|
### Create Pydantic Models Directly
|
|
90
83
|
|
|
91
84
|
```python
|
|
92
|
-
from
|
|
85
|
+
from string_schema import string_to_model
|
|
93
86
|
|
|
94
87
|
# Create Pydantic model from string syntax
|
|
95
88
|
UserModel = string_to_model("name:string, email:email, age:int?")
|
|
@@ -99,9 +92,9 @@ user = UserModel(name="Alice", email="alice@example.com")
|
|
|
99
92
|
print(user.model_dump_json()) # {"name": "Alice", "email": "alice@example.com"}
|
|
100
93
|
```
|
|
101
94
|
|
|
102
|
-
## 🎯 What
|
|
95
|
+
## 🎯 What String Schema Does
|
|
103
96
|
|
|
104
|
-
|
|
97
|
+
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
98
|
|
|
106
99
|
**Input:** Human-readable string syntax
|
|
107
100
|
**Output:** JSON Schema, Pydantic models, or OpenAPI specifications
|
|
@@ -164,7 +157,7 @@ Simple Schema takes human-readable text descriptions and converts them into stru
|
|
|
164
157
|
### ✅ Validate Data
|
|
165
158
|
|
|
166
159
|
```python
|
|
167
|
-
from
|
|
160
|
+
from string_schema import validate_to_dict, validate_to_model
|
|
168
161
|
|
|
169
162
|
# Example raw data (from API, user input, etc.)
|
|
170
163
|
raw_data = {
|
|
@@ -187,7 +180,7 @@ print(user_model.age) # 25 - Converted to int
|
|
|
187
180
|
### 🎨 Function Decorators
|
|
188
181
|
|
|
189
182
|
```python
|
|
190
|
-
from
|
|
183
|
+
from string_schema import returns_dict, returns_model
|
|
191
184
|
import uuid
|
|
192
185
|
|
|
193
186
|
# Auto-validate function returns to dicts
|
|
@@ -217,7 +210,7 @@ print(user_model.name) # "Bob" - Full type safety
|
|
|
217
210
|
### 🌐 FastAPI Integration
|
|
218
211
|
|
|
219
212
|
```python
|
|
220
|
-
from
|
|
213
|
+
from string_schema import string_to_model, returns_dict
|
|
221
214
|
|
|
222
215
|
# Create models for FastAPI
|
|
223
216
|
UserRequest = string_to_model("name:string, email:email")
|
|
@@ -237,7 +230,7 @@ def create_user_endpoint(user: UserRequest):
|
|
|
237
230
|
### 🌱 Simple Example - Basic User Data
|
|
238
231
|
|
|
239
232
|
```python
|
|
240
|
-
from
|
|
233
|
+
from string_schema import string_to_json_schema
|
|
241
234
|
|
|
242
235
|
# Define schema using intuitive string syntax
|
|
243
236
|
schema = string_to_json_schema("""
|
|
@@ -289,7 +282,7 @@ print(schema) # Full JSON Schema ready for validation
|
|
|
289
282
|
### 🐍 Pydantic Models (Python Classes)
|
|
290
283
|
|
|
291
284
|
```python
|
|
292
|
-
from
|
|
285
|
+
from string_schema import string_to_model
|
|
293
286
|
|
|
294
287
|
# Direct conversion: String syntax → Pydantic model
|
|
295
288
|
UserModel = string_to_model("name:string, email:email, active:bool")
|
|
@@ -302,7 +295,7 @@ print(user.model_dump_json()) # {"name": "John Doe", "email": "john@example.com
|
|
|
302
295
|
### 🔧 Code Generation (For Templates & Tools)
|
|
303
296
|
|
|
304
297
|
```python
|
|
305
|
-
from
|
|
298
|
+
from string_schema import string_to_model_code
|
|
306
299
|
|
|
307
300
|
# Generate Pydantic model code as a string
|
|
308
301
|
code = string_to_model_code("User", "name:string, email:email, active:bool")
|
|
@@ -325,7 +318,7 @@ with open('models.py', 'w') as f:
|
|
|
325
318
|
### 🌐 OpenAPI Schemas (API Documentation)
|
|
326
319
|
|
|
327
320
|
```python
|
|
328
|
-
from
|
|
321
|
+
from string_schema import string_to_openapi
|
|
329
322
|
|
|
330
323
|
# Direct conversion: String syntax → OpenAPI schema
|
|
331
324
|
openapi_schema = string_to_openapi("name:string, email:email")
|
|
@@ -342,14 +335,14 @@ print(openapi_schema)
|
|
|
342
335
|
|
|
343
336
|
## 🔄 Reverse Conversions (Universal Schema Converter)
|
|
344
337
|
|
|
345
|
-
|
|
338
|
+
String Schema provides complete bidirectional conversion between all schema formats!
|
|
346
339
|
|
|
347
340
|
> **⚠️ 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
341
|
|
|
349
342
|
### 🔍 Schema Introspection
|
|
350
343
|
|
|
351
344
|
```python
|
|
352
|
-
from
|
|
345
|
+
from string_schema import model_to_string, string_to_model
|
|
353
346
|
|
|
354
347
|
# Create a model first
|
|
355
348
|
UserModel = string_to_model("name:string, email:email, active:bool")
|
|
@@ -363,9 +356,9 @@ print(f"Model schema: {schema_string}")
|
|
|
363
356
|
### 📦 Migration & Import
|
|
364
357
|
|
|
365
358
|
```python
|
|
366
|
-
from
|
|
359
|
+
from string_schema import json_schema_to_string
|
|
367
360
|
|
|
368
|
-
# Example: Convert existing JSON Schema to
|
|
361
|
+
# Example: Convert existing JSON Schema to String Schema syntax
|
|
369
362
|
json_schema = {
|
|
370
363
|
"type": "object",
|
|
371
364
|
"properties": {
|
|
@@ -384,7 +377,7 @@ print(f"Converted: {simple_syntax}")
|
|
|
384
377
|
### 🔧 Schema Comparison & Analysis
|
|
385
378
|
|
|
386
379
|
```python
|
|
387
|
-
from
|
|
380
|
+
from string_schema import string_to_model, model_to_string
|
|
388
381
|
|
|
389
382
|
# Create two versions of a model
|
|
390
383
|
UserV1 = string_to_model("name:string, email:email")
|
|
@@ -426,7 +419,7 @@ print(f"V2: {v2_str}") # "name:string, email:email, active:bool"
|
|
|
426
419
|
## ✅ Validation
|
|
427
420
|
|
|
428
421
|
```python
|
|
429
|
-
from
|
|
422
|
+
from string_schema import validate_string_syntax
|
|
430
423
|
|
|
431
424
|
# Validate your schema syntax
|
|
432
425
|
result = validate_string_syntax("name:string, email:email, age:int?")
|
|
@@ -446,7 +439,7 @@ print(f"Errors: {bad_result['errors']}") # ['Unknown type: invalid_type']
|
|
|
446
439
|
### 🤖 LLM Data Extraction
|
|
447
440
|
|
|
448
441
|
```python
|
|
449
|
-
from
|
|
442
|
+
from string_schema import string_to_json_schema
|
|
450
443
|
|
|
451
444
|
# Define what data to extract
|
|
452
445
|
schema = string_to_json_schema("company:string, employees:[{name:string, email:email}], founded:int?")
|
|
@@ -456,7 +449,7 @@ schema = string_to_json_schema("company:string, employees:[{name:string, email:e
|
|
|
456
449
|
### 🔧 FastAPI Development
|
|
457
450
|
|
|
458
451
|
```python
|
|
459
|
-
from
|
|
452
|
+
from string_schema import string_to_model
|
|
460
453
|
|
|
461
454
|
# Create model for FastAPI
|
|
462
455
|
UserModel = string_to_model("name:string, email:email")
|
|
@@ -470,7 +463,7 @@ async def create_user(user: UserModel):
|
|
|
470
463
|
### 🏗️ Code Generation & Templates
|
|
471
464
|
|
|
472
465
|
```python
|
|
473
|
-
from
|
|
466
|
+
from string_schema import string_to_model_code
|
|
474
467
|
|
|
475
468
|
# Generate model code
|
|
476
469
|
code = string_to_model_code("User", "name:string, email:email")
|
|
@@ -485,7 +478,7 @@ with open('user_model.py', 'w') as f:
|
|
|
485
478
|
### 📋 Configuration Validation
|
|
486
479
|
|
|
487
480
|
```python
|
|
488
|
-
from
|
|
481
|
+
from string_schema import string_to_json_schema
|
|
489
482
|
|
|
490
483
|
# Validate app configuration
|
|
491
484
|
config_schema = string_to_json_schema("database:{host:string, port:int}, debug:bool")
|
|
@@ -505,8 +498,8 @@ Ready-to-use schema examples are available in the `examples/` directory:
|
|
|
505
498
|
|
|
506
499
|
```python
|
|
507
500
|
# Import example schemas if needed
|
|
508
|
-
from
|
|
509
|
-
from
|
|
501
|
+
from string_schema.examples.presets import user_schema, product_schema
|
|
502
|
+
from string_schema.examples.recipes import create_ecommerce_product_schema
|
|
510
503
|
|
|
511
504
|
# Or better yet, use string syntax directly:
|
|
512
505
|
user_schema = string_to_json_schema("name:string, email:email, age:int?")
|
|
@@ -529,7 +522,7 @@ pytest tests/
|
|
|
529
522
|
Contributions are welcome! The codebase is well-organized and documented:
|
|
530
523
|
|
|
531
524
|
```
|
|
532
|
-
|
|
525
|
+
string_schema/
|
|
533
526
|
├── core/ # Core functionality (fields, builders, validators)
|
|
534
527
|
├── parsing/ # String parsing and syntax
|
|
535
528
|
├── integrations/ # Pydantic, JSON Schema, OpenAPI
|
|
@@ -542,4 +535,4 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
|
|
|
542
535
|
|
|
543
536
|
---
|
|
544
537
|
|
|
545
|
-
**
|
|
538
|
+
**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.
|