The README screens a month of Sentinel-2 scene records with a filter, a retried and cached read on four threads, and a count per tile, and shows that the whole chain round-trips through JSON with the same content hash. This page picks up from there: the same composition on NumPy arrays with a Graph and an observer, then how the pieces work (the operator model, the wrappers, the execution engine, the dict and list operators, saving and hashing), the zero-dependency guarantee, what pipekit-ops deliberately leaves out, and how to move code written for older versions.
The notation is the README’s. A pipeline is a chain of operators, where maps one carrier to the next, and is its content hash.
Operators on arrays: |, Graph, observers and JSON¶
We standardise a row of reflectance values by a fixed mean and spread , so , clip to to give , and then take the difference of two dates , each cleaned the same way. The carrier is a NumPy array this time, so the example also needs NumPy and jaxtyping (uv add numpy jaxtyping); pipekit-ops itself never imports them.
import numpy as np
from jaxtyping import Float
from pipekit_ops import Graph, Input, Operator, Sequential, Tap, dumps, loads
# Shapes: N = 3 samples
Vector = Float[np.ndarray, " N"]
# user
class Standardize(Operator):
"""Centre and scale by a fixed mean and spread."""
def __init__(self, *, mean: float, std: float) -> None:
# μ
self.mean = mean
# σ
self.std = std
def _apply(self, x: Vector) -> Vector:
# z = (x − μ) / σ
return (x - self.mean) / self.std
# user
class Clip(Operator):
"""Clip to the interval [lo, hi]."""
def __init__(self, *, lo: float, hi: float) -> None:
self.lo = lo
self.hi = hi
def _apply(self, z: Vector) -> Vector:
# z̃ = min(max(z, lo), hi)
return np.clip(z, self.lo, self.hi)
# user
class Difference(Operator):
"""Subtract the second input from the first."""
def _apply(self, a: Vector, b: Vector) -> Vector:
# d = a − b
return a - b
# user
def show(v: Vector) -> None:
print("clean:", v)
# 1 · compose with |: a Sequential, itself an Operator
# user
# z = (x − 10) / 2
standardize = Standardize(mean=10.0, std=2.0)
# user
# z̃ = min(max(z, −3), 3)
clip = Clip(lo=-3.0, hi=3.0)
# today (pipekit-ops)
# o_2 ∘ o_1
clean: Sequential = standardize | clip
# (N,)
x: Vector = np.array([4.0, 10.0, 30.0])
# (N,) → (N,)
z: Vector = clean(x)
# 2 · wire a Graph: named inputs, shared operators, named outputs
# user
difference = Difference()
# today (pipekit-ops)
a = Input("a")
# today (pipekit-ops)
b = Input("b")
a_clean = clean(a)
b_clean = clean(b)
anomaly = difference(a_clean, b_clean)
# today (pipekit-ops)
graph = Graph(inputs={"a": a, "b": b}, outputs={"anomaly": anomaly})
# d = clean(a) − clean(b)
# (N,), (N,) → {"anomaly": (N,)}
out: dict[str, Vector] = graph(a=x, b=x + 2.0)
# 3 · observe without changing the flow
# today (pipekit-ops)
traced: Sequential = clean | Tap(show)
# (N,) → (N,), and show prints the clean values
same_values: Vector = traced(x)
# 4 · configuration is data: an operator round-trips through JSON
# today (pipekit-ops)
text: str = dumps(standardize)
# today (pipekit-ops)
same: Operator = loads(text)
print(z, out["anomaly"], same)This prints clean: [-3. 0. 3.] from the Tap, then [-3. 0. 3.] [-1. -1. 0.] Standardize(mean=10.0, std=2.0). The first is : , 0, and clipped to 3. The second is for , whose cleaned values are . The third is the standardiser rebuilt from its JSON, {"class": "Standardize", "config": {"mean": 10.0, "std": 2.0}, "module": "__main__"}. Inside the Graph, clean(a) called on an Input does not compute anything: it records a node, and the graph runs the nodes in topological order when it is called on data.
The operator model¶
An
Operatorhas one method,_apply(self, carrier) -> carrier. pipekit never inspects the carrier; domain packages narrow it.Composition is
|.a | b | cis aSequential, flattened, so(a | b) | canda | (b | c)are the same three steps. Flows that branch and merge are aGraph, built by calling operators onInputs; it rejects cycles and evaluates in topological order.Wrappers are operators too.
Retry,Timeout,Try,Cache,Mapand the QC asserts take an operator and return one, so they nest anywhere.State is explicit. A
StatefulOperatormaps , a carrier and a state to the next carrier and state, and aSequentialorGraphthreads the state through its stateful steps; pipekit-cycle’sCycleandDACycleand pipekit-train’sTrainingLoopare built on it.Configuration is data. An operator’s constructor arguments, stored under their own names, are its config;
dumpswrites it as JSON andloadsrebuilds the operator.Libraries plug in by protocol.
Predictor,FittableTransformerand the named-array adapters are runtime-checkable seams, so a library satisfies them without importing pipekit (Protocols).
The long form is Concepts. A single operator also carries backends (the array backends it accepts) and compute_output_signature (how it changes a Signature), so Sequential.summary and Graph.summary can print shapes before anything runs.
Wrappers: control, flow, cache and store, observe, QC¶
Control puts decisions and failures inside the pipeline:
Branch,Switch,Try,CoalesceandRetry.TryandRetryneed their exception list, so neither is ever a silent catch-all.Flow limits bound a step:
Timeoutgives up after a number of seconds (the thread is abandoned, not killed),RateLimitcaps calls per period across the threads of one process, andUntilrepeats a step until a predicate holds.Cache and store.
Cache(op)keys on a SHA-256 of the input and the inner operator’spipeline_hash.Cache(op, store="scenes", key=Get("id"))keeps its entries in a named store bound withstore_scope, so the store is not in the config and the pipeline hashes the same on a laptop and on a cluster. ADirectoryStorewrites one pickle per key, atomically; pickle loads run code, so point it only at a directory you control.Observers pass the carrier through unchanged:
Tap,LogandShapeTrace, and the controllersSnapshotandHistogram, whose.at(key)gives the operator you place, andProfile, whose.wrap(op)does.QC turns “this won’t break” into a permanent guard:
AssertShape,AssertDType,AssertThatandAssertSignatureraiseQCError, whileQuarantinereturns a sentinel and keeps going.
Every wrapper is in the core tour, with a run output for each.
A bigger graph puts these together: an anomaly detector that reads a stack of multi-channel images in parallel with retries and a cache, checks the stack, picks a composite by the number of exposures, scores against a background input and summarises, with four named outputs.
The wiring and the six domain operators, step by step and runnable, are in the tutorial Build a bigger graph.
Execution: Map, executors, Prefetch, Fold and the presets¶
Map(op, executor=...) is the one engine for running an operator over many items. executor is "serial", "thread", "process" (spawn by default), "async", or "scope", which borrows the concurrent.futures.Executor that an executor_scope binds (a Dask or Ray one included) and never shuts it down. The executor is not in the config, so the pipeline hashes the same wherever it runs. Input is pulled lazily, at most max_in_flight items are held at once, and on_error is "raise" (fail fast), "collect" (raise a MapError holding the partial results, with a Failed record per failure) or "log_and_continue".
Prefetch(op, depth) reads up to depth items ahead of the consumer, and Fold(op, initial, chunksize) folds chunks in parallel through Map and then combines the partial results. ThreadMap, ProcessMap, AsyncMap and BatchedMap are presets of Map with their own arguments (n_workers, semaphore, batch_size). Process pools need every operator to pickle, so check_pickleable(op) walks a pipeline and returns the operators that hold a closure (they set forbid_in_yaml = True) before you fan out. The details are in the execution design.
Dict and list plumbing¶
A Graph returns a dict, a Fanout returns a dict, and a STAC search returns a list of dicts. The dict operators (Get, GetIn, Pick, Rename, Merge, Assoc, UpdateIn, ValMap, Dissoc) reshape those without a Lambda, and the list operators (Filter, Remove, GroupBy, CountBy, Reduce, Take, SortBy, …) work on a list of items inside the pipeline. Their predicates and keys are operators too, so a chain built from them still round-trips through dumps and loads.
Saving and hashing¶
dumps(op) writes op.state as JSON with sorted keys, nested operators included: a child operator appears in its parent’s config as its own record, a Graph records every node and its wiring, and an exception class is written as {"exception": "builtins.OSError"}. loads rebuilds the whole tree, as long as the modules that define the classes are imported. pipeline_hash hashes that record,
where is the state of and writes it with sorted keys; optional weight bytes are appended after a zero byte. So two pipelines share a hash exactly when they are configured the same, and the pipekit-experiment registries store models under it. Each public class is recorded under the module pipekit_ops, whichever area its file sits in, so moving a class between files inside the package does not change a hash.
For pipelines you did not write (uploaded by users, read from a queue), loads_sandboxed builds only the classes you have registered, at any depth, and checks every class before constructing anything. The operators that hold a function or a debug payload (Lambda, Sink, Tap, ShapeTrace, Branch, Switch, Coalesce, Quarantine and AssertCallable) set forbid_in_yaml: dumps still writes them, but only as a debug record that names the function, loads refuses to rebuild them with a RuntimeError, and pipeline_hash hashes that record, so two different lambdas share a hash. When the pipeline must round-trip, use Log in place of Tap and an operator in place of a plain function wherever the operator takes one (the predicate of Filter, the key of CountBy); the flagged control-flow operators are rebuilt in code. pipekit_ops.testing.assert_round_trip(op, *inputs) checks the contract from your own test suite, and public_operators(module) lists the operators a module exports, so a sweep can fail on one that has no test case yet.
The zero-dependency guarantee¶
pipekit-ops declares no dependencies, and we keep it that way: import pipekit_ops loads only the standard library, and tests/test_no_dependencies.py checks both (the import in a fresh interpreter). The one exception is pipekit_ops.testing, which imports NumPy lazily when assert_round_trip compares two arrays. Array-aware features find what they need through the carrier instead. AssertShape reads shape, Cache keys an array by its bytes, dtype and shape, and the named-array adapters (a NamedArrayAdapter registered by pipekit-array, gridax, geotoolz-array or another library) give a carrier’s dims to AssertSignature and Signature. on_import runs a callback when a module such as jax is imported, without importing it, which is how pipekit-array’s JAX pytree registrations stay optional.
So you get real value from this package without the rest of pipekit, and a library can depend on it without pulling in NumPy, JAX or anything else. If your science has its own carrier (AnnData, astropy tables, a GeoTensor), you write operators for it and get composition, control flow, caching, parallel maps, QC and a JSON round-trip for free. pipekit-ops and pipekit-array are the two foundations of the workspace, each usable on its own, and every other pipekit package builds on pipekit-ops; the workspace README has the layering.
What is not built¶
Two things are left out by design.
There is no automatic parallelism:
Sequentialruns in order andGraphevaluates in one process.There is no graph scheduler:
Map(executor="scope")can send the items of one step to a Dask or Ray executor, but scheduling whole pipelines across machines is left to Dask, Ray, Beam and orchestrators.
The open design questions are in the roadmap.
Moving from older versions¶
From pipekit before 0.2. Until 0.2.0 this package was called pipekit. Change the import; every name and argument is unchanged.
# Today: since 0.2.0 this line raises an ImportError that names the new import
# from pipekit import Operator, Retry, Sequential
# After:
# today (pipekit-ops)
from pipekit_ops import Operator, Retry, SequentialLibraries should depend on pipekit-ops, not on pipekit: since 0.2.0 pipekit is the umbrella that installs the whole workspace, JAX included. States saved before 0.2.0 (dumps output, registry entries) still load: a module saved as pipekit.<name> resolves to pipekit_ops.<name>. Their pipeline_hash changes, because the hash covers each operator’s module.
From the flat layout before 0.4. Until 0.4.0 the package was a flat list of modules (pipekit_ops.control, pipekit_ops.serial, pipekit_ops.hashing, …); since then it is the seven areas. Those modules are gone, so import pipekit_ops.control raises ModuleNotFoundError: import the name from pipekit_ops or from its area (pipekit_ops.saving for sha256_hex) instead. A state saved under one of the flat modules still loads, because record_moves reads those module names as pipekit_ops; its pipeline_hash changes once, since every class is now recorded under pipekit_ops (decision O17 in Decisions).
Further reading¶
Patterns for batch jobs, services, orchestrators and audits, and Guards for
guardandjit_report.The design docs (vision, decisions, roadmap, per-module API specs) and the master plan, Report 2.
The API reference.
Tutorials: a bigger graph, ETL over many regions, inference.
The sibling foundation, pipekit-array, and the rest of the family.