HumanSignal / label-studio

Label Studio is a multi-type data labeling and annotation tool with standardized output format
https://labelstud.io
Apache License 2.0
18.26k stars 2.29k forks source link

Allow label-studio to be used in a bigger flask project (by exposing a blueprint) and correct the use of app_factory #432

Closed graingert closed 3 years ago

graingert commented 4 years ago

Issue-title: allow label-studio to be used in a bigger flask project (by exposing a blueprint) and correct the use of app_factory Description: Is your feature request related to a problem? Please describe. I'd like to be able to pip install label-studio, and consume it in an existing flask app secondly the flask app_factory pattern is implemented incorrectly as it's immediately invoked:

https://github.com/heartexlabs/label-studio/blob/db33799ed56a3c20d54c5a486834f23e3f082d30/label_studio/server.py#L60-L76

app = app_factory()  # this call makes the app_factory pattern redundant, it should be left to "main()" or "gunicorn" to call

Describe the solution you'd like using label_studio = Blueprint() I want to replace the @app.route calls with @label_studio.route, and move the app_factory() call into main

Describe alternatives you've considered the "downside" of the app_factory pattern is that you can't use @app.route you have to use @some_blueprint.route instead

label-studio could opt-out of the app_factory pattern completely and therefore explicitly disallow such composition, but I think that would be a shame

Additional context The docstring links to this URL so it seems that this pattern is desired.

https://flask.palletsprojects.com/en/1.1.x/patterns/appfactories/#basic-factories https://flask.palletsprojects.com/en/1.1.x/blueprints/#why-blueprints

kasuteru commented 3 years ago

I second this request, as I would also love to integrate it into an existing app.

makseq commented 3 years ago

Blueprints are now supported in release/0.8.1. https://github.com/heartexlabs/label-studio/pull/472