make python function to Node-RED node
Project description
NodeRED.py
make python function to Node-RED node
🎛️ requirements
- node.js 18.16.1 or higher(latest stable)
- 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(WSL) | 🚫 |
🌐 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}])\
.build()
# using RED directly
red = RED(
"{user_dir}", "{node_red_dir}",
"{admin_root}", "{node_root}", port, "{default_flow}",
remote_access, [{default_categories}]
)
# 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
- 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
register from Node-RED object
- 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.
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}")
start Node-RED
red.start({debug:bool}, {callback:MethodType})
Todos
✅ type support for "list" and "dict"
Roadmap To 2.0
✅ remove aiohttp server
🟩 flexible property ui
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
nodered_py-0.2.12.tar.gz
(315.4 kB
view details)
Built Distribution
nodered_py-0.2.12-py3-none-any.whl
(314.3 kB
view details)
File details
Details for the file nodered_py-0.2.12.tar.gz
.
File metadata
- Download URL: nodered_py-0.2.12.tar.gz
- Upload date:
- Size: 315.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.29.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 34fa2440d082d844de7047c0d9b745c7e2aaf8eb061746999b69b8612405e3ee |
|
MD5 | 500beeefa9756d4f42022d7063d36200 |
|
BLAKE2b-256 | 7ea486841de1c237b56f454854a16598d3530782803203e8205e2dec5d583877 |
File details
Details for the file nodered_py-0.2.12-py3-none-any.whl
.
File metadata
- Download URL: nodered_py-0.2.12-py3-none-any.whl
- Upload date:
- Size: 314.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.29.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c3bf8fbf1c1a88acf8f6cfca8bc6aefb6537e87903d00e194da9b9cf72183781 |
|
MD5 | 52c6d660db49d2cf5556242acefd15ab |
|
BLAKE2b-256 | d77cdcdb77e6d573647137f30097d0672148ea219741c8888295aaf1b39bce70 |