Skip to content

somehitDev/NodeRED.py

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

63 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

NodeRED.py

make python function to Node-RED node




πŸŽ›οΈ requirements

  • 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) βœ… βœ…



🌐 install

- using pip

python -m pip install nodered.py

- using git(dev)

python -m pip install git+https://github.com/oyajiDev/NodeRED.py.git



πŸ›  usage

Node-RED initialize

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")
)

register Node

register as decorator

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

register from Node-RED object

api = API()

red.register("test", api.test)

custom Property/Widget

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 route

route(get, post)

  • 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")

static

red.static("/static", "{static_directory_or_file_path}")

custom editor widget

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()

start Node-RED

red.start({debug:bool}, {callback:MethodType})



Todos

βœ… type support for "list" and "dict"



Roadmap To 0.2.0

βœ… remove aiohttp server

Roadmap to 0.3.0

βœ… add Tab.

🟩 more property types.(processing...)

  • βœ… TypedInput
  • 🟩 SearchBox
  • 🟩 TreeList