Automatic model code generator for SQLAlchemy
This is a tool that reads the structure of an existing database and generates the appropriate SQLAlchemy model code, using the declarative style if possible.
This tool was written as a replacement for sqlautocode, which was suffering from several issues (including, but not limited to, incompatibility with Python 3 and the latest SQLAlchemy version).
To install, do:
pip install sqlacodegen
or, failing that:
At the minimum, you have to give sqlacodegen a database URL. The URL is passed directly to SQLAlchemy’s create_engine() method so please refer to SQLAlchemy’s documentation for instructions on how to construct a proper URL.
sqlacodegen postgresql:///some_local_db sqlacodegen mysql+oursql://user:password@localhost/dbname sqlacodegen sqlite:///database.db
To see the full list of options:
The table name (which is assumed to be in English) is converted to singular form using the “inflect” library. Then, every underscore is removed while transforming the next letter to upper case. For example, sales_invoices becomes SalesInvoice.
Relationships are detected based on existing foreign key constraints as follows:
A table is considered an association table if it satisfies all of the following conditions:
Relationships are typically named based on the opposite class name. For example, if an Employee class has a column named employer which has a foreign key to Company.id, the relationship is named company.
A special case for single column many-to-one and one-to-one relationships, however, is if the column is named like employer_id. Then the relationship is named employer due to that _id suffix.
If more than one relationship would be created with the same name, the latter ones are appended numeric suffixes, starting from 1.
The source can be browsed at Bitbucket.
A bug tracker is provided by bitbucket.org.
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|File Name & Checksum SHA256 Checksum Help||Version||File Type||Upload Date|
|sqlacodegen-1.1.6-py2.py3-none-any.whl (13.4 kB) Copy SHA256 Checksum SHA256||py2.py3||Wheel||May 15, 2015|
|sqlacodegen-1.1.6.tar.gz (15.5 kB) Copy SHA256 Checksum SHA256||–||Source||May 15, 2015|