Metadata-Version: 2.5
Name: pyflowred-node-lowercase
Version: 0.1.0
Summary: An example PyFlowRED node package: lowercases msg.payload.
Project-URL: Homepage, https://pypi.org/project/pyflowred/
Author: Melvin Neffle
License: Apache-2.0
Keywords: example,flow,node-red,pyflowred
Classifier: Development Status :: 4 - Beta
Classifier: Framework :: AsyncIO
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
Requires-Python: >=3.13
Requires-Dist: pyflowred
Description-Content-Type: text/markdown

# pyflowred-node-lowercase

A node package for [PyFlowRED](https://pypi.org/project/pyflowred/), kept
deliberately small: it adds one node type, `lower-case`, which lowercases
`msg.payload` and passes the message on.

It exists to be **read**. It is the smallest thing that is still a complete
node package — a Python file, an edit dialog, and the entry point that makes
a distribution a node package — so it can be copied as the starting point for
a real one.

## Installing it

From the editor: *Menu → Manage palette → Install*, and search for
`pyflowred-node-lowercase`. Or over the admin API, which is the same path:

```bash
curl -X POST localhost:1880/nodes -H 'content-type: application/json' \
     -d '{"module": "pyflowred-node-lowercase"}'
```

The node appears in the palette under *function* straight away. PyFlowRED
installs it into the environment it keeps beside the flows and writes it down
in `<userDir>/externalModules/requirements.txt`, so a replacement instance
installs the same palette rather than coming up without it.

## What is in it

```
src/pyflowred_node_lowercase/
  __init__.py       nothing to declare: the directory is scanned
  lowercase.py      the node
  lowercase.html    the edit dialog, the help text and the palette label
```

The node itself:

```python
def register(RED):
    class LowerCaseNode(RED.Node):
        def __init__(self, config: dict[str, Any]):
            super().__init__(config)
            self.on("input", self._on_input)

        def _on_input(self, msg, send, done) -> None:
            payload = msg.get("payload")
            if isinstance(payload, str):
                msg["payload"] = payload.lower()
            send(msg)
            done()

    RED.nodes.register_type("lower-case", LowerCaseNode)
```

A payload that is not a string is passed through untouched rather than
coerced: a node that quietly turns a number into `"42"` is harder to debug
than one that leaves it alone.

And what makes the distribution a node package at all:

```toml
[project.entry-points."pyflowred.nodes"]
pyflowred-node-lowercase = "pyflowred_node_lowercase"
```

The entry point *name* is the module name shown in the palette; the *value* is
an importable package whose directory is scanned for `.py`/`.html` pairs.

## Writing your own

Everything above is the whole of it: a `register(RED)` function that declares
a class and registers a type, an `.html` beside it carrying the edit dialog,
the help text and the palette label, and the entry point. Copy this package,
rename it, and replace the body.

Beyond that - config nodes, HTTP endpoints, icons, translations, shipping
example flows, and testing a node - the reference is `docs/writing-nodes.md`
in the PyFlowRED source distribution. See
[pyflowred on PyPI](https://pypi.org/project/pyflowred/).
