The memri [pod](https://gitlab.memri.io/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.
%% Cell type:code id: tags:
``` python
# export
# hide
classMyItem(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
classMyPlugin(PluginBase):
""""""
properties=PluginBase.properties
edges=PluginBase.edges
def__init__(self,**kwargs):
super().__init__(**kwargs)
self.pluginPackage="pymemri.plugin.pluginbase"
defrun(self,run,client):
print("running")
client.create(MyItem("some person",20))
defadd_to_schema(self,client):
client.add_to_schema(MyItem("my name",10))
```
%% Cell type:markdown id: tags:
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` CLI. To use the CLI, you can either pass your run arguments as parameters, or set them as environment variables. If both are set, the CLI will prefer the passed arguments.
%% Cell type:code id: tags:
``` python
# hide
# export
defrun_plugin_from_run_id(run_id,client):
run=client.get(run_id)
plugins=run.plugin
iflen(plugins)==0:
raiseValueError(f"plugin run {run_id} has no plugin attached to it. Make sure there is a 'plugin' \
edge from your run to the actual plugin object.")
iflen(plugins)>1:
raiseValueError("Too many plugins attached to run")
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 (currently on docker is supported). We can start this process using the CLI by provding `--from_pod==True` and providing a `--container` (the docker container used by the pod). **Note that the provided docker container should be installed within the Pod environemnt (e.g. `docker build -t pymemri .` for this repo) in order to start it.**