Quickstart Example
In this example, we demonstrate a trivial Pyrophone program to convey the principles of a node-based dataflow data processing architecture.
This example will show us defining three custom node types:
- a
Greetingsource node which emits a textual message (hello, pyrophone); - an
Uppercasetransformation node which receives textual messages, converts them to uppercase, and then outputs them; - a
Displaysink node which prints every message it receives on stdout.
Steps
Let's see how this can be accomplished in three easy steps:
Install Pyrophone from PyPI.
Terminal window python3 -m pip install PyrophoneCreate the file
quickstart.py.quickstart.py @node_typeclass Greeting(Source[str]):async def produce(self):while True:yield "hello, pyrophone"@node_typeclass Uppercase(Transform[str, str]):async def transform(self, value: str) -> str:return value.upper()@node_typeclass Display(Sink[str]):async def consume(self, message: str):print(message, flush=True)@maindef graph():return Greeting() | Uppercase() | Display()Run.
Terminal window python3 quickstart.pyHELLO, PYROPHONEHELLO, PYROPHONEHELLO, PYROPHONEThe processing pipeline prints one message per second to stdout. Hit Ctrl-C to stop.