Documentation
¶
Overview ¶
Package openflange wires the OpenFlange reference implementation together: an Engine owns an adapter registry preloaded with the standard library and the default adapters (Starlark, executable, composite, HTTP Pipe Protocol client), compiles pipes and pipelines into plans and runs them.
eng := openflange.New()
plan, err := eng.Compile(ctx, "./examples/email/normalize-and-mask-email", openflange.CompileOptions{})
out := &stream.Collector{}
rep, err := eng.Run(ctx, plan, runner.Options{
Inputs: map[string]stream.Reader{"email": stream.FromItems(stream.String("Alice@Example.COM"))},
Outputs: map[string]stream.Writer{"email": out},
})
Applications embed the engine and extend it through Engine.Registry: see adapter.Registry.RegisterBuiltin and adapter.Registry.Register.
Example ¶
Compile a pipeline once, then run it with in-memory inputs and outputs and a preview tap on every edge.
package main
import (
"context"
"fmt"
"strings"
openflange "github.com/openflange/openflange-go"
"github.com/openflange/openflange-go/runner"
"github.com/openflange/openflange-go/stream"
)
func main() {
eng := openflange.New()
ctx := context.Background()
plan, err := eng.Compile(ctx, "./examples/email/normalize-and-mask-email-branching", openflange.CompileOptions{})
if err != nil {
fmt.Println(err)
return
}
masked, normalized, rejected := &stream.Collector{}, &stream.Collector{}, &stream.Collector{}
preview := runner.NewPreview(1) // keep the first item seen at every output port
report, err := eng.Run(ctx, plan, runner.Options{
Inputs: map[string]stream.Reader{
"email": stream.NewDecoder(stream.MediaNDJSON, strings.NewReader("\"Alice@Example.COM\"\n\"nope\"\n")),
},
Outputs: map[string]stream.Writer{"masked": masked, "normalized": normalized, "rejected": rejected},
Tap: preview,
})
if err != nil {
fmt.Println(err)
return
}
fmt.Println(report.State, masked.Strings(), normalized.Strings())
fmt.Println("rejected:", rejected.Strings())
fmt.Println("preview:", preview.Items(runner.TapPoint{Node: "lowercase", Port: "text"}))
}
Output: completed ["a***e@example.com"] ["alice@example.com" "nope"] rejected: [{"value":"nope","reason":"expected exactly one @"}] preview: ["alice@example.com"]
Index ¶
- Constants
- Variables
- func EvalExpr(ctx context.Context, expr string, params map[string]any) (any, error)
- type CompileOptions
- type Engine
- func (e *Engine) Capabilities() adapter.Capabilities
- func (e *Engine) Compile(ctx context.Context, target string, o CompileOptions) (*pipeline.Plan, error)
- func (e *Engine) CompileManifest(ctx context.Context, m *manifest.Manifest, o CompileOptions) (*pipeline.Plan, error)
- func (e *Engine) NewFunc(ctx context.Context, m *manifest.Manifest, params map[string]any) (*runner.Func, error)
- func (e *Engine) Run(ctx context.Context, plan *pipeline.Plan, o runner.Options) (*runner.Report, error)
Examples ¶
Constants ¶
const BaseVersion = "0.0.1"
BaseVersion is the version of this implementation as written in the source: the release the code is prepared for.
Variables ¶
var Version = buildVersion()
Version is the version of this implementation: the module version from the build information when the binary or the importing program was built from a tagged release (`go install …/cmd/openflange@v0.0.1` reports "0.0.1"), otherwise BaseVersion. Development builds — pseudo-versions, "(devel)", modified working trees — report BaseVersion.
Functions ¶
Types ¶
type CompileOptions ¶
type CompileOptions struct {
// Params are the target's parameter values.
Params map[string]any
// Grants are run-wide permission grants; Trusted grants everything
// declared (not sandbox-enforced).
Grants manifest.Permissions
Trusted bool
// DisabledOutputs / DisconnectedInputs name optional external ports to
// leave unconnected.
DisabledOutputs []string
DisconnectedInputs []string
// ValidateOnly tolerates unavailable secrets.
ValidateOnly bool
// CoerceParams parses string parameter values as the CLI does.
CoerceParams bool
// BaseDir resolves relative path parameters of a directly-run pipe.
BaseDir string
// AssumeTargetGrants validates a pipe as if its consumer granted exactly
// what the pipe itself declares (used by `openflange validate <pipe>`).
AssumeTargetGrants bool
// Batch holds consumer-side batch settings for a pipe target (the
// equivalent of a node's `batch` in a pipeline file): tighten only.
Batch *manifest.BatchOverride
// NodeBatch holds batch settings addressed to nodes by path (the
// command line's `--batch <node>=…`): applied after the node's own
// `batch`, tighten only.
NodeBatch map[string]*manifest.BatchOverride
// Env and Secrets override the environment / secret providers.
Env func(string) (string, bool)
Secrets func(string) (string, bool)
}
CompileOptions are the per-compilation settings of an Engine.
type Engine ¶
type Engine struct {
// Registry holds adapters and builtin pipes; register extensions here.
Registry *adapter.Registry
// Resolver resolves pipe references. The default handles local paths,
// std: and builtin:; assign a resolve.Resolver for npm:, git:, registry
// references and lockfile enforcement.
Resolver pipeline.Resolver
}
Engine is a configured OpenFlange runner.
Example (RegisterBuiltin) ¶
Register a pipe implemented in Go. Its manifest is ordinary OPENFLANGE.md content; the name must start with "builtin:" (or "std:").
package main
import (
"context"
"fmt"
"io"
openflange "github.com/openflange/openflange-go"
"github.com/openflange/openflange-go/adapter"
"github.com/openflange/openflange-go/manifest"
"github.com/openflange/openflange-go/runner"
"github.com/openflange/openflange-go/stream"
)
func main() {
const doc = `---
spec: openflange.org/pipe/v0.1
id: reverse
version: 0.1.0
inputs:
in: {kind: values}
outputs:
out: {kind: values}
implementation: {type: builtin, name: "builtin:example/reverse"}
---
# Reverse
Implements the [OpenFlange](https://openflange.org/) specification.
`
m, err := manifest.Parse([]byte(doc), manifest.ParseOptions{})
if err != nil {
fmt.Println(err)
return
}
eng := openflange.New()
err = eng.Registry.RegisterBuiltin(&adapter.Builtin{
Name: "builtin:example/reverse",
Manifest: m,
Run: func(ctx context.Context, n *adapter.Node, nio *adapter.IO) error {
in, out := nio.In("in"), nio.Out("out")
for {
batch, err := in.Read(ctx)
if err == io.EOF {
return nil
}
if err != nil {
return err
}
items := make([]stream.Item, 0, batch.Len())
for _, it := range batch.All() {
v, err := it.Value()
if err != nil {
return err
}
s, _ := v.(string)
r := []rune(s)
for i, j := 0, len(r)-1; i < j; i, j = i+1, j-1 {
r[i], r[j] = r[j], r[i]
}
items = append(items, stream.String(string(r)))
}
if err := out.Write(ctx, stream.BatchOf(items...)); err != nil {
return err
}
}
},
})
if err != nil {
fmt.Println(err)
return
}
ctx := context.Background()
plan, err := eng.Compile(ctx, "builtin:example/reverse", openflange.CompileOptions{})
if err != nil {
fmt.Println(err)
return
}
out := &stream.Collector{}
if _, err := eng.Run(ctx, plan, runner.Options{
Inputs: map[string]stream.Reader{"in": stream.FromItems(stream.String("flange"))},
Outputs: map[string]stream.Writer{"out": out},
}); err != nil {
fmt.Println(err)
return
}
fmt.Println(out.Strings())
}
Output: ["egnalf"]
func New ¶
func New() *Engine
New returns an Engine with the standard library and the default adapters.
func (*Engine) Capabilities ¶
func (e *Engine) Capabilities() adapter.Capabilities
Capabilities reports what this engine can run.
func (*Engine) Compile ¶
func (e *Engine) Compile(ctx context.Context, target string, o CompileOptions) (*pipeline.Plan, error)
Compile validates and compiles a pipe, pipeline file, directory or reference into an execution plan. Errors are an errs.List.
func (*Engine) CompileManifest ¶
func (e *Engine) CompileManifest(ctx context.Context, m *manifest.Manifest, o CompileOptions) (*pipeline.Plan, error)
CompileManifest compiles an already loaded manifest.
func (*Engine) NewFunc ¶
func (e *Engine) NewFunc(ctx context.Context, m *manifest.Manifest, params map[string]any) (*runner.Func, error)
NewFunc prepares a function-like pipe for scalar calls (see runner.NewFunc).
Example ¶
Use a function-like pipe as a scalar function: compiled once, called many times.
package main
import (
"context"
"fmt"
openflange "github.com/openflange/openflange-go"
"github.com/openflange/openflange-go/manifest"
"github.com/openflange/openflange-go/stream"
)
func main() {
eng := openflange.New()
m, err := manifest.Load("./examples/email/pipes/lowercase", manifest.LoadOptions{})
if err != nil {
fmt.Println(err)
return
}
lower, err := eng.NewFunc(context.Background(), m, nil)
if err != nil {
fmt.Println(err)
return
}
defer lower.Close()
for _, s := range []string{"Alice@Example.COM", "BOB"} {
out, err := lower.Call(context.Background(), stream.String(s))
fmt.Println(out, err)
}
}
Output: "alice@example.com" <nil> "bob" <nil>
Directories
¶
| Path | Synopsis |
|---|---|
|
Package adapter defines the runtime adapter contract of the OpenFlange reference runner: how an implementation type (builtin, expression, script, executable, http, pipeline, or anything registered from outside this module) is validated before execution and how it runs one node against bounded streams.
|
Package adapter defines the runtime adapter contract of the OpenFlange reference runner: how an implementation type (builtin, expression, script, executable, http, pipeline, or anything registered from outside this module) is validated before execution and how it runs one node against bounded streams. |
|
composite
Package composite is the adapter for `implementation: {type: pipeline}`: a pipe implemented by a nested pipeline file.
|
Package composite is the adapter for `implementation: {type: pipeline}`: a pipe implemented by a nested pipeline file. |
|
exec
Package exec is the subprocess adapter: it runs `executable` implementations, and `script` implementations in r / python / node (sugar for an executable with the conventional interpreter), under the OpenFlange CLI protocol (openflange.org/cli/v0.1).
|
Package exec is the subprocess adapter: it runs `executable` implementations, and `script` implementations in r / python / node (sugar for an executable with the conventional interpreter), under the OpenFlange CLI protocol (openflange.org/cli/v0.1). |
|
httppipe
Package httppipe is the HTTP Pipe Protocol client adapter (openflange.org/http/v0.1): it runs a node whose implementation is `type: http` — or whose pipe was referenced as `https://host/base/pipes/<id>` — on a remote server.
|
Package httppipe is the HTTP Pipe Protocol client adapter (openflange.org/http/v0.1): it runs a node whose implementation is `type: http` — or whose pipe was referenced as `https://host/base/pipes/<id>` — on a remote server. |
|
starlark
Package starlark implements the Starlark language binding of OpenFlange: `expression` and `script` implementations, the `$expr` parameter binding, and the expression engine used by the standard library (std:map, std:filter, ...).
|
Package starlark implements the Starlark language binding of OpenFlange: `expression` and `script` implementations, the `$expr` parameter binding, and the expression engine used by the standard library (std:map, std:filter, ...). |
|
benchmarks
|
|
|
batch
command
Command batch measures what batch mode buys, end to end: the same row-wise transformation written in R, Python, Node.js, DuckDB SQL and Starlark, run by the real `openflange` binary with no batch mode and with batches of 1 to 100,000 records, as array lines and as batch files — plus a pipe whose every call costs 5 ms.
|
Command batch measures what batch mode buys, end to end: the same row-wise transformation written in R, Python, Node.js, DuckDB SQL and Starlark, run by the real `openflange` binary with no batch mode and with batches of 1 to 100,000 records, as array lines and as batch files — plus a pipe whose every call costs 5 ms. |
|
cmd
|
|
|
openflange
command
Command openflange is the standalone OpenFlange runner: it validates, inspects, tests and runs pipes and pipelines without any other product.
|
Command openflange is the standalone OpenFlange runner: it validates, inspects, tests and runs pipes and pipelines without any other product. |
|
Package errs defines the structured error model shared by every OpenFlange package: a stable baseline code (E_* / W_*), a human message, and an optional location (node, port, file, line, YAML path).
|
Package errs defines the structured error model shared by every OpenFlange package: a stable baseline code (E_* / W_*), a human message, and an optional location (node, port, file, line, YAML path). |
|
examples
|
|
|
go-multiport-validate
command
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. |
|
Package httpserver serves OpenFlange pipes with the HTTP Pipe Protocol (openflange.org/http/v0.1): versioned discovery, execution sessions, one independent streaming request per port, an authoritative session status, expiry and cancellation.
|
Package httpserver serves OpenFlange pipes with the HTTP Pipe Protocol (openflange.org/http/v0.1): versioned discovery, execution sessions, one independent streaming request per port, an authoritative session status, expiry and cancellation. |
|
internal
|
|
|
deps
Package deps pins module dependencies that are added ahead of their first use so that go.mod stays stable while packages are developed in parallel.
|
Package deps pins module dependencies that are added ahead of their first use so that go.mod stays stable while packages are developed in parallel. |
|
fakeclock
Package fakeclock provides a manually advanced stream.Clock for tests of the batch-mode wait: no test needs to sleep for a real maxWaitMs.
|
Package fakeclock provides a manually advanced stream.Clock for tests of the batch-mode wait: no test needs to sleep for a real maxWaitMs. |
|
fixture
Package fixture provides the validate-email interoperability fixture of the HTTP Pipe Protocol specification (http/v0.1 §11) as a builtin pipe, and a counting source, for the protocol tests of this module.
|
Package fixture provides the validate-email interoperability fixture of the HTTP Pipe Protocol specification (http/v0.1 §11) as a builtin pipe, and a counting source, for the protocol tests of this module. |
|
safehttp
Package safehttp performs bounded, SSRF-safe HTTP fetches for untrusted URLs (registry indexes, remote pipe definitions, std:http-source):
|
Package safehttp performs bounded, SSRF-safe HTTP fetches for untrusted URLs (registry indexes, remote pipe definitions, std:http-source): |
|
safeyaml
Package safeyaml parses untrusted YAML documents under the OpenFlange safe profile: YAML 1.2 core schema values only, no custom tags, no anchors or aliases, no merge keys, no duplicate keys, a single document, bounded size and nesting depth.
|
Package safeyaml parses untrusted YAML documents under the OpenFlange safe profile: YAML 1.2 core schema values only, no custom tags, no anchors or aliases, no merge keys, no duplicate keys, a single document, bounded size and nesting depth. |
|
semver
Package semver implements SemVer 2.0 versions and the npm-style range subset used by OpenFlange references: exact versions, partial versions ("0.1", "1", "1.x", "*"), caret and tilde ranges, comparators (>=, >, <, <=, =), space-separated conjunction and "||" alternatives.
|
Package semver implements SemVer 2.0 versions and the npm-style range subset used by OpenFlange references: exact versions, partial versions ("0.1", "1", "1.x", "*"), caret and tilde ranges, comparators (>=, >, <, <=, =), space-separated conjunction and "||" alternatives. |
|
Package manifest parses and validates OpenFlange pipe manifests (OPENFLANGE.md: YAML frontmatter + Markdown body) and discovers the pipes of a package directory.
|
Package manifest parses and validates OpenFlange pipe manifests (OPENFLANGE.md: YAML frontmatter + Markdown body) and discovers the pipes of a package directory. |
|
Package pipeline parses pipeline files (pipeline.yaml), validates them against the pipe manifests they reference and compiles them into an explicit execution Plan: nodes, edges, enabled ports, inserted conversions, resolved parameters, grants, adapter and execution location per node.
|
Package pipeline parses pipeline files (pipeline.yaml), validates them against the pipe manifests they reference and compiles them into an explicit execution Plan: nodes, edges, enabled ports, inserted conversions, resolved parameters, grants, adapter and execution location per node. |
|
Package pipetest runs OpenFlange portable tests (openflange.org/test/v0.1): YAML files named `tests/*.test.yaml` or `openflange.test.yaml` next to a manifest.
|
Package pipetest runs OpenFlange portable tests (openflange.org/test/v0.1): YAML files named `tests/*.test.yaml` or `openflange.test.yaml` next to a manifest. |
|
Package registry reads an OpenFlange registry index (openflange.org/registry/v0.1): the generated `index.json` (or `index.ndjson`) of a Git-backed registry.
|
Package registry reads an OpenFlange registry index (openflange.org/registry/v0.1): the generated `index.json` (or `index.ndjson`) of a Git-backed registry. |
|
Package resolve turns pipe references (baseline §4) into loaded manifests: local project paths, `std:` and `builtin:` pipes, npm packages, git repositories and registry references, with a project-local cache (`.openflange/cache`), the `openflange.lock.yaml` lockfile, integrity hashing, locked verification, transitive resolution and cycle detection.
|
Package resolve turns pipe references (baseline §4) into loaded manifests: local project paths, `std:` and `builtin:` pipes, npm packages, git repositories and registry references, with a project-local cache (`.openflange/cache`), the `openflange.lock.yaml` lockfile, integrity hashing, locked verification, transitive resolution and cycle detection. |
|
Package runner executes a compiled pipeline.Plan: one goroutine per node, bounded pipes with blocking backpressure between nodes, broadcast of immutable batches to every enabled consumer, explicit draining of discarded outputs, fail-fast cancellation that unblocks every wait, and a structured run report.
|
Package runner executes a compiled pipeline.Plan: one goroutine per node, bounded pipes with blocking backpressure between nodes, broadcast of immutable batches to every enabled consumer, explicit draining of discarded outputs, fail-fast cancellation that unblocks every wait, and a structured run report. |
|
Package std implements the OpenFlange portable standard library (`std:<name>`, version 0.1) as in-process Go pipes.
|
Package std implements the OpenFlange portable standard library (`std:<name>`, version 0.1) as in-process Go pipes. |
|
Package stream contains the OpenFlange data plane: items, immutable batches, port kinds and media types, codecs (NDJSON, text, binary, CSV, window frames) and bounded pipes with backpressure and cancellation.
|
Package stream contains the OpenFlange data plane: items, immutable batches, port kinds and media types, codecs (NDJSON, text, binary, CSV, window frames) and bounded pipes with backpressure and cancellation. |