structurize 2.22.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.
Files changed (81) hide show
  1. structurize-2.22.2/.gitignore +15 -0
  2. structurize-2.22.2/LICENSE +201 -0
  3. structurize-2.22.2/MANIFEST.in +6 -0
  4. structurize-2.22.2/PKG-INFO +107 -0
  5. structurize-2.22.2/README.md +61 -0
  6. structurize-2.22.2/avrotize/__init__.py +66 -0
  7. structurize-2.22.2/avrotize/__main__.py +6 -0
  8. structurize-2.22.2/avrotize/_version.py +34 -0
  9. structurize-2.22.2/avrotize/asn1toavro.py +160 -0
  10. structurize-2.22.2/avrotize/avrotize.py +152 -0
  11. structurize-2.22.2/avrotize/avrotocpp.py +483 -0
  12. structurize-2.22.2/avrotize/avrotocsharp.py +1198 -0
  13. structurize-2.22.2/avrotize/avrotocsv.py +121 -0
  14. structurize-2.22.2/avrotize/avrotodatapackage.py +173 -0
  15. structurize-2.22.2/avrotize/avrotodb.py +1383 -0
  16. structurize-2.22.2/avrotize/avrotogo.py +489 -0
  17. structurize-2.22.2/avrotize/avrotographql.py +197 -0
  18. structurize-2.22.2/avrotize/avrotoiceberg.py +210 -0
  19. structurize-2.22.2/avrotize/avrotojava.py +2218 -0
  20. structurize-2.22.2/avrotize/avrotojs.py +250 -0
  21. structurize-2.22.2/avrotize/avrotojsons.py +503 -0
  22. structurize-2.22.2/avrotize/avrotojstruct.py +345 -0
  23. structurize-2.22.2/avrotize/avrotokusto.py +364 -0
  24. structurize-2.22.2/avrotize/avrotomd.py +137 -0
  25. structurize-2.22.2/avrotize/avrotools.py +168 -0
  26. structurize-2.22.2/avrotize/avrotoparquet.py +208 -0
  27. structurize-2.22.2/avrotize/avrotoproto.py +359 -0
  28. structurize-2.22.2/avrotize/avrotopython.py +670 -0
  29. structurize-2.22.2/avrotize/avrotorust.py +473 -0
  30. structurize-2.22.2/avrotize/avrotots.py +687 -0
  31. structurize-2.22.2/avrotize/avrotoxsd.py +344 -0
  32. structurize-2.22.2/avrotize/cddltostructure.py +1841 -0
  33. structurize-2.22.2/avrotize/commands.json +3527 -0
  34. structurize-2.22.2/avrotize/common.py +834 -0
  35. structurize-2.22.2/avrotize/constants.py +92 -0
  36. structurize-2.22.2/avrotize/csvtoavro.py +132 -0
  37. structurize-2.22.2/avrotize/datapackagetoavro.py +76 -0
  38. structurize-2.22.2/avrotize/dependencies/cpp/vcpkg/vcpkg.json +19 -0
  39. structurize-2.22.2/avrotize/dependencies/typescript/node22/package.json +16 -0
  40. structurize-2.22.2/avrotize/dependency_resolver.py +348 -0
  41. structurize-2.22.2/avrotize/dependency_version.py +432 -0
  42. structurize-2.22.2/avrotize/jsonstoavro.py +2167 -0
  43. structurize-2.22.2/avrotize/jsonstostructure.py +2864 -0
  44. structurize-2.22.2/avrotize/jstructtoavro.py +878 -0
  45. structurize-2.22.2/avrotize/kstructtoavro.py +93 -0
  46. structurize-2.22.2/avrotize/kustotoavro.py +455 -0
  47. structurize-2.22.2/avrotize/openapitostructure.py +717 -0
  48. structurize-2.22.2/avrotize/parquettoavro.py +157 -0
  49. structurize-2.22.2/avrotize/proto2parser.py +498 -0
  50. structurize-2.22.2/avrotize/proto3parser.py +403 -0
  51. structurize-2.22.2/avrotize/prototoavro.py +382 -0
  52. structurize-2.22.2/avrotize/structuretocddl.py +597 -0
  53. structurize-2.22.2/avrotize/structuretocpp.py +697 -0
  54. structurize-2.22.2/avrotize/structuretocsharp.py +2406 -0
  55. structurize-2.22.2/avrotize/structuretocsv.py +365 -0
  56. structurize-2.22.2/avrotize/structuretodatapackage.py +659 -0
  57. structurize-2.22.2/avrotize/structuretodb.py +1146 -0
  58. structurize-2.22.2/avrotize/structuretogo.py +757 -0
  59. structurize-2.22.2/avrotize/structuretographql.py +502 -0
  60. structurize-2.22.2/avrotize/structuretoiceberg.py +355 -0
  61. structurize-2.22.2/avrotize/structuretojava.py +959 -0
  62. structurize-2.22.2/avrotize/structuretojs.py +657 -0
  63. structurize-2.22.2/avrotize/structuretojsons.py +498 -0
  64. structurize-2.22.2/avrotize/structuretokusto.py +639 -0
  65. structurize-2.22.2/avrotize/structuretomd.py +322 -0
  66. structurize-2.22.2/avrotize/structuretoproto.py +764 -0
  67. structurize-2.22.2/avrotize/structuretopython.py +872 -0
  68. structurize-2.22.2/avrotize/structuretorust.py +714 -0
  69. structurize-2.22.2/avrotize/structuretots.py +741 -0
  70. structurize-2.22.2/avrotize/structuretoxsd.py +679 -0
  71. structurize-2.22.2/avrotize/xsdtoavro.py +413 -0
  72. structurize-2.22.2/build.ps1 +50 -0
  73. structurize-2.22.2/build.sh +37 -0
  74. structurize-2.22.2/pyproject.toml +71 -0
  75. structurize-2.22.2/setup.cfg +4 -0
  76. structurize-2.22.2/structurize.egg-info/PKG-INFO +107 -0
  77. structurize-2.22.2/structurize.egg-info/SOURCES.txt +248 -0
  78. structurize-2.22.2/structurize.egg-info/dependency_links.txt +1 -0
  79. structurize-2.22.2/structurize.egg-info/entry_points.txt +2 -0
  80. structurize-2.22.2/structurize.egg-info/requires.txt +34 -0
  81. structurize-2.22.2/structurize.egg-info/top_level.txt +1 -0
