--- title: Plugins keywords: fastai sidebar: home_sidebar nb_path: "nbs/plugin.pluginbase.ipynb" ---
PluginBase is the plugin class that the simplest plugin inherits.
Inheriting class should implement:
The memri pod uses a plugin system to add features to the backend memri backend. Plugins can import your data (importers), change your data (indexers), or call other serivces. Users can define their own plugins to add new behaviour to their memri app. Let's use the following plugin as an example of how we can start plugins.
class MyItem(Item):
properties = Item.properties + ["name", "age"]
edges = Item.edges
def __init__(self, name=None, age=None, **kwargs):
super().__init__(**kwargs)
self.name = name
self.age = age
class MyPlugin(PluginBase):
""""""
properties = PluginBase.properties
edges= PluginBase.edges
def __init__(self, **kwargs):
super().__init__(**kwargs)
def run(self, client):
print("running")
client.create(MyItem("some person", 20))
def add_to_schema(self, client):
client.add_to_schema(MyItem("my name", 10))
Memri plugins need to define at least 2 methods: .run()
and .add_to_schema()
. .run()
defines the logic of the plugin. .add_to_schema()
defines the schema for the plugin in the pod. Note that currently, add_to_schema
requires all item to have all properties defined that are used in the plugin. In the future, we might replace add_to_schema, to be done automatically, based on a declarative schema defined in the plugin.
Plugins can be started using the pymemri run_plugin
or simulate_run_plugin_from_frontend
CLI. With run_plugin
the plugin is invoked directly by spawning a new python process, while simulate_run_plugin_from_frontend
requests the pod to spawn a new process, docker container, or kubernetes container, which in calls run_plugin
(for more info see simulate_run_plugin_from_frontend
. When using run_plugin
, you can either pass your run arguments as parameters, or set them as environment variables. If both are set, the CLI will use the passed arguments.
To start a plugin on your local machine, you can use the CLI. This will create a client for you, and run the code defined in <myplugin>.run()
client = PodClient(database_key=read_pod_key("database_key"), owner_key=read_pod_key("owner_key"))
run = PluginRun(containerImage="no_container", pluginModule="pymemri.plugin.pluginbase",
plugin="pymemri.plugin.pluginbase.MyPlugin",
pluginName="MyPlugin", state="not started")
assert client.add_to_schema(PluginRun("", "", "", "", "")) and client.create(run)
run_plugin(plugin_run_id=run.id)
{% include note.html content='The data that is created here should be in the pod in order for this to work' %}
In production, we start plugins by making an API call to the pod, which in turn creates an environment for the plugin and starts it using docker containers, kubernetes containers or a shell script. We can start this process using the simulate_run_plugin_from_frontend
CLI. Note that when using docker, provided container name should be "installed" within the Pod environemnt (e.g. docker build -t pymemri .
for this repo) in order to start it.
client = PodClient()
!simulate_run_plugin_from_frontend --plugin_path="pymemri.plugin.pluginbase.MyPlugin"