@hyamanieu/node-red-pixi-tasks 1.0.0

Node-RED nodes that run Python functions and commands in reproducible pixi environments

npm install @hyamanieu/node-red-pixi-tasks

node-red-pixi-tasks

npm version CI Node-RED Node.js Python Licence: MIT

Call Python from your Node-RED flows, on this machine, in a container or on a cloud GPU, without changing the flow. Or any compiled language pixi supports, like Rust.

Status: v1, the first release. Phases 0 to 2 are complete. Phase 3 (container execution) is next; see ROADMAP.md for the plan.

Roadmap status:

  • Phase 0: containerised development environment
  • Phase 1: local execution (MVP): call Python functions and commands from your flows
  • Phase 2: ergonomics: parallel call processing and direct TOML editing (in 1.0.0)
  • Phase 3: container execution
  • Phase 4: orchestrator-backed execution (optional)
  • Phase 5: cloud execution
  • Phase 6: payload and schema ergonomics (optional, unscheduled)

The idea

Node-RED is very good at talking to the physical world: PLCs, serial buses, MQTT brokers, OPC-UA servers, REST APIs. It is much less comfortable when the next step is compute: fitting a model, resampling a few million rows, running an image through a vision pipeline. That work belongs in Python.

Today the answer is an exec node running python script.py. This package replaces that with something you can put in production:

[ MQTT in ] → [ pixi python: detect_anomaly ] → [ switch ] → [ alert ]

You write a normal Python function. The node calls it. The return value comes out of the node. Exceptions become Node-RED errors you can handle with a catch node.

Installation

Install it from npm:

cd ~/.node-red
npm install @hyamanieu/node-red-pixi-tasks

Or from the repository:

cd ~/.node-red
npm install github:hyamanieu/node-red-pixi-tasks # `--allow-git all` for npm >= v12

Restart Node-RED: the five nodes appear in the palette under the pixi category.

Supported: Node-RED 4.1 to 5, Node.js 20 to 24, Python 3.12 to 3.15 on Linux x86-64. Every combination in that list runs in CI on each push, and the badge at the top of this page reports the result.

pixi is the package manager that builds each node's environment, in a folder of its own. It is a single static binary with no dependencies of its own. The nodes look for PIXI_HOME first, then ~/.pixi, then pixi on PATH.

pixi and npm install scripts

The package installs pixi into ~/.pixi during npm install, with an install script. npm does not always run those: since 11.16 it asks you to allow them, and npm 12 does not run them at all unless you do. That install still succeeds, so a host can end up with the nodes but no pixi.

If your install printed a warning about allowScripts, or you installed from the palette (Manage palette) and the nodes report that pixi was not found, do one of these:

# let npm run the package's install script, then rerun it
npm install-scripts approve @hyamanieu/node-red-pixi-tasks && npm rebuild
# or install pixi directly; no npm involved, no allowlist to maintain
curl -fsSL https://pixi.sh/install.sh | sh

Either way, restart Node-RED afterwards. The bootstrap needs network access and curl; managing pixi yourself with --ignore-scripts works too. Nothing else in the package downloads anything.

One exception is worth knowing, because it makes the npm warning misleading. Installing from the repository (npm install github:hyamanieu/node-red-pixi-tasks) bootstraps pixi even on npm 12. This bug has been reported here.

Running on Alpine

The Node-RED base Docker image runs on Alpine, which uses musl rather than glibc. On that image, installing Python 3.14 or later, or using libraries with C-compiled code such as numpy, fails.

The nodes

All five sit in the pixi palette category and work together: one describes the environment, the others run code in it or write files into it.

pixi workspace

The configuration node. It describes an environment, meaning which packages it needs, and builds it as a workspace of its own. You own one per environment and reference it from the other nodes.

The environment can be defined two ways:

  • the simple editor takes a list of dependencies, one per line, version specifiers allowed (python-freethreading=3.15, numpy, pandas>=2.0).
  • the manifest editor takes the complete pixi.toml, for what a list cannot express: extra channels, several platforms, [feature.*] sections, tasks, platform-specific dependencies. A manifest needs a [workspace] table with the channels and platforms to resolve against, and a [dependencies] table. Opening the manifest editor on an environment that already exists loads the pixi.toml that environment has, so you start from the file in use. The two editors are not convertible: saving a manifest takes over the definition of the environment, and going back to the list discards the manifest text stored in the node, leaving the file on disk as it was.