@@ -0,0 +1,15 @@
1
+ # Copied source directory for building
2
+ avrotize/
3
+
4
+ # Build artifacts
5
+ dist/
6
+ build/
7
+ *.egg-info/
8
+
9
+ # Python cache
10
+ __pycache__/
11
+ *.py[cod]
12
+ *$py.class
13
+
14
+ # Backup files
15
+ *.bak
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2018 CloudEvents Authors
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,6 @@
1
+ graft ../avrotize
2
+ include ../README.md
3
+ include ../LICENSE
4
+ include ../MANIFEST.in
5
+ global-exclude __pycache__
6
+ global-exclude *.py[co]
@@ -0,0 +1,107 @@
1
+ Metadata-Version: 2.4
2
+ Name: structurize
3
+ Version: 2.22.2
4
+ Summary: Tools to convert from and to JSON Structure from various other schema languages.
5
+ Author-email: Clemens Vasters <clemensv@microsoft.com>
6
+ Classifier: Programming Language :: Python :: 3
7
+ Classifier: License :: OSI Approved :: MIT License
8
+ Classifier: Operating System :: OS Independent
9
+ Requires-Python: >=3.10
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE
12
+ Requires-Dist: jsonschema>=4.23.0
13
+ Requires-Dist: lark>=1.1.9
14
+ Requires-Dist: pyarrow>=22.0.0
15
+ Requires-Dist: asn1tools>=0.167.0
16
+ Requires-Dist: jsonpointer>=3.0.0
17
+ Requires-Dist: jsonpath-ng>=1.6.1
18
+ Requires-Dist: jsoncomparison>=1.1.0
19
+ Requires-Dist: requests>=2.32.3
20
+ Requires-Dist: azure-kusto-data>=5.0.5
21
+ Requires-Dist: azure-identity>=1.17.1
22
+ Requires-Dist: datapackage>=1.15.4
23
+ Requires-Dist: jinja2>=3.1.4
24
+ Requires-Dist: pyiceberg>=0.10.0
25
+ Requires-Dist: pandas>=2.2.2
26
+ Requires-Dist: docker>=7.1.0
27
+ Provides-Extra: dev
28
+ Requires-Dist: pytest>=8.3.2; extra == "dev"
29
+ Requires-Dist: fastavro>=1.9.5; extra == "dev"
30
+ Requires-Dist: xmlschema>=3.3.2; extra == "dev"
31
+ Requires-Dist: xmlunittest>=1.0.1; extra == "dev"
32
+ Requires-Dist: pylint>=3.2.6; extra == "dev"
33
+ Requires-Dist: dataclasses_json>=0.6.7; extra == "dev"
34
+ Requires-Dist: dataclasses>=0.8; extra == "dev"
35
+ Requires-Dist: pydantic>=2.8.2; extra == "dev"
36
+ Requires-Dist: avro>=1.12.0; extra == "dev"
37
+ Requires-Dist: testcontainers>=4.7.2; extra == "dev"
38
+ Requires-Dist: pymysql>=1.1.1; extra == "dev"
39
+ Requires-Dist: psycopg2>=2.9.9; extra == "dev"
40
+ Requires-Dist: pyodbc>=5.1.0; extra == "dev"
41
+ Requires-Dist: pymongo>=4.8.0; extra == "dev"
42
+ Requires-Dist: oracledb>=2.3.0; extra == "dev"
43
+ Requires-Dist: cassandra-driver>=3.29.1; extra == "dev"
44
+ Requires-Dist: sqlalchemy>=2.0.32; extra == "dev"
45
+ Dynamic: license-file
46
+
47
+ # Structurize / Avrotize
48
+
49
+ **Structurize** is a powerful schema conversion toolkit that helps you transform between various schema formats including JSON Schema, JSON Structure, Avro Schema, Protocol Buffers, XSD, SQL, and many more.
50
+
51
+ This package is published under two names:
52
+
53
+ - **`structurize`** - The primary package name, emphasizing JSON Structure conversion capabilities
54
+ - **`avrotize`** - The original package name, emphasizing Avro Schema conversion capabilities
55
+
56
+ Both packages currently share the same features and codebase. However, in future releases, Avro-focused and JSON Structure-focused features may be split across the two tools to make the feature list more manageable and focused for users. Choose whichever variant better aligns with your primary use case.
57
+
58
+ ## Quick Start
59
+
60
+ Install the package:
61
+
62
+ ```bash
63
+ pip install structurize
64
+ ```
65
+
66
+ or
67
+
68
+ ```bash
69
+ pip install avrotize
70
+ ```
71
+
72
+ Use the CLI:
73
+
74
+ ```bash
75
+ # Using structurize
76
+ structurize --help
77
+
78
+ # Or using avrotize
79
+ avrotize --help
80
+ ```
81
+
82
+ ## Key Features
83
+
84
+ - Convert between JSON Schema, JSON Structure, and Avro Schema
85
+ - Transform schemas to and from Protocol Buffers, XSD, ASN.1
86
+ - Generate code in C#, Python, TypeScript, Java, Go, Rust, C++, JavaScript
87
+ - Export schemas to SQL databases (MySQL, PostgreSQL, SQL Server, Oracle, Cassandra, MongoDB, DynamoDB, and more)
88
+ - Convert to Parquet, Iceberg, Kusto, and other data formats
89
+ - Generate documentation in Markdown
90
+
91
+ ## Documentation
92
+
93
+ For complete documentation, examples, and detailed usage instructions, please see the main repository:
94
+
95
+ **[📖 Full Documentation](https://github.com/clemensv/avrotize)**
96
+
97
+ The main README includes:
98
+
99
+ - Comprehensive command reference
100
+ - Conversion examples and use cases
101
+ - Code generation guides
102
+ - Database schema export instructions
103
+ - API documentation
104
+
105
+ ## License
106
+
107
+ MIT License - see the [LICENSE](../LICENSE) file in the repository root.
@@ -0,0 +1,61 @@
1
+ # Structurize / Avrotize
2
+
3
+ **Structurize** is a powerful schema conversion toolkit that helps you transform between various schema formats including JSON Schema, JSON Structure, Avro Schema, Protocol Buffers, XSD, SQL, and many more.
4
+
5
+ This package is published under two names:
6
+
7
+ - **`structurize`** - The primary package name, emphasizing JSON Structure conversion capabilities
8
+ - **`avrotize`** - The original package name, emphasizing Avro Schema conversion capabilities
9
+
10
+ Both packages currently share the same features and codebase. However, in future releases, Avro-focused and JSON Structure-focused features may be split across the two tools to make the feature list more manageable and focused for users. Choose whichever variant better aligns with your primary use case.
11
+
12
+ ## Quick Start
13
+
14
+ Install the package:
15
+
16
+ ```bash
17
+ pip install structurize
18
+ ```
19
+
20
+ or
21
+
22
+ ```bash
23
+ pip install avrotize
24
+ ```
25
+
26
+ Use the CLI:
27
+
28
+ ```bash
29
+ # Using structurize
30
+ structurize --help
31
+
32
+ # Or using avrotize
33
+ avrotize --help
34
+ ```
35
+
36
+ ## Key Features
37
+
38
+ - Convert between JSON Schema, JSON Structure, and Avro Schema
39
+ - Transform schemas to and from Protocol Buffers, XSD, ASN.1
40
+ - Generate code in C#, Python, TypeScript, Java, Go, Rust, C++, JavaScript
41
+ - Export schemas to SQL databases (MySQL, PostgreSQL, SQL Server, Oracle, Cassandra, MongoDB, DynamoDB, and more)
42
+ - Convert to Parquet, Iceberg, Kusto, and other data formats
43
+ - Generate documentation in Markdown
44
+
45
+ ## Documentation
46
+
47
+ For complete documentation, examples, and detailed usage instructions, please see the main repository:
48
+
49
+ **[📖 Full Documentation](https://github.com/clemensv/avrotize)**
50
+
51
+ The main README includes:
52
+
53
+ - Comprehensive command reference
54
+ - Conversion examples and use cases
55
+ - Code generation guides
56
+ - Database schema export instructions
57
+ - API documentation
58
+
59
+ ## License
60
+
61
+ MIT License - see the [LICENSE](../LICENSE) file in the repository root.
@@ -0,0 +1,66 @@
1
+ import importlib
2
+
3
+ mod = "avrotize"
4
+ class LazyLoader:
5
+ """
6
+ Lazy loader for the avrotize functions to speed up startup time.
7
+ """
8
+ def __init__(self, mappings):
9
+ self._modules = {}
10
+ self._mappings = mappings
11
+
12
+ def _load_module(self, module_name):
13
+ if module_name not in self._modules:
14
+ self._modules[module_name] = importlib.import_module(module_name)
15
+ return self._modules[module_name]
16
+
17
+ def __getattr__(self, item):
18
+ if item in self._mappings:
19
+ module_name, func_name = self._mappings[item]
20
+ module = self._load_module(module_name)
21
+ return getattr(module, func_name)
22
+ else:
23
+ return self._load_module(f"{mod}.{item}")
24
+
25
+ # Define the functions and their corresponding module paths
26
+ _mappings = {
27
+ "convert_proto_to_avro": (f"{mod}.prototoavro", "convert_proto_to_avro"),
28
+ "convert_jsons_to_avro": (f"{mod}.jsonstoavro", "convert_jsons_to_avro"),
29
+ "convert_kafka_struct_to_avro_schema": (f"{mod}.kstructtoavro", "convert_kafka_struct_to_avro_schema"),
30
+ "convert_kusto_to_avro": (f"{mod}.kustotoavro", "convert_kusto_to_avro"),
31
+ "convert_asn1_to_avro": (f"{mod}.asn1toavro", "convert_asn1_to_avro"),
32
+ "convert_xsd_to_avro": (f"{mod}.xsdtoavro", "convert_xsd_to_avro"),
33
+ "convert_avro_to_json_schema": (f"{mod}.avrotojsons", "convert_avro_to_json_schema"),
34
+ "convert_avro_to_kusto_file": (f"{mod}.avrotokusto", "convert_avro_to_kusto_file"),
35
+ "convert_avro_to_kusto_db": (f"{mod}.avrotokusto", "convert_avro_to_kusto_db"),
36
+ "convert_avro_to_parquet": (f"{mod}.avrotoparquet", "convert_avro_to_parquet"),
37
+ "convert_avro_to_proto": (f"{mod}.avrotoproto", "convert_avro_to_proto"),
38
+ "convert_avro_to_sql": (f"{mod}.avrotodb", "convert_avro_to_sql"),
39
+ "convert_avro_to_xsd": (f"{mod}.avrotoxsd", "convert_avro_to_xsd"),
40
+ "convert_avro_to_java": (f"{mod}.avrotojava", "convert_avro_to_java"),
41
+ "convert_avro_schema_to_java": (f"{mod}.avrotojava", "convert_avro_schema_to_java"),
42
+ "convert_avro_to_csharp": (f"{mod}.avrotocsharp", "convert_avro_to_csharp"),
43
+ "convert_avro_schema_to_csharp": (f"{mod}.avrotocsharp", "convert_avro_schema_to_csharp"),
44
+ "convert_avro_to_python": (f"{mod}.avrotopython", "convert_avro_to_python"),
45
+ "convert_avro_schema_to_python": (f"{mod}.avrotopython", "convert_avro_schema_to_python"),
46
+ "convert_avro_to_typescript": (f"{mod}.avrotots", "convert_avro_to_typescript"),
47
+ "convert_avro_schema_to_typescript": (f"{mod}.avrotots", "convert_avro_schema_to_typescript"),
48
+ "convert_avro_to_javascript": (f"{mod}.avrotojs", "convert_avro_to_javascript"),
49
+ "convert_avro_schema_to_javascript": (f"{mod}.avrotojs", "convert_avro_schema_to_javascript"),
50
+ "convert_avro_to_markdown": (f"{mod}.avrotomd", "convert_avro_to_markdown"),
51
+ "convert_structure_to_markdown": (f"{mod}.structuretomd", "convert_structure_to_markdown"),
52
+ "convert_avro_to_cpp": (f"{mod}.avrotocpp", "convert_avro_to_cpp"),
53
+ "convert_avro_schema_to_cpp": (f"{mod}.avrotocpp", "convert_avro_schema_to_cpp"),
54
+ "convert_avro_to_go": (f"{mod}.avrotogo", "convert_avro_to_go"),
55
+ "convert_avro_schema_to_go": (f"{mod}.avrotogo", "convert_avro_schema_to_go"),
56
+ "convert_avro_to_rust": (f"{mod}.avrotorust", "convert_avro_to_rust"),
57
+ "convert_avro_schema_to_rust": (f"{mod}.avrotorust", "convert_avro_schema_to_rust"),
58
+ "convert_avro_to_datapackage": (f"{mod}.avrotodatapackage", "convert_avro_to_datapackage"),
59
+ "convert_structure_to_javascript": (f"{mod}.structuretojs", "convert_structure_to_javascript"),
60
+ "convert_structure_schema_to_javascript": (f"{mod}.structuretojs", "convert_structure_schema_to_javascript"),
61
+ }
62
+
63
+ _lazy_loader = LazyLoader(_mappings)
64
+
65
+ def __getattr__(name):
66
+ return getattr(_lazy_loader, name)
@@ -0,0 +1,6 @@
1
+ # __main__.py
2
+
3
+ from . import avrotize
4
+
5
+ if __name__ == '__main__':
6
+ avrotize.main()
@@ -0,0 +1,34 @@
1
+ # file generated by setuptools-scm
2
+ # don't change, don't track in version control
3
+
4
+ __all__ = [
5
+ "__version__",
6
+ "__version_tuple__",
7
+ "version",
8
+ "version_tuple",
9
+ "__commit_id__",
10
+ "commit_id",
11
+ ]
12
+
13
+ TYPE_CHECKING = False
14
+ if TYPE_CHECKING:
15
+ from typing import Tuple
16
+ from typing import Union
17
+
18
+ VERSION_TUPLE = Tuple[Union[int, str], ...]
19
+ COMMIT_ID = Union[str, None]
20
+ else:
21
+ VERSION_TUPLE = object
22
+ COMMIT_ID = object
23
+
24
+ version: str
25
+ __version__: str
26
+ __version_tuple__: VERSION_TUPLE
27
+ version_tuple: VERSION_TUPLE
28
+ commit_id: COMMIT_ID
29
+ __commit_id__: COMMIT_ID
30
+
31
+ __version__ = version = '2.22.2'
32
+ __version_tuple__ = version_tuple = (2, 22, 2)
33
+
34
+ __commit_id__ = commit_id = 'g25efcf5da'
@@ -0,0 +1,160 @@
1
+ import json
2
+ from typing import List
3
+ import asn1tools
4
+ from asn1tools.codecs.ber import Sequence, SequenceOf, Integer, Boolean, Enumerated, OctetString, IA5String, UTF8String, Date, Real, Choice, Null, SetOf, Recursive, ExplicitTag
5
+ from asn1tools.codecs.ber import BitString, VisibleString, BMPString, GeneralString, GraphicString, NumericString, PrintableString, TeletexString, UniversalString, ObjectIdentifier, Set
6
+
7
+ from avrotize.common import avro_name
8
+ from avrotize.dependency_resolver import sort_messages_by_dependencies
9
+
10
+ def asn1_type_to_avro_type(asn1_type: dict, avro_schema: list, namespace: str, parent_type_name: str | None, parent_member_name: str | None, dependencies: list)-> str | dict | None:
11
+ """Convert an ASN.1 type to an Avro type."""
12
+ avro_type: str | dict | list | None = None
13
+ deps: List[str] = []
14
+
15
+ if isinstance(asn1_type,Integer):
16
+ avro_type = 'int'
17
+ elif isinstance(asn1_type, Boolean):
18
+ avro_type = 'boolean'
19
+ elif isinstance(asn1_type, Enumerated):
20
+ symbols = [avro_name(member) for member in asn1_type.data_to_value.keys()]
21
+ avro_type = {
22
+ 'type': 'enum',
23
+ 'name': avro_name(parent_member_name if parent_member_name else asn1_type.name),
24
+ 'namespace': namespace,
25
+ 'symbols': symbols
26
+ }
27
+ elif isinstance(asn1_type, Sequence) or isinstance(asn1_type, Choice) or isinstance(asn1_type, Set):
28
+ if avro_schema and next((s for s in avro_schema if s.get('name') == asn1_type.type_name), []):
29
+ return namespace + '.' + asn1_type.type_name
30
+ else:
31
+ record_name = asn1_type.type_name if asn1_type.type_name else asn1_type.name
32
+ if record_name == 'CHOICE' or record_name == 'SEQUENCE' or record_name == 'SET':
33
+ if parent_member_name and parent_type_name:
34
+ record_name = parent_type_name + parent_member_name
35
+ elif parent_type_name:
36
+ record_name = parent_type_name
37
+ else:
38
+ raise ValueError(f"Can't name record without a type name and member name")
39
+
40
+ fields = []
41
+ for member in asn1_type.members if isinstance(asn1_type, Choice) else asn1_type.root_members:
42
+ field_type = asn1_type_to_avro_type(member, avro_schema, namespace, record_name, member.name, deps)
43
+ if isinstance(field_type, dict) and (field_type.get('type') == 'record' or field_type.get('type') == 'enum'):
44
+ existing_type = next((t for t in avro_schema if (isinstance(t,dict) and t.get('name') == field_type['name'] and t.get('namespace') == field_type.get('namespace')) ), None)
45
+ if not existing_type:
46
+ field_type['dependencies'] = [dep for dep in deps if dep != field_type['namespace']+'.'+field_type['name']]
47
+ avro_schema.append(field_type)
48
+ field_type = namespace + '.' + field_type.get('name','')
49
+ dependencies.append(field_type)
50
+ if isinstance(asn1_type, Choice):
51
+ field_type = [field_type, 'null']
52
+ fields.append({
53
+ 'name': avro_name(member.name),
54
+ 'type': field_type
55
+ })
56
+
57
+ avro_type = {
58
+ 'type': 'record',
59
+ 'name': avro_name(record_name),
60
+ 'namespace': namespace,
61
+ 'fields': fields
62
+ }
63
+ elif isinstance(asn1_type, BitString):
64
+ avro_type = {
65
+ 'type': 'bytes',
66
+ 'logicalType': 'bitstring'
67
+ }
68
+ elif isinstance(asn1_type, ObjectIdentifier):
69
+ avro_type = 'string'
70
+ elif isinstance(asn1_type, SequenceOf):
71
+ record_name = asn1_type.name if asn1_type.name else parent_member_name
72
+ if record_name == 'SEQUENCE OF':
73
+ record_name = parent_member_name if parent_member_name else ''
74
+ if parent_type_name:
75
+ record_name = parent_type_name + record_name
76
+ item_type = asn1_type_to_avro_type(asn1_type.element_type, avro_schema, namespace, record_name, 'Item', deps)
77
+ if isinstance(item_type, dict) and not item_type.get('name'):
78
+ item_type['name'] = asn1_type.name + 'Item'
79
+ avro_type = {
80
+ 'type': 'array',
81
+ 'namespace': namespace,
82
+ 'name': avro_name(record_name),
83
+ 'items': item_type
84
+ }
85
+ elif isinstance(asn1_type, SetOf):
86
+ record_name = asn1_type.name if asn1_type.name else parent_member_name
87
+ if record_name == 'SET OF':
88
+ record_name = parent_member_name if parent_member_name else ''
89
+ if parent_type_name:
90
+ record_name = parent_type_name + record_name
91
+ item_type = asn1_type_to_avro_type(asn1_type.element_type, avro_schema, namespace, record_name, 'Item', deps)
92
+ if isinstance(item_type, dict) and not item_type.get('name'):
93
+ item_type['name'] = asn1_type.name + 'Item'
94
+ avro_type = {
95
+ 'type': 'array',
96
+ 'namespace': namespace,
97
+ 'name': avro_name(record_name),
98
+ 'items': item_type
99
+ }
100
+ elif isinstance(asn1_type, OctetString):
101
+ avro_type = 'bytes'
102
+ elif isinstance(asn1_type, IA5String) or isinstance(asn1_type, UTF8String) or isinstance(asn1_type, VisibleString) or isinstance(asn1_type, BMPString) or isinstance(asn1_type, GeneralString) or isinstance(asn1_type, GraphicString) or isinstance(asn1_type, NumericString) or isinstance(asn1_type, PrintableString) or isinstance(asn1_type, TeletexString) or isinstance(asn1_type, UniversalString):
103
+ avro_type = 'string'
104
+ elif isinstance(asn1_type, Date):
105
+ avro_type = {'type': 'int', 'logicalType': 'date'}
106
+ elif isinstance(asn1_type, Real):
107
+ avro_type = 'double'
108
+ elif isinstance(asn1_type, Null):
109
+ avro_type = 'null'
110
+ elif isinstance(asn1_type, Recursive):
111
+ avro_type = asn1_type.type_name
112
+ elif isinstance(asn1_type, ExplicitTag):
113
+ avro_type = asn1_type_to_avro_type(asn1_type.inner, avro_schema, namespace, parent_type_name, parent_member_name, dependencies)
114
+ if isinstance(avro_type, dict):
115
+ avro_type['name'] = asn1_type.name if asn1_type.name else asn1_type.type_name
116
+ else:
117
+ raise ValueError(f"Don't know how to translate ASN.1 type '{type(asn1_type)}' to Avro")
118
+
119
+ if len(avro_schema) > 0 and isinstance(avro_type, dict) and 'name' in avro_type:
120
+ existing_type = next((t for t in avro_schema if (isinstance(t,dict) and t.get('name') == avro_type['name'] and t.get('namespace') == avro_type.get('namespace')) ), None)
121
+ if existing_type:
122
+ qualified_name = namespace + '.' + existing_type.get('name','')
123
+ dependencies.append(qualified_name)
124
+ return qualified_name
125
+
126
+ return avro_type
127
+
128
+ def convert_asn1_to_avro_schema(asn1_spec_list: List[str]):
129
+ """Convert ASN.1 specification to Avro schema."""
130
+
131
+ try:
132
+ spec = asn1tools.compile_files(asn1_spec_list)
133
+ except asn1tools.ParseError as e:
134
+ print(f"Error parsing ASN.1 files: {e.args[0]}")
135
+ for file in asn1_spec_list:
136
+ print(f" {file}")
137
+ return None
138
+
139
+ avro_schema: List[dict] = []
140
+ for module_name, module in spec.modules.items():
141
+ for type_name, asn1_type in module.items():
142
+ dependencies: List [str] = []
143
+ avro_type = asn1_type_to_avro_type(asn1_type.type, avro_schema, avro_name(module_name), type_name, None, dependencies)
144
+ if avro_type and not isinstance(avro_type, str):
145
+ avro_type['dependencies'] = [dep for dep in dependencies if dep != avro_type['namespace'] + '.' + avro_type['name']]
146
+ avro_schema.append(avro_type)
147
+
148
+ avro_schema = sort_messages_by_dependencies(avro_schema)
149
+
150
+ if len(avro_schema) == 1:
151
+ return avro_schema[0]
152
+ return avro_schema
153
+
154
+ def convert_asn1_to_avro(asn1_spec_list: List[str], avro_file_path: str):
155
+ """Convert ASN.1 specification to Avro schema and save it to a file."""
156
+ avro_schema = convert_asn1_to_avro_schema(asn1_spec_list)
157
+ if avro_schema is None:
158
+ return
159
+ with open(avro_file_path, 'w') as file:
160
+ json.dump(avro_schema, file, indent=4)