--- title: Stateful Plugins keywords: fastai sidebar: home_sidebar nb_path: "nbs/plugin.stateful.ipynb" ---
If a plugin with persistent and runtime states are going to be used, this includes the plugins with user interaction, then StatefulPlugin should be used.
If a plugin needs views, an account to login or a last state to continue then a persistent state should be deployed into the pod.
StatefulPlugin is a sub-class of PluginBase that allows setting both runtime and persistent states.
Through this inherited class you can set states to control the flow and views that are displayed to user.
from pymemri.data.schema import Person
class MyStatefulPlugin(StatefulPlugin):
def __init__(self, runId=None, views=None, **kwargs):
super().__init__(runId=runId, views=None, **kwargs)
def run(self, client):
# plugin's magic happens here
# manipulate run state
self.set_run_vars(client, {'state': 'Running'})
# set UI view (CVU)
self.set_run_view(client, 'splash-screen')
# create items in POD
imported_person = Person(firstName="Hari", lastName="Seldon")
client.create(imported_person)
# set persistent state
self.set_state_str("continue_from:5021")
return
def add_to_schema(self, client):
print("Adding schema")
super().add_to_schema(client)
# add plugin-specific schemas here
client.add_to_schema(Person(firstName="", lastName=""))
pass