json-model-compiler 2.0b0__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.
Files changed (51) hide show
  1. json_model/README.md +32 -0
  2. json_model/__init__.py +18 -0
  3. json_model/analyze.py +409 -0
  4. json_model/clang.py +563 -0
  5. json_model/convert.py +430 -0
  6. json_model/data/clang_entry.c +21 -0
  7. json_model/data/clang_free.c +10 -0
  8. json_model/data/clang_init.c +11 -0
  9. json_model/data/clang_pcre2_fun.c +6 -0
  10. json_model/data/clang_re2_fun.c +5 -0
  11. json_model/data/javascript_exe.js +4 -0
  12. json_model/data/javascript_foot.js +9 -0
  13. json_model/data/javascript_free.js +9 -0
  14. json_model/data/javascript_head.js +1 -0
  15. json_model/data/javascript_init.js +11 -0
  16. json_model/data/javascript_main.js +5 -0
  17. json_model/data/plpgsql_entry.sql +16 -0
  18. json_model/data/python_entry.py +11 -0
  19. json_model/data/python_exe.py +1 -0
  20. json_model/data/python_free.py +6 -0
  21. json_model/data/python_init.py +9 -0
  22. json_model/data/python_main.py +4 -0
  23. json_model/javascript.py +310 -0
  24. json_model/language.py +748 -0
  25. json_model/model.py +1084 -0
  26. json_model/mtypes.py +42 -0
  27. json_model/objmerge.py +165 -0
  28. json_model/optim.py +486 -0
  29. json_model/plpgsql.py +422 -0
  30. json_model/python.py +269 -0
  31. json_model/recurse.py +127 -0
  32. json_model/resolver.py +106 -0
  33. json_model/runtime/META.json +30 -0
  34. json_model/runtime/Makefile +21 -0
  35. json_model/runtime/__init__.py +32 -0
  36. json_model/runtime/json-model.c +1054 -0
  37. json_model/runtime/json-model.h +183 -0
  38. json_model/runtime/json_model--2.0.sql +261 -0
  39. json_model/runtime/json_model.control +2 -0
  40. json_model/runtime/main.c +473 -0
  41. json_model/runtime/support.py +485 -0
  42. json_model/runtime/types.py +16 -0
  43. json_model/script.py +585 -0
  44. json_model/url_cache.py +82 -0
  45. json_model/utils.py +623 -0
  46. json_model/xstatic.py +1444 -0
  47. json_model_compiler-2.0b0.dist-info/METADATA +201 -0
  48. json_model_compiler-2.0b0.dist-info/RECORD +51 -0
  49. json_model_compiler-2.0b0.dist-info/WHEEL +5 -0
  50. json_model_compiler-2.0b0.dist-info/entry_points.txt +2 -0
  51. json_model_compiler-2.0b0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,201 @@
