The sample I like for this problem is to not have the extension defining the database models, but instead provide the mixin (s) class from which the developer can inherit the models. In addition to mixin (s), you can have callback functions for operations, such as loading or saving models from a database, also provided by the application developer.
This method is used, for example, by Flask-Login . I like it because it does agnostic extension database. You said that you are interested in this for SQLAlchemy, but if you publish your extension, at some point someone will want to use it with Mongo, Peewee or without an ORM layer. All of this will be supported if you make no assumptions about the database mechanism in the extension.
source share