LightningApp

class lightning.app.core.LightningApp(root, flow_cloud_compute=None, log_level='info', info=None, root_path='')[source]

Bases: object

The Lightning App, or App in short runs a tree of one or more components that interact to create end-to-end applications. There are two kinds of components: LightningFlow and LightningWork. This modular design enables you to reuse components created by other users.

The Lightning App alternatively run an event loop triggered by delta changes sent from either LightningWork or from the Lightning UI. Once deltas are received, the Lightning App runs the LightningFlow provided.

Parameters:
  • root (Union[LightningFlow, LightningWork]) – The root LightningFlow or LightningWork component, that defines all the app’s nested components, running infinitely. It must define a run() method that the app can call.

  • flow_cloud_compute (Optional[CloudCompute]) – The default Cloud Compute used for flow, Rest API and frontend’s.

  • log_level (str) – The log level for the app, one of [info, debug]. This can be helpful when reporting bugs on Lightning repo.

  • info (Optional[AppInfo]) – Provide additional info about the app which will be used to update html title, description and image meta tags and specify any additional tags as list of html strings.

  • root_path (str) – Set this to /path if you want to run your app behind a proxy at /path leave empty for “/”. For instance, if you want to run your app at https://customdomain.com/myapp, set root_path to /myapp. You can learn more about proxy here.

_run()[source]

Entry point of the LightningApp.

This would be dispatched by the Runtime objects.

Return type:

bool

connect(runtime)[source]

Override to customize your application to the runtime.

Return type:

None

get_component_by_name(component_name)[source]

Returns the instance corresponding to the given component name.

Return type:

Union[LightningFlow, LightningWork]

maybe_apply_changes()[source]

Get the deltas from both the flow queue and the work queue, merge the two deltas and update the state.

Return type:

Optional[bool]

run_once()[source]

Method used to collect changes and run the root Flow once.

Return type:

bool

set_state(state)[source]

Method to set a new app state set to the application.

Return type:

None

property flows: List[Union[LightningWork, LightningFlow]][source]

Returns all the flows defined within this application.

property last_state: dict[source]

Returns the latest state.

property named_works: List[Tuple[str, LightningWork]][source]

Returns all the works defined within this application with their names.

property root: Union[LightningFlow, LightningWork][source]

Returns the root component of the application.

property state: dict[source]

Return the current state of the application.

property state_vars: dict[source]

Return the current state restricted to the user defined variables of the application.

property state_with_changes: dict[source]

Return the current state with the new changes of the application.

property works: List[LightningWork][source]

Returns all the works defined within this application.