def create_app(*, retriever_class=BigQuery, model_class=DummyClassifier, writer_class=PostgreSQLDatabase, conf=configure): app = Flask("data-pipeline-ms") @app.route('/') def hello_world(): return 'Hello, this is the data pipeline microservice!' @app.route('/health') def healthcheck(): logging.info("Healthcheck endpoint called") return '{\"status\": \"UP\"}' @injector.inject @app.route('/model', methods=["GET", "POST"]) def apply_model(retriever: retriever_class, model: model_class, writer: writer_class): logging.info("Modell endpoint called") user = request.values.get("user") if not user: return jsonify("Please provide a valid user id") data = retriever.get(user) result = {user: model.apply(data)} writer.write(result) return jsonify("Model applied") flask_injector.FlaskInjector(app=app, modules=[conf]) return app
def create_app(config_name=None, **kwargs): """ Entry point to the Flask RESTful Server application. """ from app.products.views import products_api connexion_app = connexion.FlaskApp(__name__, specification_dir='openapi/', **kwargs) app = connexion_app.app try: app.config.from_object(get_config(config_name)) except ImportError: raise Exception('Invalid Config') connexion_app.add_api('products-api-docs.yaml', resolver=RestyResolver('products')) app.register_blueprint(products_api, url_prefix='/v1.0/api/products/') managet = CouchDBManager() managet.add_document(Products) managet.setup(app) flask_injector.FlaskInjector(app=app, modules=INJECTOR_DEFAULT_MODULES.values()) app.run(port=8080) return app
def _configure_dependency_injection(flask_app, injector_modules, custom_injector) -> None: modules = dict(INJECTOR_DEFAULT_MODULES) if injector_modules: modules.update(injector_modules) flask_injector.FlaskInjector(app=flask_app, injector=custom_injector, modules=modules.values())
def create_app(env, test_config=None): app = Flask( __name__, instance_relative_config=True, static_folder="../app/build/static" ) app.json_encoder = CustomJSONEncoder app.config.from_mapping( TOKEN="<default token, override me>", WEBHOOK_URL_ID="<default webhook url id, override me>", PROJECT_ID="<default project id, override me>", ) if test_config is None: app.config.from_pyfile("config.py", silent=True) else: app.config.update(test_config) setup_logging(env, logging.DEBUG) app.config.update(TG_URL="https://api.telegram.org/bot" + app.config["TOKEN"] + "/") try: os.makedirs(app.instance_path) except OSError: pass # pylint: disable=unused-variable @app.route("/") def root(): return send_from_directory("../app/build", "index.html") @app.route("/<path:path>") def other_files(path): return send_from_directory("../app/build", path) from tapeworm import tapeworm from tapeworm import api app.register_blueprint(tapeworm.bp) app.register_blueprint(api.bp) injector_default_modules = dict( telegram=providers.TelegramClientModule(), incoming=providers.IncomingModule(), links=providers.LinksClientModule(), ds=providers.DatastoreClientModule(), ) flask_injector.FlaskInjector(app=app, modules=injector_default_modules.values()) return app
def create_app(): """ Creates the Flask application using the factory method :return: Flask application """ setup_logging() # create flask app and register API app = Flask(__name__) app.register_blueprint(api) # provide the dependent modules via dependency injection def configure(binder): binder.bind(MedCatProcessor, to=MedCatProcessor, scope=injector.singleton) binder.bind(NlpService, to=MedCatService, scope=injector.singleton) flask_injector.FlaskInjector(app=app, modules=[configure]) # remember to return the app return app
return count binder.bind(Count, to=CallableProvider(get_count), scope=flask_injector.request) binder.bind(MessageGenerator, to=MessageGenerator(message='hi there {}!'.format(text))) return configure app = connexion.FlaskApp(__name__) app.add_api('injector_api.yaml') if __name__ == '__main__': modules = [make_configuration('prod')] else: modules = [make_configuration('test')] injector = Injector(modules) flask_injector.FlaskInjector(app=app.app, injector=injector) if __name__ == '__main__': app.run(port=8080) @pytest.fixture def client() -> flask.testing.FlaskClient: yield app.app.test_client() def test_get_message(client: flask.testing.FlaskClient): response = client.get('/message') assert response.status_code == 200 assert response.get_json() == { 'message': 'hi there test!',