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.

  • 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, set root_path to /myapp. You can learn more about proxy here.

>>> from lightning_app import LightningFlow, LightningApp
>>> from lightning_app.runners import MultiProcessRuntime
>>> class RootFlow(LightningFlow):
...     def run(self):
...         print("Hello World!")
...         self._exit()
>>> app = LightningApp(RootFlow())  # application can be dispatched using the `runners`.
>>> MultiProcessRuntime(app).dispatch()
Hello World!

Entry point of the LightningApp.

This would be dispatched by the Runtime objects.

Return type



Override to customize your application to the runtime.

Return type



Returns the instance corresponding to the given component name.


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

Return type



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


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

property flows: List[lightning_app.core.flow.LightningFlow][source]

Returns all the flows defined within this application.

Return type


property last_state[source]

Returns the latest state.

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

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

Return type

List[Tuple[str, LightningWork]]

property root[source]

Returns the root component of the application.

property state[source]

Return the current state of the application.

property state_vars[source]

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

property state_with_changes[source]

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

property works: List[][source]

Returns all the works defined within this application.

Return type