Skip to content

KPN++

A C++20 Kahn Process Network library. Each node wraps a plain function and runs concurrently, communicating with downstream nodes via bounded FIFO channels. Includes Python bindings via nanobind.


Why KPN++?

  • Zero boilerplate — wrap any callable as a node; types flow automatically from the function signature
  • Bounded channels — backpressure is structural, not bolted on
  • Observable — per-node and network-level callbacks for overflow and stop events; diagnostics snapshots; optional web UI
  • ComposableNetwork for runtime wiring, StaticNetwork for compile-time topology with zero overhead

Quick example

#include <kpn/kpn.hpp>
using namespace kpn;

static int  produce()        { return 42; }
static int  double_it(int x) { return x * 2; }
static void print_it(int x)  { std::cout << "result: " << x << '\n'; }

int main() {
    Network net;
    net.add("src",  src)
       .add("dbl",  dbl)
       .add("sink", sink)
       .connect("src",  src.output<0>(),  "dbl",  dbl.input<0>())
       .connect("dbl",  dbl.output<0>(),  "sink", sink.input<0>())
       .build();

    net.start();
    std::this_thread::sleep_for(std::chrono::milliseconds(100));
    net.stop();
}

Install & build

cmake -B build
cmake --build build --parallel
ctest --test-dir build          # unit tests + example smoke tests

See Getting Started for full build options.