pydantic-avro 0.7.3__py3-none-any.whl → 0.8.1__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.
- pydantic_avro/to_avro/types.py +47 -0
- {pydantic_avro-0.7.3.dist-info → pydantic_avro-0.8.1.dist-info}/METADATA +12 -1
- {pydantic_avro-0.7.3.dist-info → pydantic_avro-0.8.1.dist-info}/RECORD +6 -7
- pydantic_avro-0.7.3.dist-info/LICENSE +0 -21
- /LICENSE → /pydantic_avro-0.8.1.dist-info/LICENSE +0 -0
- {pydantic_avro-0.7.3.dist-info → pydantic_avro-0.8.1.dist-info}/WHEEL +0 -0
- {pydantic_avro-0.7.3.dist-info → pydantic_avro-0.8.1.dist-info}/entry_points.txt +0 -0
pydantic_avro/to_avro/types.py
CHANGED
|
@@ -22,6 +22,45 @@ STRING_TYPE_MAPPING = {
|
|
|
22
22
|
"binary": "bytes",
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
AVRO_TYPE_MAPPING = {
|
|
26
|
+
"timestamp-millis": {
|
|
27
|
+
"type": "long",
|
|
28
|
+
"logicalType": "timestamp-millis",
|
|
29
|
+
},
|
|
30
|
+
"timestamp-micros": {
|
|
31
|
+
"type": "long",
|
|
32
|
+
"logicalType": "timestamp-micros",
|
|
33
|
+
},
|
|
34
|
+
"time-millis": {
|
|
35
|
+
"type": "int",
|
|
36
|
+
"logicalType": "time-millis",
|
|
37
|
+
},
|
|
38
|
+
"time-micros": {
|
|
39
|
+
"type": "long",
|
|
40
|
+
"logicalType": "time-micros",
|
|
41
|
+
},
|
|
42
|
+
"decimal": {
|
|
43
|
+
"type": "bytes",
|
|
44
|
+
"logicalType": "decimal",
|
|
45
|
+
},
|
|
46
|
+
"uuid": {
|
|
47
|
+
"type": "string",
|
|
48
|
+
"logicalType": "uuid",
|
|
49
|
+
},
|
|
50
|
+
"int": "int",
|
|
51
|
+
"long": "long",
|
|
52
|
+
"float": "float",
|
|
53
|
+
"double": "double",
|
|
54
|
+
"boolean": "boolean",
|
|
55
|
+
"bytes": "bytes",
|
|
56
|
+
"string": "string",
|
|
57
|
+
"null": "null",
|
|
58
|
+
"date": {
|
|
59
|
+
"type": "int",
|
|
60
|
+
"logicalType": "date",
|
|
61
|
+
},
|
|
62
|
+
}
|
|
63
|
+
|
|
25
64
|
|
|
26
65
|
def get_definition(ref: str, schema: dict):
|
|
27
66
|
"""Reading definition of base schema for nested structs"""
|
|
@@ -91,6 +130,7 @@ class AvroTypeConverter:
|
|
|
91
130
|
t = field_props.get("type")
|
|
92
131
|
f = field_props.get("format")
|
|
93
132
|
r = field_props.get("$ref")
|
|
133
|
+
at = field_props.get("avro_type")
|
|
94
134
|
if "allOf" in field_props and len(field_props["allOf"]) == 1:
|
|
95
135
|
r = field_props["allOf"][0]["$ref"]
|
|
96
136
|
u = field_props.get("anyOf")
|
|
@@ -101,6 +141,13 @@ class AvroTypeConverter:
|
|
|
101
141
|
return self._handle_references(r, avro_type_dict)
|
|
102
142
|
elif t is None:
|
|
103
143
|
raise ValueError(f"Field '{field_props}' does not have a defined type.")
|
|
144
|
+
elif at is not None:
|
|
145
|
+
if not isinstance(at, str) or at not in AVRO_TYPE_MAPPING:
|
|
146
|
+
raise ValueError(
|
|
147
|
+
f"Field '{field_props}' does not have a supported avro_type. Type should be one of "
|
|
148
|
+
f" {AVRO_TYPE_MAPPING.keys()}"
|
|
149
|
+
)
|
|
150
|
+
avro_type_dict["type"] = AVRO_TYPE_MAPPING[at]
|
|
104
151
|
elif t == "array":
|
|
105
152
|
return self._array_to_avro(field_props, avro_type_dict)
|
|
106
153
|
elif t == "string":
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: pydantic-avro
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.8.1
|
|
4
4
|
Summary: Converting pydantic classes to avro schemas
|
|
5
5
|
Home-page: https://github.com/godatadriven/pydantic-avro
|
|
6
6
|
License: MIT
|
|
@@ -62,6 +62,17 @@ pydantic-avro avro_to_pydantic --asvc /path/to/schema.asvc
|
|
|
62
62
|
pydantic-avro avro_to_pydantic --asvc /path/to/schema.asvc --output /path/to/output.py
|
|
63
63
|
```
|
|
64
64
|
|
|
65
|
+
### Specify expected Avro type
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
from datetime import datetime
|
|
69
|
+
from pydantic import Field
|
|
70
|
+
from pydantic_avro.base import AvroBase
|
|
71
|
+
|
|
72
|
+
class ExampleModel(AvroBase):
|
|
73
|
+
field1: int = Field(..., avro_type="long") # Explicitly set Avro type to "long"
|
|
74
|
+
field2: datetime = Field(..., avro_type="timestamp-millis") # Explicitly set Avro type to "timestamp-millis"
|
|
75
|
+
```
|
|
65
76
|
|
|
66
77
|
### Install for developers
|
|
67
78
|
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
LICENSE,sha256=gBlYCG1yxb0vGlsmek0lMPVOK5YDxQope4F54jzeqoY,1069
|
|
2
1
|
pydantic_avro/__init__.py,sha256=P4vaozEL8Rea7xWdB6ENj3DNF2RPPOWascfwbtQS7gE,48
|
|
3
2
|
pydantic_avro/__main__.py,sha256=-AL9FNYsAdFmilm-96MbbxymTW6QminXPCBZJ1nkqBE,695
|
|
4
3
|
pydantic_avro/base.py,sha256=i1wco_T6FXFdtlxzbzXt3Jv93TmTzTfJ493KCfZh1dc,78
|
|
@@ -10,9 +9,9 @@ pydantic_avro/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
|
10
9
|
pydantic_avro/to_avro/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
11
10
|
pydantic_avro/to_avro/base.py,sha256=Y8QOGTpXO3BwJ6arrRK-k2JniK5kLTvlDpQ0PyZojmg,1409
|
|
12
11
|
pydantic_avro/to_avro/config.py,sha256=R9HLkWiXs7YZ02te8CQt5Kf2rbsE8Fx-hjqv3tBSFJU,152
|
|
13
|
-
pydantic_avro/to_avro/types.py,sha256=
|
|
14
|
-
pydantic_avro-0.
|
|
15
|
-
pydantic_avro-0.
|
|
16
|
-
pydantic_avro-0.
|
|
17
|
-
pydantic_avro-0.
|
|
18
|
-
pydantic_avro-0.
|
|
12
|
+
pydantic_avro/to_avro/types.py,sha256=9bGoTDxejaHUsKRvQxwqF3-k7NGHU-vjTnhzR3o8m8o,8980
|
|
13
|
+
pydantic_avro-0.8.1.dist-info/entry_points.txt,sha256=gwHiQfbGLO8Np2sa1bZ_bpxU7sEufx6IachViBE_Fnw,66
|
|
14
|
+
pydantic_avro-0.8.1.dist-info/LICENSE,sha256=gBlYCG1yxb0vGlsmek0lMPVOK5YDxQope4F54jzeqoY,1069
|
|
15
|
+
pydantic_avro-0.8.1.dist-info/WHEEL,sha256=vxFmldFsRN_Hx10GDvsdv1wroKq8r5Lzvjp6GZ4OO8c,88
|
|
16
|
+
pydantic_avro-0.8.1.dist-info/METADATA,sha256=PQHBW2nLJ87OPKIpUwicMHU4ph7ibZrD8jAqaZrSzhg,2945
|
|
17
|
+
pydantic_avro-0.8.1.dist-info/RECORD,,
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2021 GoDataDriven
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
File without changes
|
|
File without changes
|
|
File without changes
|