class lightning_app.core.LightningApp(root, debug=False)[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 (LightningFlow) – The root LightningFlow component, that defines all the app’s nested components, running infinitely. It must define a run() method that the app can call.

  • debug (bool) – Whether to activate the Lightning Logger debug mode. This can be helpful when reporting bugs on Lightning repo.

>>> from lightning import LightningFlow, LightningApp
>>> from 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


© Copyright Copyright (c) 2021-2022, Lightning-AI et al...

Built with Sphinx using a theme provided by Read the Docs.