When making modular flask applications, it's common not to immediately provide the app in the constructor, but to pass it later on with the method init_app(app) as we can see in the documentation -- https://flask.palletsprojects.com/en/1.1.x/extensions/
With a bit of changes on the constructor this can become a "proper" flask extension
https://flask.palletsprojects.com/en/1.1.x/extensiondev/
The example of the SQLite extension provides an idea on how this could look like:
def __init__(self, app=None):
self.app = app
if app is not None:
self.init_app(app)
def init_app(self, app):
app.config.setdefault('SQLITE3_DATABASE', ':memory:')
app.teardown_appcontext(self.teardown)