use sqlalchemy model to generate avro schema

148 views
Skip to first unread message

Isaac Martin

unread,
Jul 22, 2019, 7:47:51 PM7/22/19
to sqlalchemy
Hey folks! I have a sqlalchemy model. I would like to define interaction between services as being constrained by a contract. For that contract, I wish to use avro schema. It would be nice to be able to generate new schema when I change the sqlalchemy model. Is anyone aware of a library or straight-forward way of generating avro schema from a sqlalchemy model?

Jonathan Vanasco

unread,
Jul 22, 2019, 8:04:09 PM7/22/19
to sqlalchemy


On Monday, July 22, 2019 at 7:47:51 PM UTC-4, Isaac Martin wrote:
 or straight-forward way of generating avro schema from a sqlalchemy model?

You can iterate the columns and relations of a SqlAlchemy model / table.  Search terms like "iterate sqlachemy model columns" and you'll see many examples.  Some advanced items may require the inspect feature (https://docs.sqlalchemy.org/en/13/core/inspection.html)

In terms of implementing it, you could make an external function that reads your model package... or make a mixin class that offers a method for generating it, and just inherit from that.  I do the latter for creating json 'fingerprints' of a model that seem similar to what the avro schema format looks like.
Reply all
Reply to author
Forward
0 new messages