The environment itself lives in a folder named after the node's Name, on the Node-RED host, and survives restarts. Deleting the configuration node deletes that folder for good, build cache included.

Worker mode is what the rest of the package builds on:

  • auto (default) runs calls on threads when the interpreter has no GIL, and in processes when it has one, so CPU-bound work is parallel either way.
  • threads runs them on a pool of threads inside the worker. Real parallelism only on a no-GIL build; with the GIL, I/O-bound calls still overlap while CPU-bound ones take turns.
  • processes runs them in a pool of separate interpreters. CPU-bound calls are parallel even with the GIL, at the cost of copying payload and result across, one interpreter per process in memory, and no shared state between calls.
  • sequential runs them one after another in the worker. Lowest latency, shared state, and one slow call blocks the others.
  • deactivated starts no worker at all. The environment is installed and pixi run works in it, while pixi python reports an error. This is how an environment with no Python interpreter in it is described, a Rust one for example.

Responses are matched to their request, so parallel calls may reach the node out of order. For the best parallel performance, depend on python-freethreading instead of python. In processes mode the payload and the result must be picklable; they are plain JSON today, so they always are.

pixi python

Runs the Python function body written in the dialog, for each message, in the environment's persistent worker. You write the body only: no def, payload as the input variable, and return for the result, like Node-RED's core function node but in Python. The return value becomes msg.payload, and everything else on the message is preserved.

Pre-imported Modules takes a comma-separated list (numpy,pandas) imported before each call, so the body can use them without import statements. Timeout is per call, in milliseconds, and 0 disables it. Exceptions come back through node.error with type, message and traceback, so a catch node handles them.

This node needs an interpreter in the workspace: with worker mode deactivated it reports an error instead of running. Modules kept in the flow are importable with import sys; sys.path.insert(0, "src"), but the worker imports a module once and keeps it, so redeploy after editing one.

pixi run

Runs a command inside the environment for each message, one process per message, with pixi run -e <environment> -x <command> [args...]. The command is resolved on the environment's PATH. This covers CLI tools with no Python API, packages too large to write inline, and compiled languages, and it works whether or not the workspace runs a worker.

Fixed Arguments are prepended to the arguments a message brings. The payload becomes arguments: an array element by element, an object as a single JSON string, anything else as one stringified value. Set Payload to Ignore when the message only triggers the command, which is what a build node wants when it follows pixi source files.

stdout, trimmed, becomes msg.payload. A non-zero exit code or a timeout is reported through node.error, with the end of the tool's stderr in the message and the whole output on msg.error.stderr. Timeout is per call, in milliseconds.

pixi code

Holds one file: a plain name and its content. It writes nothing itself, it emits them as msg.filename and msg.payload, ready for pixi source files. The node shows that file name on the canvas when it has no name of its own, which is what tells two of them apart in a flow.

File name is a plain name such as main.py or utils.rs, not a path; leave it blank to keep the one the message already carries. Highlight picks the editor's mode for JSON, YAML, Python, TOML or Rust and only changes the colours: the content is emitted exactly as written. Whether a mode lights the text up depends on the editor build Node-RED ships, as it does for the core template node's own formats.

pixi source files

Writes what a message describes into the selected workspace's src folder, then reports what that folder holds. It needs no worker, so it works with worker mode deactivated too.

Two shapes arrive: a string or Buffer payload, written to the file named by msg.filename, or an array of { filename, payload } objects, each written to its own file in order, with msg.filename ignored. An empty payload deletes that file, which is how a flow removes a source it no longer needs, and an empty array does nothing rather than deleting everything.

src stays flat, and a name containing a directory is refused. Node-RED is not the place to grow a package tree; it is for a couple of files an environment compiles or imports. A file whose content did not change is not rewritten, so its modification time stays put and a compiler behind it stays incremental. Every entry of an array is checked before the first write, so one bad entry cannot leave half a set behind.

The output is the report of the folder:

Key Contents
files every file in src, sorted, as { filename, created, modified, status }
workspace the name of the workspace written to
deleted the names this message removed

status is created, modified or unchanged, and a file the message did not touch stays unchanged. created is the file's birth time, which not every filesystem records, so it is null there rather than a wrong date.

From src, the files are reached the ordinary way: cargo build and cargo run for Rust, python src/report.py through pixi run for Python.

Reusable logic is installed as a dependency (PyPI, conda-forge, git URL, or a private index), then referenced either by importing it in a pixi python body or by calling its CLI entry point with pixi run. Sources you keep in the flow are what pixi code and pixi source files are for. Putting files elsewhere on the Node-RED host by hand is not supported and is out of scope.

Rust, and other compiled languages

Python is what this package is for: the worker, the parallel modes and the editor are built around it. The environment is a general pixi environment, though, so a compiled language is not blocked: it just does not get a worker.

A Rust workspace, end to end

This is the pixi Rust tutorial with one node per command:

  1. pixi workspace, Define the environment by → writing the manifest, with rust in the dependencies:

    [workspace]
    name = "rust-env"
    channels = ["conda-forge"]
    platforms = ["linux-64"]
    
    [dependencies]
    rust = "*"
    
  2. Worker mode → deactivated. There is no Python interpreter in this environment, so no worker is started and the workspace stays usable by pixi run instead of failing to start.

  3. pixi run, command cargo, fixed arguments init. That is the tutorial's pixi run cargo init: cargo creates Cargo.toml and a hello-world src/main.rs inside the workspace folder, so you do not write a manifest for the crate by hand. Cargo refuses a folder that already holds a crate, so this node is for a fresh workspace. Click it once.

  4. pixi code → pixi source files, twice: once for main.rs, once for utils.rs. Each pixi code node holds one file's text and name in the flow, and the pixi source files node writes it into the workspace's src folder, replacing the generated main.rs and adding the module next to it. A file whose text did not change is not rewritten, so the build stays incremental.

  5. pixi run, command cargo, fixed argument build, then pixi run with run. cargo run compiles first when a source changed, so a single node with the argument run is enough if you would rather have fewer parts; a separate build at deploy keeps the first message fast: about 36 ms per message once built, against about 0.4 s after an edit, on this container.

examples/rust_task.json wires exactly that flow: three injects, one per step, so you can click cargo init once, write the sources, and then run the program on a timer.

The program reads the payload as its first argument (std::env::args()).

One workspace can serve both languages: list python and rust in the same manifest, keep the worker active, and use pixi python for Python and pixi run for the compiled program. Since the environment is reproducible and locked, moving it to a container or a remote machine later is a configuration change, not a rewrite of the flow.

Note: a Rust environment is large (about 1.6 GB) and the first build needs network access to crates.io.

Design principles

  1. The common case needs nothing extra. Node-RED plus this package should be enough to run Python locally. It needs no broker, no database and no orchestrator.
  2. The flow should not encode where code runs. Moving a function to a container or a GPU node is a configuration change.
  3. Built for unattended operation. These flows run for months with nobody logged in. Workers restart, failures are visible, and a broken environment fails loudly at deploy time rather than silently at 03:00.
  4. No JavaScript required. You write Python. The Node-RED side is configuration.

What you get over an exec node

The Python process stays alive between messages, so you pay for interpreter start-up and imports once, not on every message. exec costs hundreds of milliseconds to several seconds per call; that is fine once an hour and unusable at 10 Hz.

Your flow depends on a specific set of Python packages, including the compiled ones whose system-level dependencies break when you move between a laptop, a factory gateway and a server. This package pins all of that behind the scenes, so an environment that works here works there.

When a function outgrows the machine running Node-RED, you change where the environment runs, not the flow:

Where the code runs Good for
The Node-RED host The common case: fast, low-latency, no extra infrastructure
A container Isolation, resource limits, heavy dependency trees
A cloud machine, on demand Jobs needing a GPU or far more RAM than your gateway has

The node, the wiring and the Python function stay the same; only the environment's configuration changes.

Arguments and return values are converted at the boundary, so you are not serialising to a command line and parsing stdout by hand.

Non-goals

  • Replacing Node-RED's function node for ordinary message munging.
  • Being a workflow orchestrator. If you need retries, schedules, backfills and run history, use a real orchestrator; the container tier is designed to be able to delegate to one later.
  • Shipping a Python distribution.

Related work

