Skip to content

Commit d13f741

Browse files
committed
Allow constructing AvroSchema from a dict instead of str
1 parent a8def40 commit d13f741

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/aws_schema_registry/avro.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from io import BytesIO
44
import json
5+
from typing import Union
56

67
import fastavro
78

@@ -12,15 +13,19 @@ class AvroSchema(Schema):
1213
"""Implementation of the `Schema` protocol for Avro schemas.
1314
1415
Arguments:
15-
string: the stringified schema definition
16+
definition: the schema, either as a parsed dict or a string
1617
return_record_name: if true, when reading a union of records,
1718
the result will be a tuple where the first value is the
1819
name of the record and the second value is the record
1920
itself
2021
"""
2122

22-
def __init__(self, string: str, return_record_name: bool = False):
23-
self._dict = json.loads(string)
23+
def __init__(self, definition: Union[str, dict],
24+
return_record_name: bool = False):
25+
if isinstance(definition, str):
26+
self._dict = json.loads(definition)
27+
else:
28+
self._dict = definition
2429
self._parsed = fastavro.parse_schema(self._dict)
2530
self.return_record_name = return_record_name
2631

0 commit comments

Comments
 (0)