StaticWebFrontend

class lightning.app.frontend.web.StaticWebFrontend(serve_dir)[source]

Bases: Frontend

A frontend that serves static files from a directory using FastAPI.

Return this in your LightningFlow.configure_layout() method if you wish to serve a HTML page.

Parameters:
  • serve_dir (str) – A local directory to serve files from. This directory should at least contain a file index.html.

  • root_path – A path prefix when routing traffic from behind a proxy at /<root_path>

Example

In your LightningFlow, override the method configure_layout:

def configure_layout(self):
    return StaticWebFrontend("path/to/folder/to/serve")
start_server(host, port, root_path='')[source]

Start the process that serves the UI at the given hostname and port number.

Parameters:
  • host (str) – The hostname where the UI will be served. This gets determined by the dispatcher (e.g., cloud), but defaults to localhost when running locally.

  • port (int) – The port number where the UI will be served. This gets determined by the dispatcher, which by default chooses any free port when running locally.

  • root_path (str) – root_path for the server if app in exposed via a proxy at /<root_path>

Return type:

None

Example

An custom implementation could look like this:

def start_server(self, host, port, root_path=""):
    self._process = subprocess.Popen(["flask", "run" "--host", host, "--port", str(port)])
stop_server()[source]

Stop the process that was started with start_server() so the App can shut down.

This method gets called when the LightningApp terminates.

Return type:

None

Example

def stop_server(self):
    self._process.kill()