Skip to content

Instantly share code, notes, and snippets.

@developer-sdk
Created July 13, 2021 14:11
Show Gist options
  • Save developer-sdk/dc6fc9c968fb90e4d3c813afdda1562f to your computer and use it in GitHub Desktop.
Save developer-sdk/dc6fc9c968fb90e4d3c813afdda1562f to your computer and use it in GitHub Desktop.
python을 이용한 avro 예제
import avro.schema
from avro.datafile import DataFileReader, DataFileWriter
from avro.io import DatumReader, DatumWriter
schema = avro.schema.parse("""{"namespace": "example.avro",
"type": "record",
"name": "User",
"fields": [ {"name": "name", "type": "string"} ]
}""")
writer = DataFileWriter(open("users.avro", "wb"), DatumWriter(), schema)
writer.append({"name": "Alyssa"})
writer.close()
reader = DataFileReader(open("users.avro", "rb"), DatumReader())
for user in reader:
print(user)
reader.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment