Skip to main content

pynodered

https://img.shields.io/pypi/v/pynodered.svg https://img.shields.io/travis/ghislainp/pynodered.svg Documentation Status

About

Make your python functions available in Node-RED using a simple decorator.

pynodered is a server communicating with Node-RED to make available your python functions as blocks in Node-RED. pynodered reads modules and python files containing functions decorated with ‘node_red’, register them as blocks in Node-RED. pynodred then handles communications between Node-RED (in javascript) to run your function whenever the block receives a message.

Quick Start

Requires python>=3.5

$ pip install pynodered
# Install node dependencies
$ npm install follow-redirects url querystring

Examples

A simple example to lowercase the payload of the messages:

from pynodered import node_red

@node_red(category="pyfuncs")
def lower_case(node, msg):

    msg['payload'] = str(msg['payload']).lower()
    return msg

Put this snippet is in a file “example.py”, run the pynodered server with:

$ pynodered example.py

and in another console:

$ node-red

In Node-RED, you now have a new category “pyfuncs” with a function lower_case. It can be used in a flow as any other blocks:

images/lower-case-flow.png

It is possible to add block properties (constant arguments provided by the user in Node-RED) by defining a property in the decorator:

from pynodered import node_red, NodeProperty

@node_red(category="pyfuncs",
          properties=dict(number=NodeProperty("Number", value="1")))

def repeat(node, msg):

    msg['payload'] = msg['payload'] * int(node.number.value)
    return msg

Don’t forget to restart the pynodered server everytime your python files change. Node-RED also needs to be restarted but only when the function name or properties change or a new function is added. Refreshing the browser is then necessary.

By default pynodered exports the functions in the Node-RED package ‘pynodered’ and the category ‘default’. The category name can be changed with the decorator optional argument. For the package name and information, the python module containing the functions can declare a ‘package’ dictonary like this:

package = {
    "name" : "FFT filters",
    "version" : "0.01",
    "description"  : "Nodes written in Python for signal processing",
}

Warning

pynodered is not ready for production use yet. On a multi-user computer, be aware that pynodered server will respond to anyone request and will execute code under the account that launched the server. NODE-Red has a similar issue (https://nodered.org/docs/security)

License

Copyright (C) 2019 Ghislain Picard

Free software: GNU General Public License v3

This package is a rewrite and extension of the code intially written by Tomaž Šolc for sigfox-toolbox https://github.com/sensorlab/sigfox-toolbox/tree/master/node-red-python. Copyright (2017) SensorLab, Jožef Stefan Institute http://sensorlab.ijs.si and licensed under GPL version 3

Metadata

Release files for pynodered 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pynodered 0.2.0
File Size Uploaded
pynodered-0.2.0.tar.gz 17.0 kB Details

Release files / pynodered-0.2.0.tar.gz

Download URL pynodered-0.2.0.tar.gz
Size 17.0 kB
Tags Source
SHA-256 checksum
How to use checksums
30654e8c5e044b1819858e8c310f9aa2449d3ab939d233c2d8a7850b68860ed8
BLAKE2b-256 checksum
How to use checksums
b80ee7dc632620cca30311f203c957660fcc504d28583d68628b7d1c9edc20aa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0.post20200209 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.6

Release history Release notifications | RSS feed

This release

0.2.0 This release

1 release file

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page