make python function to Node-RED node
- Node-RED 3.x
- node.js 16.x or higher(tested unto 18.x)
- nodered.py 0.2.6 or higher, automatically download from internet if no node.js installed
- python 3.7 or higher
- tested on
OS | Tested | Pass |
---|---|---|
Mac 13(Ventura) | β | β |
Windows 10 | β | β |
Linux(RPI/ARM) | β | β |
python -m pip install nodered.py
python -m pip install git+https://github.com/oyajiDev/NodeRED.py.git
from noderedpy import REDBuilder, RED, Auth
# using builder
red = REDBuilder()\
.set_user_dir("{user_dir}")\
.set_node_red_dir("{node_red_dir}")\
.set_admin_root("{admin_root}")\
.set_node_root("{node_root}")\
.set_port(port)\
.set_default_flow("{default_flow}")\
.set_remote_access(remote_access)\
.set_default_categories([{default_categories}])\
.set_node_globals({global_variables})\
.build()
# using RED directly
red = RED(
"{user_dir}", "{node_red_dir}",
"{admin_root}", "{node_root}", port, "{default_flow}",
remote_access, [{default_categories}],
{global_variables}
)
# change editor theme settings
red.editor_theme.palette.editable = False
red.editor_theme.projects.enabled = False
# add auths
red.node_auths.append(
Auth(username = "node-red-py", password = "p@ssword")
)
- See noredpy.decorator.register function for details
from noderedpy import Node
from noderedpy.decorator import register
@register("test")
def test(node:Node, props:dict, msg:dict) -> dict:
# user codes here
return msg
- See noredpy.decorator.register function for details
api = API()
red.register("test", api.test)
- See noderedpy._property for details of "Property"
- See example for details.
import htmlgenerator as hg
from noderedpy.nodered.node.properties.property import Property, RenderedProperty
from noderedpy.nodered.red.editor.widget import Widget, RenderedWidget
# custom property
class MyProperty(Property):
def __init__(self):
super().__init__(**{property_kwargs})
def render(self) -> RenderedProperty:
# abstract method for node creation
return RenderedProperty(**{kwargs})
# custom widget
class MyWidget(Widget):
def __init__(self):
super().__init__(**{widget_kwargs})
def render(self) -> RenderedWidget:
# abstract method for node creation
return RenderedWidget(**{kwargs})
- register as decorator
from noderedpy.decorator import route
# get
@route("{route_url}", "get")
def route1(params:dict) -> dict:
return {}
# post
@route("{route_url}", "post")
def route1(datas:dict) -> dict:
return {}
- register from Node-RED object
# get
red.route(lambda params: {}, "{route_url}", "get")
# post
red.route(lambda datas: {}, "{route_url}", "post")
red.static("/static", "{static_directory_or_file_path}")
from noderedpy.nodered.red.editor.widget import Widget, RenderedWidget
class MyWidget(Widget):
def __init__(self, *args, **kwargs):
super().__init__()
def render(self) -> RenderedWidget:
return RenderedWidget()
- see pre-made Properties or Widgets for details.
red.start({debug:bool}, {callback:MethodType})
β type support for "list" and "dict"
β remove aiohttp server
β add Tab.
π© more property types.(processing...)
- β TypedInput
- π© SearchBox
- π© TreeList