Plugins

Lenscraft can be extended with custom Nodes by creating a Plugin.

example_plugin/plugin.py

from lenscraft.node import Node, NumberValue
from lenscraft.plugin import LenscraftPlugin
from lenscraft.core.types import Number
from lenscraft.core.slots import Slot

plugin = LenscraftPlugin()

@plugin.node()
class AddTwoNumbers(Node):
    def setup(self):
        self.add_input("A", Slot(value_type=Number))
        self.add_input("B", Slot(value_type=Number))

        self.add_output("Result", Number)

    def compute(self):
        a = self.get_input_value("A")
        b = self.get_input_value("B")

        self.set_output_value("Result", a + b)

Manual plugin registry

To run Lenscraft with your plugin use following command:

lenscraft --plugin example_plugin.plugin

Lenscraft will dynamically import the module and look for a Plugin instance called plugin.

If you want to use a different name you can use

lenscraft --plugin example_plugin.plugin:my_plugin

Plugin Discovery

Lenscraft will automatically try to import plugins from any module that starts with lenscraft_

So, if you create a directory called lenscraft_plugin in the root of your project and add a __init__.py with the following code, Lenscraft will automatically load that plugin.

from lenscraft.node import Node, NodeInput, NodeOutput, NumberValue
from lenscraft.plugin import LenscraftPlugin


plugin = LenscraftPlugin()