Create a Process Template
Use a process template to define a workflow that consumes or produces resources. Templates contain resource slots, ordered steps, role bindings, and parameters.
from recap import Direction
with namespace.build_process_template("Collect Data", "1.0") as builder:
builder.add_resource_slot("sample", "sample", Direction.input)
builder.add_resource_slot(
"calibration", "calibration", Direction.input, required=False
)
builder.add_resource_slot(
"output", "file", Direction.output, create_resource_type=True
)
(
builder.add_step("Collect")
.add_parameters({
"acquisition": [
{"name": "exposure", "type": "float", "default": 1.0}
]
})
.bind_slot("sample", "sample")
.bind_slot("output", "output")
.close_step()
)Add required and optional slots
Slots identify resource types used by a process. Slots are required by default; set required=False when a run may omit that resource, such as optional calibration data.
builder.add_resource_slot("sample", "sample", Direction.input)
builder.add_resource_slot(
"calibration", "calibration", Direction.input, required=False
)Declare input and output directions
Use Direction.input for resources consumed by a process and Direction.output for resources it produces. Direction is part of the slot definition and keeps process roles explicit.
builder.add_resource_slot("source", "raw-data", Direction.input)
builder.add_resource_slot("result", "processed-data", Direction.output)Create resource types from slots
Set create_resource_type=True when slot’s named resource type should be created as part of template construction. Leave it false when type must already exist or is managed separately.
builder.add_resource_slot(
"report", "analysis-report", Direction.output,
create_resource_type=True,
)Define step parameters
Add typed parameter groups to a step. Parameters support defaults, units, and metadata constraints just like resource properties:
step = builder.add_step("Collect")
step.add_parameters({
"acquisition": [
{"name": "exposure", "type": "float", "default": 1.0, "unit": "s"},
{"name": "mode", "type": "str", "default": "standard"},
],
})
step.bind_slot("sample", "sample")
step.bind_slot("output", "output")
step.close_step()Use model_dump() on a parameter model to inspect its current values, and model_json_schema() to inspect the validation schema generated from your declarations.
Bind slots to step roles
bind_slot(role, slot_name) gives a step a local name for one of the template’s slots. The role is an arbitrary string that you choose; it is not validated against any fixed vocabulary.
step.bind_slot("source", "input_plate")
step.bind_slot("destination", "result_file")Roles are the stable interface between step logic and resources. A step can refer to “the source” without naming one particular plate, which is what lets the same template serve every run.
Inspect assignments on a run
When a run is loaded with its resources, assigned values are available by slot name:
run = (
namespace.query_maker()
.process_runs()
.include_steps(include_parameters=True)
.include_resources()
.first()
)
input_plate = run.assigned_resources["input_plate"].resourceProcess templates are versioned. Once a template becomes referenced, lifecycle rules prevent unsafe mutation; create a new version when the workflow shape must change.