examples/

directory
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 4, 2026 License: Apache-2.0

README

OpenFlange examples

Small, runnable examples. Each one answers one question, and its README shows the literal input, the command and the output — copied from a real run.

Run any command from the repository root. Build the runner once:

go build -o openflange ./cmd/openflange && export PATH="$PWD:$PATH"
example the question it answers runtime needed status
email/ What do a pipe, a composite pipe and a branching pipeline look like? none verified
starlark-transform/ How do I write a multi-statement transformation that runs in-process, with no permissions? none verified
etl-csv/ What does a complete ETL job — CSV in, clean, validate, aggregate, CSV out — look like as one pipeline? none verified
r-summary/ Can the R script I already have be a pipe, unchanged? Rscript + jsonlite verified
r-moving-window/ How do I run window statistics in R without loading the whole stream? Rscript + jsonlite verified
duckdb-sql/ Can a SQL query (aggregation, window functions) be a pipe? duckdb CLI verified
batch-starlark/ What does a pipe in batch mode look like (process_batch)? none verified
batch-python/ How does a Python process receive a batch per line instead of a record per line? python3 verified
batch-r/ How do I run vectorised R over batches — as array lines or as batch files? Rscript + jsonlite verified
batch-node/ How does a Node.js process receive batches — as array lines or as batch files? Node.js verified
batch-file-duckdb/ Can a file-in/file-out tool be a pipe with no glue code (one process per batch)? duckdb CLI verified
npm-package/ How do I ship a pipe as an npm package? Node.js verified
npm-wrapper/ How do I wrap a library that is already on npm, safely pinned? Node.js, npm (network once) verified
go-multiport-validate/ How does one program write several output streams? Go (to build it) verified
python-http-enrich/ Can a pipe run on another server, behind HTTP? python3, curl, jq verified (plain curl, and through the runner's HTTP adapter)
llm/ Do I need an "AI workflow" product to route data with a language model? python3 (Rscript for one pipeline) verified with mock providers
llm/llm-summarise-anthropic/ How do I swap the mock for a real, paid model? python3 + anthropic SDK, an API key not run — opt-in, costs money, sends data
llm/llm-summarise-ollama/ Can the model run on my own machine? python3, an Ollama server untested against a real server
tugql/ Can a TugQL query feed a pipeline? DataTug in development — README only

"verified" means: openflange validate and openflange test pass, and the commands in the example's README were run and their output pasted in.

Run everything

scripts/run-examples.sh        # or: go test ./examples/...

Both validate every manifest and run every portable test with the real binary. An example whose runtime is missing (Rscript, duckdb, node, an uninstalled npm dependency, a runner capability) is skipped, visibly, with the reason — a skip is not a pass. With every runtime present:

examples: 75 passed, 0 failed, 0 skipped

Without R and DuckDB, the same script reports for example:

SKIP  test      examples/r-summary/tests/r-summary.test.yaml — needs Rscript — Rscript is not on PATH

A test file says what it needs on its first line (# requires: Rscript, python3). With OPENFLANGE_EXAMPLES_REQUIRE_ALL=1 (both the script and go test) a missing runtime is a failure instead of a skip; CI sets it and installs every runtime (DuckDB 2.0.1, R 4.5.3 + jsonlite 2.0.0, Node.js 24, Python 3.13), so every example except the opt-in real-model ones runs there.

Same contract, three ways

One manifest — email/pipes/lowercase/OPENFLANGE.md, input text, output text — is everything a host needs. The contract does not change with the place it runs.

1. The command line (available):

printf '"Alice@Example.COM"\n' | openflange run ./examples/email/pipes/lowercase
"alice@example.com"

2. HTTP (available). The HTTP Pipe Protocol exposes the same ports as URLs: open a session, POST the input text, GET the output text.

openflange serve ./examples/email/pipes/lowercase        # 127.0.0.1:8080, loopback only, no token

In another terminal (real transcript; $SID and $TOKEN come from the session response and are different every time):

$ curl -s http://127.0.0.1:8080/pipes | jq -c .
{"spec":"openflange.org/http/v0.1","pipes":[{"id":"lowercase","version":"0.1.0","title":"Lowercase","url":"http://127.0.0.1:8080/pipes/lowercase"}]}
$ curl -s -X POST -H 'Content-Type: application/json' \
    -d '{"version":"0.1.0","inputs":["text"],"outputs":["text"]}' \
    http://127.0.0.1:8080/pipes/lowercase/sessions > session.json
$ jq -c 'del(.sessionToken, .urls) | .sessionId = "<id>"' session.json
{"sessionId":"<id>","expiresAt":"2026-12-03T14:16:16Z","formats":{"inputs":{"text":"application/x-ndjson"},"outputs":{"text":"application/x-ndjson"}}}
$ SID=$(jq -r .sessionId session.json); TOKEN=$(jq -r .sessionToken session.json)
$ S=http://127.0.0.1:8080/sessions/$SID
$ curl -s -H "Authorization: Bearer $TOKEN" $S/outputs/text &
$ printf '"Alice@Example.COM"\n"BOB@example.org"\n' |
    curl -s -H "Authorization: Bearer $TOKEN" -X POST -H 'Content-Type: application/x-ndjson' -T - $S/inputs/text
"alice@example.com"
"bob@example.org"
$ curl -s -H "Authorization: Bearer $TOKEN" $S | jq -c '{state, ports}'
{"state":"completed","ports":{"inputs":{"text":{"state":"completed","records":2,"bytes":36}},"outputs":{"text":{"state":"completed","records":2,"bytes":36}}}}

The output is read while the input is still being sent (&), and -X POST matters: -T alone sends PUT, which the server answers with 405 and Allow: POST. The same pipe is a pipeline node from any other machine's point of view — pipe: http://127.0.0.1:8080/pipes/lowercase with grants: {network: ["127.0.0.1:8080"], remoteData: ["127.0.0.1"]} — or a one-off: openflange run http://127.0.0.1:8080/pipes/lowercase --trusted. scripts/http-protocol-curl-demo.sh runs the whole protocol (token, three concurrent outputs, status, DELETE) and asserts the results; python-http-enrich shows the other direction, a server that is not written in Go.

3. DataTug (in development). DataTug imports this repository's Go implementation rather than re-implementing the contract, so the same OPENFLANGE.md is what its pipe library and designer load. Because lowercase is function-like (one input, one output, one-to-one, deterministic), a query language such as TugQL may also call it as a scalar function — see tugql/. Nothing DataTug-specific is in this repository.

Conventions used by every example

  • A manifest (OPENFLANGE.md) with the licence (Apache-2.0), honest permissions, the processing scope, and cardinality / deterministic only where they are true.
  • Portable tests in tests/*.test.yaml, including the awkward inputs (empty stream, bad records) and the permission refusal.
  • Pinned dependencies wherever there are any (DESCRIPTION, package-lock.json, requirements.txt).
  • Records that cannot be processed are data on a named output, or they fail the run. Nothing is dropped silently.
  • Mock providers are labelled as mocks. Nothing here needs a paid service.

Directories

Path Synopsis
Command validate-email is a multi-port OpenFlange pipe written against the CLI protocol (openflange.org/cli/v0.1) with the Go standard library only.
Command validate-email is a multi-port OpenFlange pipe written against the CLI protocol (openflange.org/cli/v0.1) with the Go standard library only.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL