def create_app(object_name='pygameweb.config.Config', engine=None,
    session_factory=None):
    """returns a flask app.

    http://flask.pocoo.org/docs/patterns/appfactories/

    :param object_name: the object to load the config from.
    :param engine: an sqlalchemy engine.
    :param session_factory: an sqlalchemy session_factory.
    """
    from flask import Flask
    from flask_bootstrap import Bootstrap
    from flask_mail import Mail
    from pygameweb import db
    app = Flask(__name__)
    app.config.from_object(object_name)
    Bootstrap(app)
    db.init(app, engine, session_factory)
    Mail(app)
    if app.config['DEBUG'] and not app.config['TESTING']:
        app.config['DEBUG_TB_PROFILER_ENABLED'] = True
        app.config['DEBUG_TB_TEMPLATE_EDITOR_ENABLED'] = True
        app.config['DEBUG_TB_INTERCEPT_REDIRECTS'] = False
        from flask_debugtoolbar import DebugToolbarExtension
        try:
            DebugToolbarExtension(app, sqlalchemy_engine=app.engine)
        except TypeError:
            DebugToolbarExtension(app)
    from pygameweb.cache import cache, limiter
    cache.init_app(app)
    if not app.config['TESTING']:
        limiter.init_app(app)
    return app
