Skip to content

Instantly share code, notes, and snippets.

@otech-nl
Last active July 18, 2016 12:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save otech-nl/f1f7251e5d0aefb5336cfe6896bcf5b8 to your computer and use it in GitHub Desktop.
Save otech-nl/f1f7251e5d0aefb5336cfe6896bcf5b8 to your computer and use it in GitHub Desktop.
Inspect a SQLAlchemy Model
# http://docs.sqlalchemy.org/en/latest/faq/ormconfiguration.html#how-do-i-get-a-list-of-all-columns-relationships-mapped-attributes-etc-given-a-mapped-class
from sqlalchemy import inspect
from models import *
mapper = inspect(Task)
for f in 'attrs column_attrs relationships all_orm_descriptors columns'.split():
print '%s:'% f
for x in getattr(mapper, f):
print ' %s' % x
for f in 'mapped_table local_table'.split():
print '%s: %s' % (f, getattr(mapper, f))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment