def create_app(app_name=None, blueprints=None, config=None):
    """
    Lemur application factory

    :param config:
    :param app_name:
    :param blueprints:
    :return:
    """
    if not blueprints:
        blueprints = DEFAULT_BLUEPRINTS
    else:
        blueprints = blueprints + DEFAULT_BLUEPRINTS

    if not app_name:
        app_name = __name__

    app = Flask(app_name)
    ctx = get_current_context(silent=True)

    # get config option value from command line
    if ctx and config is None:
        script_info = ctx.obj
        if script_info:
            config = getattr(script_info, 'config')

    configure_app(app, config)
    configure_blueprints(app, blueprints)
    configure_extensions(app)
    configure_logging(app)
    configure_database(app)
    install_plugins(app)

    @app.teardown_appcontext
    def teardown(exception=None):
        if db.session:
            db.session.remove()

    @app.shell_context_processor
    def shell_context():
        return {'app': app, 'db': db}

    return app

    Lemur application factory

    :param config:
    :param app_name:
    :param blueprints:
    :return:
    
lemur/factory.py