I have a python dict that defines the properties of an avro schema:
schema_dict = {
'type': 'record',
'name': 'the_name',
'fields': [{'name':'id', 'type':'string'}, {'name':'value', 'type':'integer'}]
}
How do I create an instance of an avro.schema.Schema from this?
The examples use avro.schema.parse which assumes that the schema is defined as aJSON format string. I don't have that. I could go through the rigamarole of writing the dict to JSON and parsing it, but is there a more direct way of constructing the schema from this data?
If you already have it in a dictionary format there a make_avsc_object (which is internally called by parse after it does a json.loads()).
So you would just do the following:
from avro.schema import make_avsc_object
parsed_schema = make_avsc_object(schema_dict)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With