1
+ Metadata-Version: 2.4
2
+ Name: json_model_compiler
3
+ Version: 2.0b0
4
+ Summary: JSON Model Tools
5
+ Author: Fabien Coelho, Claire Yannou-Medrala
6
+ License-Expression: CC0-1.0
7
+ Project-URL: repository, https://github.com/clairey-zx81/json-model
8
+ Classifier: Topic :: Software Development
9
+ Requires-Python: >=3.12
10
+ Description-Content-Type: text/markdown
11
+ Requires-Dist: requests
12
+ Requires-Dist: google-re2
13
+ Requires-Dist: pyyaml
14
+ Requires-Dist: validators
15
+ Requires-Dist: json-schema-utils
16
+ Provides-Extra: dev
17
+ Requires-Dist: flake8; extra == "dev"
18
+ Requires-Dist: ruff; extra == "dev"
19
+ Requires-Dist: pyright; extra == "dev"
20
+ Requires-Dist: pytest; extra == "dev"
21
+ Requires-Dist: pytest-xdist[psutils]; extra == "dev"
22
+ Requires-Dist: filelock; extra == "dev"
23
+ Requires-Dist: ipython; extra == "dev"
24
+ Requires-Dist: json_schema_utils; extra == "dev"
25
+ Provides-Extra: dist
26
+ Requires-Dist: build; extra == "dist"
27
+ Requires-Dist: wheel; extra == "dist"
28
+ Requires-Dist: twine; extra == "dist"
29
+
30
+ # JSON Model Compiler
31
+
32
+ JSON Model is a compact and intuitive JSON syntax to describe JSON data structures.
33
+
34
+ Version 2 is work-in-progress design, implementation and tests.
35
+
36
+ This implementation is given to the _Public Domain_.
37
+
38
+ ## Tool Installation
39
+
40
+ Proof-of-concept compiler to test JSON Model is available as Python a command
41
+ which can be installed with `pip` directly from GitHub:
42
+
43
+ ```shell
44
+ python -m venv venv
45
+ source venv/bin/activate
46
+ pip install git+https://github.com/clairey-zx81/json-model.git
47
+ ```
48
+
49
+ ## JMC Command
50
+
51
+ Command `jmc` options include:
52
+
53
+ - main operations (default depends on other options, final guess is preprocess):
54
+ - `-P`: preprocess model.
55
+ - `-E`: export model to JSON Schema version draft 2020-12, if possible.
56
+ - `-C`: compile to Python, C, JS or PL/pgSQL.
57
+ - `-U`: dump all models.
58
+ - `-J`: dump json IR.
59
+ - `-O`: optimize model: const prop, partial eval, xor to or, flatten…
60
+ (this is the default, `-nO` to disable)
61
+ - `-o output`: file output instead of standard
62
+ - `-F format`: select `json` or `yaml` for output
63
+ - …
64
+
65
+ For instance, let's consider a JSON model in file `person.model.json`:
66
+
67
+ ```json
68
+ {
69
+ "#": "A person with a birth date",
70
+ "name": "/^[a-z]+$/i",
71
+ "born": "$DATE"
72
+ }
73
+ ```
74
+
75
+ - to _export_ this model as a JSON schema in the YaML format:
76
+
77
+ ```sh
78
+ jmc -E -F yaml person.model.json
79
+ ```
80
+ ```yaml
81
+ description: A person with a birth date
82
+ type: object
83
+ properties:
84
+ name:
85
+ type: string
86
+ pattern: (?i)^[a-z]+$
87
+ born:
88
+ type: string
89
+ format: date
90
+ required:
91
+ - name
92
+ - born
93
+ additionalProperties: false
94
+ ```
95
+
96
+ - to check directly sample JSON values against it (with the Python backend):
97
+
98
+ ```sh
99
+ jmc -r person.model.json hobbes.json oops.json
100
+ ```
101
+ ```
102
+ hobbes.json: PASS
103
+ oops.json: FAIL (.: not an expected object [.]; .: missing mandatory prop <born> [.])
104
+ ```
105
+
106
+ - to actually compile an executable for checking a model (with the C backend),
107
+ and use it for validating values:
108
+
109
+ ```sh
110
+ jmc -o ./person.out person.model.json
111
+ ./person.out -r hobbes.json oops.json
112
+ ```
113
+ ```
114
+ hobbes.json: PASS
115
+ oops.json: FAIL (.: not an expected object [.]; .: missing mandatory prop <born> [.])
116
+ ```
117
+
118
+ The generated executable allow to collect validation performance figures (average and
119
+ standard deviation) over a loop, with or without reporting:
120
+
121
+ ```sh
122
+ ./person.out -r -T 100000 hobbes.json
123
+ ```
124
+ ```
125
+ hobbes.json.[0] nop PASS 0.056 ± 0.423 µs/check (0.174)
126
+ hobbes.json.[0] rep PASS 0.071 ± 0.443 µs/check (0.174)
127
+ hobbes.json: PASS
128
+ ```
129
+
130
+ ## JSON Model Python API
131
+
132
+ The package provides functions to create and check models from Python:
133
+
134
+ ```python
135
+ import json_model as jm
136
+
137
+ # direct model definition with 2 mandatory properties
138
+ person_model: jm.Jsonable = {
139
+ "name": "/^[a-z]+$/i",
140
+ "born": "$DATE"
141
+ }
142
+
143
+ # create a dynamically compiled checker function for the model
144
+ checker = jm.model_checker_from_json(person_model)
145
+
146
+ # check valid data
147
+ good_person = { "name": "Hobbes", "born": "2020-07-29" }
148
+ print(good_person, "->", checker(good_person))
149
+
150
+ # check invalid data
151
+ bad_person = { "name": "Oops" }
152
+ print(bad_person, "->", checker(bad_person))
153
+
154
+ # collect reasons
155
+ reasons: jm.Report = []
156
+ assert not checker(bad_person, "", reasons)
157
+ print("reasons:", reasons)
158
+ ```
159
+
160
+ ## JSON Model Validation Performance
161
+
162
+ Preliminary performance tests below compare validation times for a _large_ 500 KB JSON OpenAPI
163
+ description using JSON Model in C, JS and Python and JSON Schema Blaze 9.6.1 implementation,
164
+ with an average collected on one thousand runs, in _fast_ (no reporting) mode, including
165
+ format validations, on a laptop:
166
+
167
+ - JSON Model C: _204_ µs/check (about ⅕ ms)
168
+ - JSON Model JS: _791_ µs/check (under 1 ms)
169
+ - JSON Schema C++ Blaze: _1252_ µs/check (over 1 ms)
170
+ - JSON Model Python: _4,433_ µs/check (over 4 ms)
171
+
172
+ On this benchmark, JSON Model Compiler outperforms the fastest JSON Schema library 6:1,
173
+ and the JavaScript model validation is faster than the C++ schema validation.
174
+
175
+ ## More Information
176
+
177
+ See the [JSON Model Tutorial](./TUTO.md) for a hands-on overview of JSON Model.
178
+
179
+ JSON Model design is presented in research papers and reports:
180
+
181
+ - JSON Model: a Lightweight Featureful DSL for JSON.
182
+ Fabien Coelho and Claire Yannou-Medrala.
183
+ Technical Report [A/817/CRI](https://www.cri.minesparis.psl.eu/classement/doc/A-817.pdf),
184
+ Mines Paris - PSL, April 2024
185
+
186
+ JSON Model version 1.
187
+
188
+ - An Analysis of Defects in Public JSON Schemas.
189
+ Claire Yannou-Medrala and Fabien Coelho.
190
+ In BDA 2023, 39ème conférence sur la gestion de données - Principes, technologies et applications.
191
+ Also TR [A/794/CRI](https://www.cri.minesparis.psl.eu/classement/doc/A-794.pdf),
192
+ Mines Paris - PSL, October 2023
193
+
194
+ Brief introduction to version 0 at the end of the paper.
195
+
196
+ - JSON Model: a Lightweight Featureful Description Language for JSON Data Structures.
197
+ Fabien Coelho and Claire Yannou-Medrala.
198
+ Technical Report [A/795/CRI](https://www.cri.minesparis.psl.eu/classement/doc/A-795.pdf),
199
+ Mines Paris - PSL, May 2023
200
+
201
+ JSON Model version 0.
@@ -0,0 +1,51 @@
1
+ json_model/README.md,sha256=Z6Xd2as6vNGY_Tj3t8OQ0k62g5ExBazowRHPlcDxd1o,1021
2
+ json_model/__init__.py,sha256=2x01hMHk4vTuI3Whpr19_0qYRNglPer57Kcu5S4BlyY,532
3
+ json_model/analyze.py,sha256=SxO2VUw10VKIH0n1UQ57M_JuFej1Up73idleYTMsCIg,14651
4
+ json_model/clang.py,sha256=e-8fdnvuJuw5HI7tW4F4iVRPUa9M3rIvJFNMKg8eeGI,22140
5
+ json_model/convert.py,sha256=KMjCkf_e1a-nlpYZ31MRAATnX7JkpxnS0FAAC9XR86A,19069
6
+ json_model/javascript.py,sha256=9GGAR8WbGxEPi1V-Z7VL335QYH4rl86XGduS5NodUfU,12074
7
+ json_model/language.py,sha256=nN2KmD_KGUfQ8wFfs-pPXNIIytWGDF6mMXj6EaG8ie8,26828
8
+ json_model/model.py,sha256=Ri-zIbapm3DQaVPzfPdzJewueylIEOyB9H65DBgxNWE,43540
9
+ json_model/mtypes.py,sha256=Ni-MJ6NxgFC39KYjBlRZ92VpNTjvPwJqfe92wZomgQ8,1184
10
+ json_model/objmerge.py,sha256=tWyCBblbtnmRtQlDqDroTC5fk9dLbQl6GyDmAAf13p0,5185
11
+ json_model/optim.py,sha256=ps1EPpzol05WWPj8qpodCSmufx3RrqN3c9MlA_Ow1X0,18453
12
+ json_model/plpgsql.py,sha256=PMzzTj0PyDMREolV6EfyZptMLUIo6y6OBv1xj9JRSAM,15501
13
+ json_model/python.py,sha256=UhOx_anMGHE2o4LxDNqSD5cyj9vzxzulr2tQN0N5u-0,10571
14
+ json_model/recurse.py,sha256=MD9GufbuilPsl7KzaPgl5Kj56PNkPCLdWXLW839w2Mk,5588
15
+ json_model/resolver.py,sha256=VNpDqayrqkWqETr9lVAi2du9rEkGKHr41T91ux6UiGE,4009
16
+ json_model/script.py,sha256=5TjtZohWcqWZN8RaVHHHklTsd7KekuQ0EfIVtl_Dz6g,24492
17
+ json_model/url_cache.py,sha256=2uPz1GAnra4reOPGN-ee2rQzRtXksdY1ALmGXsZwE-M,2225
18
+ json_model/utils.py,sha256=tRjcm1PPlKMSkMvEW3cii5NNbFjwQh8jyMcxDt1WwRs,22881
19
+ json_model/xstatic.py,sha256=XC8g3Uokhse7UyaFXR2DTiyCf8IQ-DGBJdKsYURZwa0,62336
20
+ json_model/data/clang_entry.c,sha256=jk9L433JRYjTpUT8wZZH-6hMUD8PkHjsiEXBOLp-70U,588
21
+ json_model/data/clang_free.c,sha256=_KxwtMQ6vHupsHbjejEK-uarpGO8WDN3QPT_6vVuX3g,138
22
+ json_model/data/clang_init.c,sha256=geJanK9KYQx3qscePePAtjYk52ZkvUpAAlV3qBEEAq8,171
23
+ json_model/data/clang_pcre2_fun.c,sha256=ZCPVKSvJVJMpWwzFvnTR0nob8yfwqX0x1tk-KXaPows,242
24
+ json_model/data/clang_re2_fun.c,sha256=SjTwtXE3HYRzxBUftaYb9II7OBomPdZzDCQx_8cyFac,195
25
+ json_model/data/javascript_exe.js,sha256=8ZemV50r595GppfJ6W1GOek6HNAyLVncf1aTEbhiS3I,145
26
+ json_model/data/javascript_foot.js,sha256=rdE8crUmigjveO5o1ouO0M-b3vfssyB36-z_n0MOv_o,256
27
+ json_model/data/javascript_free.js,sha256=_ZUWEjoOjInRlJL877QGzlatLsJYQDRnipIKpFZ_ImI,147
28
+ json_model/data/javascript_head.js,sha256=ySypDlDodWucINqr8YcF-n0YWSQaKEBKf4lU5Z4ziZM,46
29
+ json_model/data/javascript_init.js,sha256=BLWBlqgmh5Qi002zvow-EicRqr2rkkOzj5oxkrVEgug,181
30
+ json_model/data/javascript_main.js,sha256=U-kLFbZBvqtmenclXLoFzAxDPqF5BXuVAKIHulLgLzg,217
31
+ json_model/data/plpgsql_entry.sql,sha256=jzZlT7PZ0Q_zP8mYRStUR-KHpUEZwDGlThmAJDR8fuE,433
32
+ json_model/data/python_entry.py,sha256=jqgng_21-P_0UxUz5m0JZ4GiTYtNAKkRXsYWKfFjAOo,500
33
+ json_model/data/python_exe.py,sha256=DcOGHiPvAfh9j7YwlGcJe3WU7cywnD_XMC7muDPXsVU,19
34
+ json_model/data/python_free.py,sha256=hy2j7HG9GYfKcldnBvcBHw359NHJaelSNOXYBshhALs,140
35
+ json_model/data/python_init.py,sha256=_TFZhxh5G95E8xXff7ONd19VL5MAlODMVnesMqVTcgU,201
36
+ json_model/data/python_main.py,sha256=BkFMW_fLnj6Gwt4vZf2C1-oMvoMzhpQubWdCQv5hsPA,161
37
+ json_model/runtime/META.json,sha256=uvBU1ZSeTOsQ2ze1_rqA8RazsqMgZjOdCv__u6358Ak,895
38
+ json_model/runtime/Makefile,sha256=-08OA1cqZduR-8brytaLksmSwfvumPs3vklWrhyhmzk,354
39
+ json_model/runtime/__init__.py,sha256=qZsqZmeqEAS6ZeO5UY5Sa79i0Q4LdF_0s_IHaPcS4o8,478
40
+ json_model/runtime/json-model.c,sha256=yDTfcuYCLHyWs3-d5SiwC_2uP9wXfZ7INhMXjmnSfmU,29825
41
+ json_model/runtime/json-model.h,sha256=MxAVm52s2w6Lm4I5xSb1ohPIf8_f2FKOV5DE6bEGbyw,5352
42
+ json_model/runtime/json_model--2.0.sql,sha256=X_UgsY2ldfcLA4UQR1yAKB6wVZUmIT95M3RcelJPqiM,6386
43
+ json_model/runtime/json_model.control,sha256=Y8TcsxUZNSAiZW1Nidwq9JNoFxAhLAkywaeNu4n0TNI,88
44
+ json_model/runtime/main.c,sha256=KvmHIe0Fkj3JV7HPUDpyJocPLErvdDbaTMjT0a6_q6Q,14363
45
+ json_model/runtime/support.py,sha256=SnDydxIgMNn7-4ki5pKCGvY0D6pAWMj-3vunn8W61Qo,16921
46
+ json_model/runtime/types.py,sha256=P3hAlvUuDayXVl4bMPu2oZD9IMNPVMzVhlwfJidSnL8,460
47
+ json_model_compiler-2.0b0.dist-info/METADATA,sha256=M2Lc1y_WYWM3KaOKH8ENZZ7hTdkD4RbHANSDt42IQys,5996
48
+ json_model_compiler-2.0b0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
49
+ json_model_compiler-2.0b0.dist-info/entry_points.txt,sha256=Y0HQXC2D_EQwqd1iS_d0sQ6Lmya_0Uc-CI7imE8ZrOM,46
50
+ json_model_compiler-2.0b0.dist-info/top_level.txt,sha256=46NQ59wM_HKBJzvDPOFVZRPesmtLIjjrJKUbLY-Z0lI,11
51
+ json_model_compiler-2.0b0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.9.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ jmc = json_model:jmc_script
@@ -0,0 +1 @@
1
+ json_model