Created
March 26, 2025 19:34
-
-
Save gurmeetsaran/5779805a0f761d627282720af16615db to your computer and use it in GitHub Desktop.
Generate Python Model from avsc file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from dataclasses_avroschema import ModelGenerator, ModelType | |
model_generator = ModelGenerator() | |
schema = { | |
"type": "record", | |
"namespace": "com.kubertenes", | |
"name": "AvroDeployment", | |
"fields": [ | |
{"name": "image", "type": "string"}, | |
{"name": "replicas", "type": "int"}, | |
{"name": "port", "type": "int"}, | |
], | |
} | |
result = model_generator.render_module( | |
schemas=[schema], | |
model_type=ModelType.AVRODANTIC.value, | |
) | |
# save the result in a file | |
with open("models.py", mode="+w") as f: | |
f.write(result) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment