lob-pyweb

Base layer for flask and dash web applications


License
MIT
Install
pip install lob-pyweb==0.6.2

Documentation

pyweb

Action Status

This project is the backbone for the web applications.

Technology

We take advantage of various technologies here

  • We host static files with Whitenoise.

    # add whitenoise
    server.wsgi_app = WhiteNoise(server.wsgi_app, root='/static', prefix='assets/')
  • We use the Waitress server.

    #!/usr/bin/env python3
    from waitress import serve
    from pyweb.app import create_app
    
    
    if __name__ == '__main__':
        serve(app=create_app(), port=8000)
  • The flask application is relying on the popular blueprint concept. We expose a REST server for performance calculations. Applications built on this package can reuse the very same blueprints and remain slim and elegant.

    def create_app():
        server = create_server(extensions=[engine, cache], static_folder="/static")
    
        server.register_blueprint(blue_whoosh, url_prefix="/whoosh")
        server.register_blueprint(blue_post, url_prefix="/engine")
        server.register_blueprint(blue_admin, url_prefix="/admin")
    
        # add whitenoise
        server.wsgi_app = WhiteNoise(server.wsgi_app, root='/static', prefix='assets/')
    
        return server
  • We use Flask extensions and a central settings.cfg file to initialize the extensions only once. Within the Dockerfile we set

    ENV APPLICATION_SETTINGS="/server/config/settings.cfg"
  • We extensively test the app and achieve a full coverage score. We test against a client created as a pytest fixture.

    @pytest.fixture(scope="module")
    def client():
        app = create_app()
    
        with app.app_context():
            __init_session()
    
        yield app.test_client()
  • We use httpie within the Docker image for simple testing and debugging