views:

40

answers:

2

Hi,

is there a python ORM (object relational mapper) that has a tool for automatically creating python classes (as code so I can expand them) from a given database schema?

I'm frequently faced with small tasks involving different databases (like importing/exporting from various sources etc.) and I thought python together with the abovementioned tool would be perfect for that.

It should work like Visual Studios ADO.NET/Linq for SQL designer, where I can just drop DB tables and VS creates classes for me ...

Thanks in advance.

+2  A: 

You do not need to produce a source code representation of your classes to be able to expand them.

The only trick is that you need the ORM to generate the classes BEFORE importing the module that defines the derived classes.

Even better, don't use derivation, but use __getattr__ and __setattr__ to implement transparent delegation to the ORM classes.

ddaa
Thanks for the idea which I like very much. Which ORM would you suggest for this approach? The ORMs I've investigated require me to define mapping classes by hand (as far as I understood at least ...)
MartinStettner
I am only familiar with SQLAlchemy, which does have a database introspection facility <http://www.sqlalchemy.org/docs/reference/ext/sqlsoup.html>, but it does not appear to be easily usable for your purpose.
ddaa