json-structure 0.1.6__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.
@@ -0,0 +1,34 @@
1
+ # Generated version file (created by hatch-vcs at build time)
2
+ src/json_structure/_version.py
3
+
4
+ # Byte-compiled / optimized / DLL files
5
+ __pycache__/
6
+ *.py[cod]
7
+ *$py.class
8
+
9
+ # Distribution / packaging
10
+ dist/
11
+ build/
12
+ *.egg-info/
13
+ *.egg
14
+
15
+ # Virtual environments
16
+ .venv/
17
+ venv/
18
+ ENV/
19
+
20
+ # Testing
21
+ .pytest_cache/
22
+ .coverage
23
+ htmlcov/
24
+ coverage.xml
25
+
26
+ # IDE
27
+ .idea/
28
+ .vscode/
29
+ *.swp
30
+ *.swo
31
+
32
+ # OS
33
+ .DS_Store
34
+ Thumbs.db
@@ -0,0 +1,260 @@
1
+ Metadata-Version: 2.4
2
+ Name: json-structure
3
+ Version: 0.1.6
4
+ Summary: Validators for JSON Structure schemas and instances
5
+ Project-URL: Homepage, https://json-structure.org
6
+ Project-URL: Documentation, https://github.com/json-structure/sdk
7
+ Project-URL: Repository, https://github.com/json-structure/sdk
8
+ Project-URL: Issues, https://github.com/json-structure/sdk/issues
9
+ Author-email: JSON Structure Project <info@json-structure.org>
10
+ License-Expression: MIT
11
+ Keywords: json,json-structure,schema,type-system,validation
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Operating System :: OS Independent
16
+ 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
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Programming Language :: Python :: 3.13
23
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
24
+ Classifier: Topic :: Text Processing :: Markup
25
+ Classifier: Typing :: Typed
26
+ Requires-Python: >=3.8
27
+ Provides-Extra: dev
28
+ Requires-Dist: pytest-cov>=4.0; extra == 'dev'
29
+ Requires-Dist: pytest>=7.0; extra == 'dev'
30
+ Description-Content-Type: text/markdown
31
+
32
+ # JSON Structure Python SDK
33
+
34
+ [![PyPI version](https://badge.fury.io/py/json-structure.svg)](https://badge.fury.io/py/json-structure)
35
+ [![Python](https://img.shields.io/pypi/pyversions/json-structure.svg)](https://pypi.org/project/json-structure/)
36
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
37
+
38
+ Python validators for [JSON Structure](https://json-structure.org) schemas and instances.
39
+
40
+ JSON Structure is a type-oriented schema language for JSON, designed for defining data structures
41
+ that can be validated and mapped to programming language types.
42
+
43
+ ## Installation
44
+
45
+ ```bash
46
+ pip install json-structure
47
+ ```
48
+
49
+ ## Quick Start
50
+
51
+ ### Validate a Schema
52
+
53
+ ```python
54
+ from json_structure import SchemaValidator
55
+
56
+ schema = {
57
+ "$schema": "https://json-structure.org/meta/core/v0/#",
58
+ "$id": "https://example.com/person",
59
+ "name": "Person",
60
+ "type": "object",
61
+ "properties": {
62
+ "name": {"type": "string"},
63
+ "age": {"type": "int32"},
64
+ "email": {"type": "string"}
65
+ },
66
+ "required": ["name"]
67
+ }
68
+
69
+ validator = SchemaValidator()
70
+ errors = validator.validate(schema)
71
+
72
+ if errors:
73
+ print("Schema is invalid:")
74
+ for error in errors:
75
+ print(f" - {error}")
76
+ else:
77
+ print("Schema is valid!")
78
+ ```
79
+
80
+ ### Validate an Instance
81
+
82
+ ```python
83
+ from json_structure import InstanceValidator
84
+
85
+ schema = {
86
+ "$schema": "https://json-structure.org/meta/core/v0/#",
87
+ "$id": "https://example.com/person",
88
+ "name": "Person",
89
+ "type": "object",
90
+ "properties": {
91
+ "name": {"type": "string"},
92
+ "age": {"type": "int32"}
93
+ },
94
+ "required": ["name"]
95
+ }
96
+
97
+ instance = {
98
+ "name": "Alice",
99
+ "age": 30
100
+ }
101
+
102
+ validator = InstanceValidator(schema)
103
+ errors = validator.validate_instance(instance)
104
+
105
+ if errors:
106
+ print("Instance is invalid:")
107
+ for error in errors:
108
+ print(f" - {error}")
109
+ else:
110
+ print("Instance is valid!")
111
+ ```
112
+
113
+ ## Features
114
+
115
+ ### Supported Types
116
+
117
+ All 34 types from JSON Structure Core v0 are supported:
118
+
119
+ **Primitive Types:**
120
+ - `string`, `number`, `integer`, `boolean`, `null`
121
+ - `int8`, `uint8`, `int16`, `uint16`, `int32`, `uint32`
122
+ - `int64`, `uint64`, `int128`, `uint128` (string-encoded)
123
+ - `float8`, `float`, `double`, `decimal`
124
+ - `date`, `datetime`, `time`, `duration`
125
+ - `uuid`, `uri`, `binary`, `jsonpointer`
126
+
127
+ **Compound Types:**
128
+ - `object`, `array`, `set`, `map`, `tuple`, `choice`, `any`
129
+
130
+ ### Extensions
131
+
132
+ - **Conditional Composition**: `allOf`, `anyOf`, `oneOf`, `not`, `if`/`then`/`else`
133
+ - **Validation Addins**: `minimum`, `maximum`, `minLength`, `maxLength`, `pattern`, etc.
134
+ - **Import Extension**: `$import`, `$importdefs` for schema composition
135
+
136
+ ### Command Line Tools
137
+
138
+ ```bash
139
+ # Validate a schema file
140
+ json-structure-check schema.json
141
+
142
+ # Validate an instance against a schema
143
+ json-structure-validate instance.json schema.json
144
+ ```
145
+
146
+ ## API Reference
147
+
148
+ ### SchemaValidator
149
+
150
+ ```python
151
+ from json_structure import SchemaValidator
152
+
153
+ validator = SchemaValidator(
154
+ allow_dollar=False, # Allow '$' in property names
155
+ allow_import=False, # Enable $import/$importdefs
156
+ import_map=None, # Dict mapping URIs to local files
157
+ extended=False, # Enable extended validation features
158
+ external_schemas=None # List of schema dicts to sideload (matched by $id)
159
+ )
160
+
161
+ errors = validator.validate(schema_dict, source_text=None)
162
+ ```
163
+
164
+ ### InstanceValidator
165
+
166
+ ```python
167
+ from json_structure import InstanceValidator
168
+
169
+ validator = InstanceValidator(
170
+ root_schema, # The JSON Structure schema dict
171
+ allow_import=False, # Enable $import/$importdefs
172
+ import_map=None, # Dict mapping URIs to local files
173
+ extended=False, # Enable extended validation features
174
+ external_schemas=None # List of schema dicts to sideload (matched by $id)
175
+ )
176
+
177
+ errors = validator.validate_instance(instance)
178
+ ```
179
+
180
+ ### Sideloading External Schemas
181
+
182
+ When using `$import` to reference external schemas, you can provide those schemas
183
+ directly instead of fetching them from URIs:
184
+
185
+ ```python
186
+ from json_structure import InstanceValidator
187
+
188
+ # External schema that would normally be fetched from https://example.com/address.json
189
+ address_schema = {
190
+ "$schema": "https://json-structure.org/meta/core/v0/#",
191
+ "$id": "https://example.com/address.json",
192
+ "name": "Address",
193
+ "type": "object",
194
+ "properties": {
195
+ "street": {"type": "string"},
196
+ "city": {"type": "string"}
197
+ }
198
+ }
199
+
200
+ # Main schema that imports the address schema
201
+ main_schema = {
202
+ "$schema": "https://json-structure.org/meta/core/v0/#",
203
+ "$id": "https://example.com/person",
204
+ "name": "Person",
205
+ "type": "object",
206
+ "properties": {
207
+ "name": {"type": "string"},
208
+ "address": {"$ref": "#/definitions/Imported/Address"}
209
+ },
210
+ "definitions": {
211
+ "Imported": {
212
+ "$import": "https://example.com/address.json"
213
+ }
214
+ }
215
+ }
216
+
217
+ # Sideload the address schema - matched by $id
218
+ validator = InstanceValidator(
219
+ main_schema,
220
+ allow_import=True,
221
+ external_schemas=[address_schema]
222
+ )
223
+
224
+ instance = {
225
+ "name": "Alice",
226
+ "address": {"street": "123 Main St", "city": "Seattle"}
227
+ }
228
+
229
+ errors = validator.validate_instance(instance)
230
+ ```
231
+
232
+ You can supply multiple schemas to satisfy multiple imports. The schemas are matched
233
+ by their `$id` field against the import URIs.
234
+
235
+ ## Development
236
+
237
+ ```bash
238
+ # Clone the repository
239
+ git clone https://github.com/json-structure/sdk.git
240
+ cd sdk/python
241
+
242
+ # Install development dependencies
243
+ pip install -e ".[dev]"
244
+
245
+ # Run tests
246
+ pytest
247
+
248
+ # Run tests with coverage
249
+ pytest --cov=json_structure --cov-report=term-missing
250
+ ```
251
+
252
+ ## License
253
+
254
+ MIT License - see [LICENSE](../LICENSE) for details.
255
+
256
+ ## Links
257
+
258
+ - [JSON Structure Specification](https://github.com/json-structure/core)
259
+ - [JSON Structure Primer](https://github.com/json-structure/primer-and-samples)
260
+ - [SDK Repository](https://github.com/json-structure/sdk)
@@ -0,0 +1,229 @@
1
+ # JSON Structure Python SDK
2
+
3
+ [![PyPI version](https://badge.fury.io/py/json-structure.svg)](https://badge.fury.io/py/json-structure)
4
+ [![Python](https://img.shields.io/pypi/pyversions/json-structure.svg)](https://pypi.org/project/json-structure/)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
+
7
+ Python validators for [JSON Structure](https://json-structure.org) schemas and instances.
8
+
9
+ JSON Structure is a type-oriented schema language for JSON, designed for defining data structures
10
+ that can be validated and mapped to programming language types.
11
+
12
+ ## Installation
13
+
14
+ ```bash
15
+ pip install json-structure
16
+ ```
17
+
18
+ ## Quick Start
19
+
20
+ ### Validate a Schema
21
+
22
+ ```python
23
+ from json_structure import SchemaValidator
24
+
25
+ schema = {
26
+ "$schema": "https://json-structure.org/meta/core/v0/#",
27
+ "$id": "https://example.com/person",
28
+ "name": "Person",
29
+ "type": "object",
30
+ "properties": {
31
+ "name": {"type": "string"},
32
+ "age": {"type": "int32"},
33
+ "email": {"type": "string"}
34
+ },
35
+ "required": ["name"]
36
+ }
37
+
38
+ validator = SchemaValidator()
39
+ errors = validator.validate(schema)
40
+
41
+ if errors:
42
+ print("Schema is invalid:")
43
+ for error in errors:
44
+ print(f" - {error}")
45
+ else:
46
+ print("Schema is valid!")
47
+ ```
48
+
49
+ ### Validate an Instance
50
+
51
+ ```python
52
+ from json_structure import InstanceValidator
53
+
54
+ schema = {
55
+ "$schema": "https://json-structure.org/meta/core/v0/#",
56
+ "$id": "https://example.com/person",
57
+ "name": "Person",
58
+ "type": "object",
59
+ "properties": {
60
+ "name": {"type": "string"},
61
+ "age": {"type": "int32"}
62
+ },
63
+ "required": ["name"]
64
+ }
65
+
66
+ instance = {
67
+ "name": "Alice",
68
+ "age": 30
69
+ }
70
+
71
+ validator = InstanceValidator(schema)
72
+ errors = validator.validate_instance(instance)
73
+
74
+ if errors:
75
+ print("Instance is invalid:")
76
+ for error in errors:
77
+ print(f" - {error}")
78
+ else:
79
+ print("Instance is valid!")
80
+ ```
81
+
82
+ ## Features
83
+
84
+ ### Supported Types
85
+
86
+ All 34 types from JSON Structure Core v0 are supported:
87
+
88
+ **Primitive Types:**
89
+ - `string`, `number`, `integer`, `boolean`, `null`
90
+ - `int8`, `uint8`, `int16`, `uint16`, `int32`, `uint32`
91
+ - `int64`, `uint64`, `int128`, `uint128` (string-encoded)
92
+ - `float8`, `float`, `double`, `decimal`
93
+ - `date`, `datetime`, `time`, `duration`
94
+ - `uuid`, `uri`, `binary`, `jsonpointer`
95
+
96
+ **Compound Types:**
97
+ - `object`, `array`, `set`, `map`, `tuple`, `choice`, `any`
98
+
99
+ ### Extensions
100
+
101
+ - **Conditional Composition**: `allOf`, `anyOf`, `oneOf`, `not`, `if`/`then`/`else`
102
+ - **Validation Addins**: `minimum`, `maximum`, `minLength`, `maxLength`, `pattern`, etc.
103
+ - **Import Extension**: `$import`, `$importdefs` for schema composition
104
+
105
+ ### Command Line Tools
106
+
107
+ ```bash
108
+ # Validate a schema file
109
+ json-structure-check schema.json
110
+
111
+ # Validate an instance against a schema
112
+ json-structure-validate instance.json schema.json
113
+ ```
114
+
115
+ ## API Reference
116
+
117
+ ### SchemaValidator
118
+
119
+ ```python
120
+ from json_structure import SchemaValidator
121
+
122
+ validator = SchemaValidator(
123
+ allow_dollar=False, # Allow '$' in property names
124
+ allow_import=False, # Enable $import/$importdefs
125
+ import_map=None, # Dict mapping URIs to local files
126
+ extended=False, # Enable extended validation features
127
+ external_schemas=None # List of schema dicts to sideload (matched by $id)
128
+ )
129
+
130
+ errors = validator.validate(schema_dict, source_text=None)
131
+ ```
132
+
133
+ ### InstanceValidator
134
+
135
+ ```python
136
+ from json_structure import InstanceValidator
137
+
138
+ validator = InstanceValidator(
139
+ root_schema, # The JSON Structure schema dict
140
+ allow_import=False, # Enable $import/$importdefs
141
+ import_map=None, # Dict mapping URIs to local files
142
+ extended=False, # Enable extended validation features
143
+ external_schemas=None # List of schema dicts to sideload (matched by $id)
144
+ )
145
+
146
+ errors = validator.validate_instance(instance)
147
+ ```
148
+
149
+ ### Sideloading External Schemas
150
+
151
+ When using `$import` to reference external schemas, you can provide those schemas
152
+ directly instead of fetching them from URIs:
153
+
154
+ ```python
155
+ from json_structure import InstanceValidator
156
+
157
+ # External schema that would normally be fetched from https://example.com/address.json
158
+ address_schema = {
159
+ "$schema": "https://json-structure.org/meta/core/v0/#",
160
+ "$id": "https://example.com/address.json",
161
+ "name": "Address",
162
+ "type": "object",
163
+ "properties": {
164
+ "street": {"type": "string"},
165
+ "city": {"type": "string"}
166
+ }
167
+ }
168
+
169
+ # Main schema that imports the address schema
170
+ main_schema = {
171
+ "$schema": "https://json-structure.org/meta/core/v0/#",
172
+ "$id": "https://example.com/person",
173
+ "name": "Person",
174
+ "type": "object",
175
+ "properties": {
176
+ "name": {"type": "string"},
177
+ "address": {"$ref": "#/definitions/Imported/Address"}
178
+ },
179
+ "definitions": {
180
+ "Imported": {
181
+ "$import": "https://example.com/address.json"
182
+ }
183
+ }
184
+ }
185
+
186
+ # Sideload the address schema - matched by $id
187
+ validator = InstanceValidator(
188
+ main_schema,
189
+ allow_import=True,
190
+ external_schemas=[address_schema]
191
+ )
192
+
193
+ instance = {
194
+ "name": "Alice",
195
+ "address": {"street": "123 Main St", "city": "Seattle"}
196
+ }
197
+
198
+ errors = validator.validate_instance(instance)
199
+ ```
200
+
201
+ You can supply multiple schemas to satisfy multiple imports. The schemas are matched
202
+ by their `$id` field against the import URIs.
203
+
204
+ ## Development
205
+
206
+ ```bash
207
+ # Clone the repository
208
+ git clone https://github.com/json-structure/sdk.git
209
+ cd sdk/python
210
+
211
+ # Install development dependencies
212
+ pip install -e ".[dev]"
213
+
214
+ # Run tests
215
+ pytest
216
+
217
+ # Run tests with coverage
218
+ pytest --cov=json_structure --cov-report=term-missing
219
+ ```
220
+
221
+ ## License
222
+
223
+ MIT License - see [LICENSE](../LICENSE) for details.
224
+
225
+ ## Links
226
+
227
+ - [JSON Structure Specification](https://github.com/json-structure/core)
228
+ - [JSON Structure Primer](https://github.com/json-structure/primer-and-samples)
229
+ - [SDK Repository](https://github.com/json-structure/sdk)
@@ -0,0 +1,85 @@
1
+ [build-system]
2
+ requires = ["hatchling", "hatch-vcs"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "json-structure"
7
+ dynamic = ["version"]
8
+ description = "Validators for JSON Structure schemas and instances"
9
+ readme = "README.md"
10
+ license = "MIT"
11
+ requires-python = ">=3.8"
12
+ authors = [
13
+ { name = "JSON Structure Project", email = "info@json-structure.org" }
14
+ ]
15
+ keywords = [
16
+ "json",
17
+ "schema",
18
+ "validation",
19
+ "json-structure",
20
+ "type-system"
21
+ ]
22
+ classifiers = [
23
+ "Development Status :: 4 - Beta",
24
+ "Intended Audience :: Developers",
25
+ "License :: OSI Approved :: MIT License",
26
+ "Operating System :: OS Independent",
27
+ "Programming Language :: Python :: 3",
28
+ "Programming Language :: Python :: 3.8",
29
+ "Programming Language :: Python :: 3.9",
30
+ "Programming Language :: Python :: 3.10",
31
+ "Programming Language :: Python :: 3.11",
32
+ "Programming Language :: Python :: 3.12",
33
+ "Programming Language :: Python :: 3.13",
34
+ "Topic :: Software Development :: Libraries :: Python Modules",
35
+ "Topic :: Text Processing :: Markup",
36
+ "Typing :: Typed"
37
+ ]
38
+
39
+ [project.urls]
40
+ Homepage = "https://json-structure.org"
41
+ Documentation = "https://github.com/json-structure/sdk"
42
+ Repository = "https://github.com/json-structure/sdk"
43
+ Issues = "https://github.com/json-structure/sdk/issues"
44
+
45
+ [project.optional-dependencies]
46
+ dev = [
47
+ "pytest>=7.0",
48
+ "pytest-cov>=4.0"
49
+ ]
50
+
51
+ [project.scripts]
52
+ json-structure-validate = "json_structure.instance_validator:main"
53
+ json-structure-check = "json_structure.schema_validator:main"
54
+
55
+ [tool.hatch.build.targets.sdist]
56
+ include = [
57
+ "/src"
58
+ ]
59
+
60
+ [tool.hatch.build.targets.wheel]
61
+ packages = ["src/json_structure"]
62
+
63
+ [tool.pytest.ini_options]
64
+ testpaths = ["tests"]
65
+ python_files = ["test_*.py"]
66
+ python_functions = ["test_*"]
67
+ addopts = "-v"
68
+
69
+ [tool.coverage.run]
70
+ source = ["src/json_structure"]
71
+ branch = true
72
+
73
+ [tool.coverage.report]
74
+ exclude_lines = [
75
+ "pragma: no cover",
76
+ "if __name__ == .__main__.:",
77
+ "raise NotImplementedError"
78
+ ]
79
+
80
+ [tool.hatch.version]
81
+ source = "vcs"
82
+ raw-options = { root = ".." }
83
+
84
+ [tool.hatch.build.hooks.vcs]
85
+ version-file = "src/json_structure/_version.py"