Skip to content

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 Greeting source node which emits a textual message (hello, pyrophone);
  • an Uppercase transformation node which receives textual messages, converts them to uppercase, and then outputs them;
  • a Display sink node which prints every message it receives on stdout.

Steps

Let's see how this can be accomplished in three easy steps:

  1. Install Pyrophone from PyPI.

    Terminal window
    python3 -m pip install Pyrophone
  2. Create the file quickstart.py.

    quickstart.py
    from pyrophone.script import *
    import asyncio
    @node_type
    class Greeting(Source[str]):
    async def produce(self):
    while True:
    yield "hello, pyrophone"
    await asyncio.sleep(1)
    @node_type
    class Uppercase(Transform[str, str]):
    async def transform(self, value: str) -> str:
    return value.upper()
    @node_type
    class Display(Sink[str]):
    async def consume(self, message: str):
    print(message, flush=True)
    @main
    def graph():
    return Greeting() | Uppercase() | Display()
  3. Run.

    Terminal window
    python3 quickstart.py
    HELLO, PYROPHONE
    HELLO, PYROPHONE
    HELLO, PYROPHONE

    The processing pipeline prints one message per second to stdout. Hit Ctrl-C to stop.