views:

234

answers:

4

Are there any Python object-relational mapping libraries that, given a database schema, can generate a set of Python classes? I know that the major libraries such as SQLObject, SQLAlchemy, and Django's internal SQL ORM library do a very good job of creating a DB schema given a set of classes, but I'm looking for a library that works in reverse.

There is a related question for Perl libraries on Stack Overflow.

+3  A: 

Geniusql (and Dejavu, its big federated brother) can do that quite well. See "Automatic Table Classes" for the former and "Automatic Unit Classes" for the latter.

fumanchu
+5  A: 

Django had an inspectdb command that creates models.py files out of your database.

Cristian
+4  A: 

SQLAlchemy can actually do what you want. You can either define the mappings yourself manually using the mapper facility, or auto-generate them using reflection.

It's not absolutely necessary to build the database using the metadata facility, you can always use an existing one instead.

Kamil Kisiel