SQLAlchemy introspection

Posted by Shaman on Stack Overflow See other posts from Stack Overflow or by Shaman
Published on 2012-07-04T13:24:48Z Indexed on 2012/07/04 15:16 UTC
Read the original article Hit count: 194

Filed under:
|

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

© Stack Overflow or respective owner

Related posts about sqlalchemy

Related posts about introspection