structurize 2.16.2__py3-none-any.whl → 2.16.5__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 (53) hide show
  1. avrotize/__init__.py +63 -63
  2. avrotize/__main__.py +5 -5
  3. avrotize/_version.py +34 -34
  4. avrotize/asn1toavro.py +160 -160
  5. avrotize/avrotize.py +152 -152
  6. avrotize/avrotocpp.py +483 -483
  7. avrotize/avrotocsharp.py +992 -992
  8. avrotize/avrotocsv.py +121 -121
  9. avrotize/avrotodatapackage.py +173 -173
  10. avrotize/avrotodb.py +1383 -1383
  11. avrotize/avrotogo.py +476 -476
  12. avrotize/avrotographql.py +197 -197
  13. avrotize/avrotoiceberg.py +210 -210
  14. avrotize/avrotojava.py +1023 -1023
  15. avrotize/avrotojs.py +250 -250
  16. avrotize/avrotojsons.py +481 -481
  17. avrotize/avrotojstruct.py +345 -345
  18. avrotize/avrotokusto.py +363 -363
  19. avrotize/avrotomd.py +137 -137
  20. avrotize/avrotools.py +168 -168
  21. avrotize/avrotoparquet.py +208 -208
  22. avrotize/avrotoproto.py +358 -358
  23. avrotize/avrotopython.py +622 -622
  24. avrotize/avrotorust.py +435 -435
  25. avrotize/avrotots.py +598 -598
  26. avrotize/avrotoxsd.py +344 -344
  27. avrotize/commands.json +2493 -2433
  28. avrotize/common.py +828 -828
  29. avrotize/constants.py +4 -4
  30. avrotize/csvtoavro.py +131 -131
  31. avrotize/datapackagetoavro.py +76 -76
  32. avrotize/dependency_resolver.py +348 -348
  33. avrotize/jsonstoavro.py +1698 -1698
  34. avrotize/jsonstostructure.py +2642 -2642
  35. avrotize/jstructtoavro.py +878 -878
  36. avrotize/kstructtoavro.py +93 -93
  37. avrotize/kustotoavro.py +455 -455
  38. avrotize/parquettoavro.py +157 -157
  39. avrotize/proto2parser.py +497 -497
  40. avrotize/proto3parser.py +402 -402
  41. avrotize/prototoavro.py +382 -382
  42. avrotize/structuretocsharp.py +2005 -2005
  43. avrotize/structuretojsons.py +498 -498
  44. avrotize/structuretopython.py +772 -772
  45. avrotize/structuretots.py +653 -0
  46. avrotize/xsdtoavro.py +413 -413
  47. {structurize-2.16.2.dist-info → structurize-2.16.5.dist-info}/METADATA +848 -805
  48. structurize-2.16.5.dist-info/RECORD +52 -0
  49. {structurize-2.16.2.dist-info → structurize-2.16.5.dist-info}/licenses/LICENSE +200 -200
  50. structurize-2.16.2.dist-info/RECORD +0 -51
  51. {structurize-2.16.2.dist-info → structurize-2.16.5.dist-info}/WHEEL +0 -0
  52. {structurize-2.16.2.dist-info → structurize-2.16.5.dist-info}/entry_points.txt +0 -0
  53. {structurize-2.16.2.dist-info → structurize-2.16.5.dist-info}/top_level.txt +0 -0
avrotize/kstructtoavro.py CHANGED
@@ -1,93 +1,93 @@
1
- """
2
-
3
- Convert a Kafka schema to an Avro schema.
4
-
5
- """
6
-
7
- import json
8
-
9
-
10
- def kafka_type_to_avro_type(kafka_field):
11
- """Convert a Kafka field type to an Avro field type."""
12
- kafka_to_avro_types = {
13
- 'int32': 'int',
14
- 'int64': 'long',
15
- 'string': 'string',
16
- 'boolean': 'boolean',
17
- 'bytes': 'bytes',
18
- 'array': 'array',
19
- 'map': 'map',
20
- 'struct': 'record'
21
- }
22
-
23
- if kafka_field['type'] in kafka_to_avro_types:
24
- return kafka_to_avro_types[kafka_field['type']]
25
- elif isinstance(kafka_field['type'], dict): # Nested struct
26
- return convert_schema(kafka_field['type'])
27
- else:
28
- raise ValueError(f"Unsupported Kafka type: {kafka_field['type']}")
29
-
30
-
31
- def convert_field(field):
32
- """Convert a Kafka field to an Avro field."""
33
- avro_field = {
34
- 'name': field['field'],
35
- 'type': []
36
- }
37
-
38
- if field['optional']:
39
- avro_field['type'].append('null')
40
-
41
- kafka_field_type = kafka_type_to_avro_type(field)
42
-
43
- if field['type'] == 'array':
44
- item_type = kafka_type_to_avro_type(field['items'])
45
- avro_field['type'].append({'type': 'array', 'items': item_type})
46
- elif field['type'] == 'map':
47
- value_type = kafka_type_to_avro_type(field['values'])
48
- avro_field['type'].append({'type': 'map', 'values': value_type})
49
- elif field['type'] == 'struct':
50
- avro_field['type'].append(convert_schema(field))
51
- else:
52
- avro_field['type'].append(kafka_field_type)
53
-
54
- if len(avro_field['type']) == 1:
55
- avro_field['type'] = avro_field['type'][0]
56
-
57
- return avro_field
58
-
59
-
60
- def convert_schema(kafka_schema):
61
- """Convert a Kafka schema to an Avro schema."""
62
- avro_schema = {
63
- 'type': 'record',
64
- 'name': kafka_schema.get('name', 'MyRecord'),
65
- 'fields': []
66
- }
67
-
68
- for field in kafka_schema['fields']:
69
- avro_schema['fields'].append(convert_field(field))
70
-
71
- return avro_schema
72
-
73
-
74
- def convert_kafka_struct_to_avro_schema(kafka_schema_file_path, avro_file_path):
75
- """Read a Kafka schema from a file, convert it to an Avro schema, and save it to another file."""
76
-
77
- if not kafka_schema_file_path:
78
- raise ValueError("Kafka schema file path is required.")
79
-
80
- # Open and read the Kafka schema file
81
- with open(kafka_schema_file_path, 'r', encoding='utf-8') as kafka_schema_file:
82
- kafka_schema_data = json.load(kafka_schema_file)
83
-
84
- # Assuming the whole file content is the schema
85
- if isinstance(kafka_schema_data, dict) and 'schema' in kafka_schema_data:
86
- kafka_schema = kafka_schema_data['schema']
87
- else:
88
- kafka_schema = kafka_schema_data
89
- avro_schema = convert_schema(kafka_schema)
90
-
91
- # Write the converted Avro schema to a file
92
- with open(avro_file_path, 'w', encoding='utf-8') as avro_file:
93
- json.dump(avro_schema, avro_file, indent=4)
1
+ """
2
+
3
+ Convert a Kafka schema to an Avro schema.
4
+
5
+ """
6
+
7
+ import json
8
+
9
+
10
+ def kafka_type_to_avro_type(kafka_field):
11
+ """Convert a Kafka field type to an Avro field type."""
12
+ kafka_to_avro_types = {
13
+ 'int32': 'int',
14
+ 'int64': 'long',
15
+ 'string': 'string',
16
+ 'boolean': 'boolean',
17
+ 'bytes': 'bytes',
18
+ 'array': 'array',
19
+ 'map': 'map',
20
+ 'struct': 'record'
21
+ }
22
+
23
+ if kafka_field['type'] in kafka_to_avro_types:
24
+ return kafka_to_avro_types[kafka_field['type']]
25
+ elif isinstance(kafka_field['type'], dict): # Nested struct
26
+ return convert_schema(kafka_field['type'])
27
+ else:
28
+ raise ValueError(f"Unsupported Kafka type: {kafka_field['type']}")
29
+
30
+
31
+ def convert_field(field):
32
+ """Convert a Kafka field to an Avro field."""
33
+ avro_field = {
34
+ 'name': field['field'],
35
+ 'type': []
36
+ }
37
+
38
+ if field['optional']:
39
+ avro_field['type'].append('null')
40
+
41
+ kafka_field_type = kafka_type_to_avro_type(field)
42
+
43
+ if field['type'] == 'array':
44
+ item_type = kafka_type_to_avro_type(field['items'])
45
+ avro_field['type'].append({'type': 'array', 'items': item_type})
46
+ elif field['type'] == 'map':
47
+ value_type = kafka_type_to_avro_type(field['values'])
48
+ avro_field['type'].append({'type': 'map', 'values': value_type})
49
+ elif field['type'] == 'struct':
50
+ avro_field['type'].append(convert_schema(field))
51
+ else:
52
+ avro_field['type'].append(kafka_field_type)
53
+
54
+ if len(avro_field['type']) == 1:
55
+ avro_field['type'] = avro_field['type'][0]
56
+
57
+ return avro_field
58
+
59
+
60
+ def convert_schema(kafka_schema):
61
+ """Convert a Kafka schema to an Avro schema."""
62
+ avro_schema = {
63
+ 'type': 'record',
64
+ 'name': kafka_schema.get('name', 'MyRecord'),
65
+ 'fields': []
66
+ }
67
+
68
+ for field in kafka_schema['fields']:
69
+ avro_schema['fields'].append(convert_field(field))
70
+
71
+ return avro_schema
72
+
73
+
74
+ def convert_kafka_struct_to_avro_schema(kafka_schema_file_path, avro_file_path):
75
+ """Read a Kafka schema from a file, convert it to an Avro schema, and save it to another file."""
76
+
77
+ if not kafka_schema_file_path:
78
+ raise ValueError("Kafka schema file path is required.")
79
+
80
+ # Open and read the Kafka schema file
81
+ with open(kafka_schema_file_path, 'r', encoding='utf-8') as kafka_schema_file:
82
+ kafka_schema_data = json.load(kafka_schema_file)
83
+
84
+ # Assuming the whole file content is the schema
85
+ if isinstance(kafka_schema_data, dict) and 'schema' in kafka_schema_data:
86
+ kafka_schema = kafka_schema_data['schema']
87
+ else:
88
+ kafka_schema = kafka_schema_data
89
+ avro_schema = convert_schema(kafka_schema)
90
+
91
+ # Write the converted Avro schema to a file
92
+ with open(avro_file_path, 'w', encoding='utf-8') as avro_file:
93
+ json.dump(avro_schema, avro_file, indent=4)