pydantic-avro 0.7.3__tar.gz → 0.8.1__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.
- {pydantic_avro-0.7.3 → pydantic_avro-0.8.1}/PKG-INFO +12 -1
- {pydantic_avro-0.7.3 → pydantic_avro-0.8.1}/README.md +11 -0
- {pydantic_avro-0.7.3 → pydantic_avro-0.8.1}/pyproject.toml +4 -4
- {pydantic_avro-0.7.3 → pydantic_avro-0.8.1}/setup.py +2 -2
- {pydantic_avro-0.7.3 → pydantic_avro-0.8.1}/src/pydantic_avro/to_avro/types.py +47 -0
- {pydantic_avro-0.7.3 → pydantic_avro-0.8.1}/LICENSE +0 -0
- {pydantic_avro-0.7.3 → pydantic_avro-0.8.1}/src/pydantic_avro/__init__.py +0 -0
- {pydantic_avro-0.7.3 → pydantic_avro-0.8.1}/src/pydantic_avro/__main__.py +0 -0
- {pydantic_avro-0.7.3 → pydantic_avro-0.8.1}/src/pydantic_avro/base.py +0 -0
- {pydantic_avro-0.7.3 → pydantic_avro-0.8.1}/src/pydantic_avro/from_avro/__init__.py +0 -0
- {pydantic_avro-0.7.3 → pydantic_avro-0.8.1}/src/pydantic_avro/from_avro/avro_to_pydantic.py +0 -0
- {pydantic_avro-0.7.3 → pydantic_avro-0.8.1}/src/pydantic_avro/from_avro/class_registery.py +0 -0
- {pydantic_avro-0.7.3 → pydantic_avro-0.8.1}/src/pydantic_avro/from_avro/types.py +0 -0
- {pydantic_avro-0.7.3 → pydantic_avro-0.8.1}/src/pydantic_avro/py.typed +0 -0
- {pydantic_avro-0.7.3 → pydantic_avro-0.8.1}/src/pydantic_avro/to_avro/__init__.py +0 -0
- {pydantic_avro-0.7.3 → pydantic_avro-0.8.1}/src/pydantic_avro/to_avro/base.py +0 -0
- {pydantic_avro-0.7.3 → pydantic_avro-0.8.1}/src/pydantic_avro/to_avro/config.py +0 -0
|
@@ -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
|
|
|
@@ -43,6 +43,17 @@ pydantic-avro avro_to_pydantic --asvc /path/to/schema.asvc
|
|
|
43
43
|
pydantic-avro avro_to_pydantic --asvc /path/to/schema.asvc --output /path/to/output.py
|
|
44
44
|
```
|
|
45
45
|
|
|
46
|
+
### Specify expected Avro type
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
from datetime import datetime
|
|
50
|
+
from pydantic import Field
|
|
51
|
+
from pydantic_avro.base import AvroBase
|
|
52
|
+
|
|
53
|
+
class ExampleModel(AvroBase):
|
|
54
|
+
field1: int = Field(..., avro_type="long") # Explicitly set Avro type to "long"
|
|
55
|
+
field2: datetime = Field(..., avro_type="timestamp-millis") # Explicitly set Avro type to "timestamp-millis"
|
|
56
|
+
```
|
|
46
57
|
|
|
47
58
|
### Install for developers
|
|
48
59
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "pydantic-avro"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.8.1"
|
|
4
4
|
description = "Converting pydantic classes to avro schemas"
|
|
5
5
|
authors = ["Peter van 't Hof' <peter.vanthof@godatadriven.com>"]
|
|
6
6
|
|
|
@@ -9,7 +9,6 @@ readme = "README.md"
|
|
|
9
9
|
license = "MIT"
|
|
10
10
|
homepage = "https://github.com/godatadriven/pydantic-avro"
|
|
11
11
|
repository = "https://github.com/godatadriven/pydantic-avro"
|
|
12
|
-
include = ["LICENSE"]
|
|
13
12
|
|
|
14
13
|
|
|
15
14
|
packages = [{ include = "pydantic_avro", from = "src" }]
|
|
@@ -24,10 +23,10 @@ pytest = "^8.3.5"
|
|
|
24
23
|
pytest-mock = "^3.10.0"
|
|
25
24
|
pyproject-flake8 = "^7.0.0"
|
|
26
25
|
isort = "^5.10.0"
|
|
27
|
-
black = "24.
|
|
26
|
+
black = "24.8.0"
|
|
28
27
|
pytest-cov = "^5.0.0"
|
|
29
28
|
mypy = "^1.1.1"
|
|
30
|
-
avro = "^1.
|
|
29
|
+
avro = "^1.12.0"
|
|
31
30
|
fastavro = "^1.8.1"
|
|
32
31
|
|
|
33
32
|
[tool.poetry.scripts]
|
|
@@ -63,6 +62,7 @@ line_length = 120
|
|
|
63
62
|
[tool.mypy]
|
|
64
63
|
files = "src/"
|
|
65
64
|
python_version = "3.9"
|
|
65
|
+
ignore_missing_imports = "true"
|
|
66
66
|
|
|
67
67
|
[build-system]
|
|
68
68
|
requires = ["poetry-core>=1.0.0"]
|
|
@@ -18,9 +18,9 @@ entry_points = \
|
|
|
18
18
|
|
|
19
19
|
setup_kwargs = {
|
|
20
20
|
'name': 'pydantic-avro',
|
|
21
|
-
'version': '0.
|
|
21
|
+
'version': '0.8.1',
|
|
22
22
|
'description': 'Converting pydantic classes to avro schemas',
|
|
23
|
-
'long_description': '[](https://github.com/godatadriven/pydantic-avro/actions/workflows/python-package.yml)\n[](https://codecov.io/gh/godatadriven/pydantic-avro)\n[](https://badge.fury.io/py/pydantic-avro)\n[](https://github.com/godatadriven/pydantic-avro/actions/workflows/codeql-analysis.yml)\n\n# pydantic-avro\n\nThis library can convert a pydantic class to a avro schema or generate python code from a avro schema.\n\n### Install\n\n```bash\npip install pydantic-avro\n```\n\n### Pydantic class to avro schema\n\n```python\nimport json\nfrom typing import Optional\n\nfrom pydantic_avro.base import AvroBase\n\n\nclass TestModel(AvroBase):\n key1: str\n key2: int\n key2: Optional[str]\n\n\nschema_dict: dict = TestModel.avro_schema()\nprint(json.dumps(schema_dict))\n\n```\n\n### Avro schema to pydantic\n\n```shell\n# Print to stdout\npydantic-avro avro_to_pydantic --asvc /path/to/schema.asvc\n\n# Save it to a file\npydantic-avro avro_to_pydantic --asvc /path/to/schema.asvc --output /path/to/output.py\n```\n\n\n### Install for developers\n\n###### Install package\n\n- Requirement: Poetry 1.*\n\n```shell\npoetry install\n```\n\n###### Run unit tests\n```shell\npytest\ncoverage run -m pytest # with coverage\n# or (depends on your local env) \npoetry run pytest\npoetry run coverage run -m pytest # with coverage\n```\n\n##### Run linting\n\nThe linting is checked in the github workflow. To fix and review issues run this:\n```shell\nblack . # Auto fix all issues\nisort . # Auto fix all issues\npflake . # Only display issues, fixing is manual\n```\n',
|
|
23
|
+
'long_description': '[](https://github.com/godatadriven/pydantic-avro/actions/workflows/python-package.yml)\n[](https://codecov.io/gh/godatadriven/pydantic-avro)\n[](https://badge.fury.io/py/pydantic-avro)\n[](https://github.com/godatadriven/pydantic-avro/actions/workflows/codeql-analysis.yml)\n\n# pydantic-avro\n\nThis library can convert a pydantic class to a avro schema or generate python code from a avro schema.\n\n### Install\n\n```bash\npip install pydantic-avro\n```\n\n### Pydantic class to avro schema\n\n```python\nimport json\nfrom typing import Optional\n\nfrom pydantic_avro.base import AvroBase\n\n\nclass TestModel(AvroBase):\n key1: str\n key2: int\n key2: Optional[str]\n\n\nschema_dict: dict = TestModel.avro_schema()\nprint(json.dumps(schema_dict))\n\n```\n\n### Avro schema to pydantic\n\n```shell\n# Print to stdout\npydantic-avro avro_to_pydantic --asvc /path/to/schema.asvc\n\n# Save it to a file\npydantic-avro avro_to_pydantic --asvc /path/to/schema.asvc --output /path/to/output.py\n```\n\n### Specify expected Avro type\n\n```python\nfrom datetime import datetime\nfrom pydantic import Field\nfrom pydantic_avro.base import AvroBase \n\nclass ExampleModel(AvroBase):\n field1: int = Field(..., avro_type="long") # Explicitly set Avro type to "long"\n field2: datetime = Field(..., avro_type="timestamp-millis") # Explicitly set Avro type to "timestamp-millis"\n```\n\n### Install for developers\n\n###### Install package\n\n- Requirement: Poetry 1.*\n\n```shell\npoetry install\n```\n\n###### Run unit tests\n```shell\npytest\ncoverage run -m pytest # with coverage\n# or (depends on your local env) \npoetry run pytest\npoetry run coverage run -m pytest # with coverage\n```\n\n##### Run linting\n\nThe linting is checked in the github workflow. To fix and review issues run this:\n```shell\nblack . # Auto fix all issues\nisort . # Auto fix all issues\npflake . # Only display issues, fixing is manual\n```\n',
|
|
24
24
|
'author': "Peter van 't Hof'",
|
|
25
25
|
'author_email': 'peter.vanthof@godatadriven.com',
|
|
26
26
|
'maintainer': 'None',
|
|
@@ -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":
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|