What I am trying to do is to get from SqlAlchemy entity definition all it’s Column()’s, determine their types and constraints, to be able to pre-validate, convert data and display custom forms to user.
How can I introspect it?
Example:
class Person(Base):
'''
Represents Person
'''
__tablename__ = 'person'
# Columns
id = Column(String(8), primary_key=True, default=uid_gen)
title = Column(String(512), nullable=False)
birth_date = Column(DateTime, nullable=False)
I want to get this id, title, birth date, determine their restrictions (such as title is string and max length is 512 or birth_date is datetime etc)
Thank you
If you are using
sqlalchemy 0.8, then you should check out the new feature New Class Inspection System. Sample code extract from the documentation:Otherwise, see Accessing Tables and Columns part of the documentation. Again, code extract from the docu: