1

I have a flask app that I've been building using the application factory pattern: Application structure

Until now I've been developing using a sqlite3 database, and some simple models placed in app/models.py with the idea of setting up a mysql database for production.

However, I see the need for other (non flask) apps to communicate with this database. I would therefore like to make my database creation code and models into a seperate python package, and use that as a dependency in my flask application.

My question is what is best practice in this case? Can I define models needed by my flask app using flask-sqlalchemy models, and "pure" sqlalchemy models for the other packages? Is there a better way to make setting up the database not depend on models I write for the flask app?

  • Addendum: if you intend to share your model classes backed by sqlalchemy without flask, you probably should build that separate package that only depend on sqlalchemy, build a standardized API, which your flask app may use instead directly. – metatoaster Jun 11 '21 at 09:44
  • Also you may wish to associate the external class model that you develop in that separate package into Flask-SQLAlchemy, see [thread](https://stackoverflow.com/questions/28789063/associate-external-class-model-with-flask-sqlalchemy). – metatoaster Jun 11 '21 at 09:51

0 Answers0