Skip to main content

make python function easily accessible from Node-RED

Project description

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

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",
}

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

History

0.1.0 (2019-01-08)

  • First release on PyPI.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pynodered-0.1.0.tar.gz (16.2 kB view details)

Uploaded Source

Built Distribution

pynodered-0.1.0-py2.py3-none-any.whl (13.6 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file pynodered-0.1.0.tar.gz.

File metadata

  • Download URL: pynodered-0.1.0.tar.gz
  • Upload date:
  • Size: 16.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1

File hashes

Hashes for pynodered-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a5fd9cc46c4760578bd696335c08466f7596e4ebf0b238cc64e7869e5fef6802
MD5 74c27dda871c66327d71a5154d393fde
BLAKE2b-256 85f61af9af4fed7452920b91f12a9215e6d0f044e3d5d14e17d2d9f23283ee5a

See more details on using hashes here.

File details

Details for the file pynodered-0.1.0-py2.py3-none-any.whl.

File metadata

  • Download URL: pynodered-0.1.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 13.6 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1

File hashes

Hashes for pynodered-0.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 077d63edeea16d1f291e3218e4a9b6ef668ba8f7569e8feaa72b5e02d7371ee5
MD5 4dfc84622cd2d91ab8addc639033ab23
BLAKE2b-256 1ae63d6c765d3c6698b0b8bcaee59c0867112424350f3f608968eeaedb4cde48

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page