Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to extract schema for avro file in python

I am trying to use the Python Avro library (https://pypi.python.org/pypi/avro) to read a AVRO file generated by JAVA. Since the schema is already embedded in the avro file, why do I need to specify a schema file? Is there a way to extract it automatically?

Found another package called fastavro(https://pypi.python.org/pypi/fastavro) can extract avro schema. Is the manual specifying schema file in python arvo package by design? Thank you very much.

like image 779
ljxue Avatar asked Jul 29 '14 00:07

ljxue


1 Answers

I use python 3.4 and Avro package 1.7.7

For schema file use:

reader = avro.datafile.DataFileReader(open('file_name.avro',"rb"),avro.io.DatumReader())
schema = reader.meta
print(schema) 
like image 99
Alon Hazan Avatar answered Sep 20 '22 07:09

Alon Hazan