I am writing a small sqlalchemy shim to export data from a MySQL database with some easy data transformations - basically changing field names. My current script works fine, but requires me to describe my model twice - once in the class declaration and once as a list of field names to repeat.
I am trying to figure out how to use introspection to identify the properties of row objects that are column assemblers. The following works almost perfectly:
for attr, value in self.__class__.__dict__.iteritems(): if isinstance(value, sqlalchemy.orm.attributes.InstrumentedAttribute): self.__class__._columns.append(attr)
except that my-many accessors relationships are also instances of sqlalchemy.orm.attributes.InstrumentedAttribute, and I need to skip them. Is there a way to distinguish between the two while I check the class dictionary?
Most of the documentation I find in the sqlalchemy introspection includes looking at .table metadata, but since I am renaming columns, this data is not trivially accessible.
python introspection declarative sqlalchemy
Seamus campbell
source share