Several existing packages run Python from Node-RED, among them node-red-pythonshell, node-red-python-venv and node-red-python-function. The better ones already keep a worker process alive. They rely on venv/pip, so environments are only as reproducible as the host they land on, and none offer a path to running the same function on other hardware. If those packages already meet your needs, use them: they are older and have seen far more use than this one.

Developer setup

This project uses Docker Compose for development. No local Node-RED or pixi installation is required.

  1. Clone this repository
  2. Run docker compose up -d
  3. Open http://localhost:1880 in your browser

The package is installed in development mode. Changes to files in nodes/, lib/, python/ are picked up on Node-RED restart, which currently means a manual restart via the menu or docker compose restart node-red.

To stop: docker compose down.

Running the unit tests

The tests run inside the development container, which is how CI runs them:

docker compose exec node-red bash -c 'cd /data/node-red-pixi-tasks && npm test'

npm test runs two layers in sequence:

Layer Runner Location
Node.js: nodes, workspace/environment manager, worker supervision, protocol, example flows loaded in a real Node-RED runtime mocha (+ node-red-node-test-helper) test/lib/, test/nodes/
Python worker: execution-mode resolution, pool sizing, request dispatch, pool-process function cache stdlib unittest, with no pytest or other extra dependency python/tests/

Both layers run Python on the same interpreter: the pixi environment pinned by test/pixi.toml, Python 3.14 by default rather than whatever python3 happens to be on PATH. That manifest is test-only, since the package never reads it, and the environments it manages live under ~/.node-red-pixi/workspaces. It also defines py312 and py315, which the suite uses to check that the worker behaves the same across versions:

# same suite on another Python version
docker compose exec node-red bash -c 'cd /data/node-red-pixi-tasks && NRPYRUN_TEST_PYTHON_ENV=py312 npm test'

Each layer can be run on its own:

# Node.js layer (or a single spec, e.g. test/lib/worker_modes_spec.js)
docker compose exec node-red bash -c 'cd /data/node-red-pixi-tasks && npx mocha test/*/*_spec.js'

# Python layer, exactly as scripts/run-python-tests.js invokes it
docker compose exec node-red bash -c 'cd /data/node-red-pixi-tasks && PYTHONPATH=python pixi run --manifest-path test/pixi.toml -e py314 python -m unittest discover -s python/tests -v'

Notes:

  • Both layers in one command are joined with &&, so a failing Node.js spec stops the run before the Python tests start. Run the Python layer separately to see its result.
  • NRPYRUN_TEST_PYTHON=<interpreter> skips pixi and runs the tests on that interpreter instead (useful off Linux, or for a free-threaded build); NRPYRUN_TEST_PYTHON_ENV selects an environment from test/pixi.toml. With neither set, a host without pixi skips the Python tests with a message; an explicitly requested environment that cannot start is an error instead.
  • The Node.js specs stub ProjectManager.createProject and WorkerManager.start, because a real start would spawn pixi and keep its restart-backoff timers alive after the results print. Process-boundary behaviour (the real worker over stdio, spawn pools) is covered by the specs that spawn the test interpreter directly.
  • CI runs the same suite for Node-RED 4.1, 5 and latest, on Python 3.12 and 3.14. The latest plus Python 3.15 combination is advisory: it reports its result without failing the build.

Examples

examples/ holds the flows the tests load: a minimal call, a throughput benchmark and a parallel task, plus rust_task.json, which follows the pixi Rust tutorial command by command, and python_src_files.json, which keeps two Python modules in the flow and runs them from src (see the Rust section above). End-to-end examples, including a full industrial stack with ingestion, storage and dashboards, live in a separate repository so this one stays focused on the nodes: node-red-pixi-tasks-examples.

Contributing

Issues and pull requests are welcome. The node interfaces are frozen for 1.0.0, so behaviour changes are expected to come with a test and a note in the pull request. See CONTRIBUTING.md.

Licence

MIT

Node Info

Version: 1.0.0
Updated 2 days ago
License: MIT
Rating: not yet rated

Categories

Actions

Rate:

Downloads

0 in the last week

Nodes

  • pixi-workspace
  • pixi-python
  • pixi-run
  • pixi-code
  • pixi-source-files

Keywords

  • node-red
  • python
  • pixi
  • rust
  • conda
  • reproducible
  • parallel

Maintainers