Python Objects from Database for SQLAlchemy

One of the most tedious tasks of web development is managing the data objects between your database and the web backend language. There is an amazing tool that can really help improve development time for Flask called SQLAlchemy. Many use SQLAlchemy to build the database as well, but for those like me who already have a database, or just like the fine control of SQL, there is a package called sqlacodegen that will create Python objects for SQLAlchemy from an existing database for you.

It is quite simple to generate your models:
sqlacodegen --outfile models.py postgresql://user:password@localhost/database

This will create the models.py folder at the current directory which can then be placed in your Flask application to be imported and used.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>