py-RED - WIP Python implementation of Node-RED

Hello,

So basically I just grabbed the editor-client, served it over Flask and started making things work.

NOTE: This is very early development and does nothing useful at the moment! I'm posting here for discussion purposes only. WIP - Work In Progress.

As of right now, I have two nodes working: inject and debug. The Inject node is like 50% working (inject button, inject after, and interval mode works) and the debug node is probably 90% working (print to UI, print to console, and print to node status works)

It's been a lot of fun, the readme on GitHub explains my motivation behind doing this.

Just wanting to get some input here while I'm still early on this journey. Input such as, what would you use this for if you were so inclined? And what would you like to see implemented?

For example, I want it to make tkinter UIs eventually, just making a button take dynamic arguments in Tk shouldn't be so hard!

1 Like

Hi

great idea and I hope something comes of if :+1: Btw I'm sure there have been many attempts before at this - I'm sure that are others here that could point out these efforts and the learnings from those attempts.

I had a similar idea but was put off by the effort involved in porting all those nodes to Python and instead I created the in-browser Node-RED implementation that attempts to simulate some nodes in the browser to have a working version of Node-RED running in the browser.

I took the same approach that you are, i.e., take the client as it is and then implement a backend that is able to work with that. It turns out that there isn't much that needs simulating (websocket + admin api are basically all).

All my extensions to the editor (to make the in-browser work) are encapsulated in a single file. I also made some changes to the base Node-RED javascript file but I attempt to keep those to a minimum.

Also what I found useful was to have a Node-RED instance that acts as a source for the client code and then have a script that retrieves all javascript code for the client. For that I created a shell script that retrieves everything that is need for the client. This allows me to change the instance and then update my standalone-serverless Node-RED codebase automagically. This makes updating the Node-RED instance possible.

What does cause issues are config nodes and node-specific API calls. That's what sort of put me off creating a Python backend. Recently I was thinking of creating an Erlang backend which would take advantage of Erlangs in-built concurrency ... if only there would be 48 hours in a day!

I hope you keep at it, I would be interested in using it once it's all done :wink:

Interesting project. Always thought that a Python tool similar to Node-RED would be really useful. If only because Python trends to have more comprehensive (or at least more mature) data manipulation libraries.

Never really got on with that myself. But I've far too many years experience with the HTML. To me, HTML/CSS/JS should be the standard for UI's.

@gregorius - I'll have to take a look at what you did, I've gone through that exercise before of isolating the client, it is very fun. Another backburner idea is a browser app that can make games that live as a standalone html file, I'm sure there'll be some crossover with this project.

One thing I could never figure out is how that final red.js file is generated from source. I know there's browser packaging tools but I can't tell which one is used, although I'm not that deep into webdev to expect to know.

@TotallyInformation - I like the idea of data manipulation, I know numpy, pandas, and matplotlib are all the rage, unfortunately I have maybe only used 5% of what I'm sure they offer. There's definitely value in doing complex math in a flow structure, can you imagine seeing plots in the debug river! that would be amazing!

It just is! I just take it as is and have the script retrieve it fresh each time something changes in Node-RED, i.e., new nodes are installed with new html/js code to be included in the red.js

The Python tools for that are generally AirFlow combined with Jupyter - so there is no real point in re-inventing the wheel for ETL + Data manipulation. There is a whole bunch of other Python helpers in that sector.

An emphasis on visually creating web flows sites (for example) would be something new for the Python would - at least I've never heard of a visual tool for modelling the flow of web requests in Python. A kind of visual interface to Flask would be something new, just as Node-RED can be a visual interface for Express.

Or simply the IoT tool for Python for modelling data flows from many devices!

1 Like

Agreed. I've played with Jupyter notebooks a fair bit, but the idea of a Python-RED is certainly interesting. :smile:

A Python driven UIBUILDER would be interesting for sure. :smile:

Fyi: I'll put up an announcement once I have a first initial working version of this but I've started on porting Node-RED to Erlang and to my pleasant surprise: it does work.

For those that don't know Erlang, it's a concurrent programming language that has very good concurrency and error management. This means that in a Erlang implementation, each node becomes an independent process which handles messages as they come in. Each process can be given a supervisor that spins it back up if something goes wrong.

The only problem with Erlang is that it's incredible hard (for anyone starting out) to understand, its syntax is a combination of Prolog and Lisp. It is a functional programming language and uses function closure matching as a form of flow control - great fun if you know Prolog.

My work so far is over here. I'm just working on getting an inject node to trigger a flow and a debug node to send an update via a websocket so that the debug panel is updated. That would be the first round-trip proof-of-concept for work-in-progress.

1 Like

I think I'm too old to once again try to get my head around Lisp let along Prolog. So sadly I doubt this will be of use to me :frowning:

No no, you misunderstand - the point is that this is a 1-to-1 compatible version of Node-RED.

Ideally any NR flow[1] will run on Erlang using this, so there is no need to learn Erlang!

Just as - ideally - you don't need to know NodeJS code to use Node-RED, so it will be with Erlang-RED - no Erlang/Prolog/Lisp knowledge required.

Now before you start out on how difficult this will be and what can go wrong and "what about my <insert name here> favourite node" - it all doesn't matter because this is an experiment which is designed to do nothing other than fill some time between now and then (for me that is)!

If, however, something does happen so that this project becomes useful for someone, then that is pure coincidence and not planned :wink:

[1] ignore function nodes that contain JS code!

P.S. notice the liberal usage of the word ideally - this is intended and is not ideal.

EDIT: last two comments have nothing to do with this thread - sorry if you read this far.

I think I do :grin:

Ah, but you DO if you want to create custom nodes - and, as you know, I DO have custom nodes published.

All I am saying is that, while I might consider doing some development by dusting off my very rusty Python skills, Erlang is likely to be beyond my pain tolerance. One of the advantages of being based on Node.js is that you get ready access to more developers.

It is an interesting experiment for sure.

Now, if you wanted to rewrite in FORTH, I might be up for that as I was very keen on that language for some time. :rofl: