Python API Reference¶
This reference documents the public Python surfaces that are intended for user workflows, tool authoring, compute payload construction, and compute submission.
For guided learning, start with Python Workflow API, Building Tool Contracts in Python, and From Python Workflow to Compute Payload. Use this page when you need signatures and member-level detail.
sophios.apis.python.workflow and sophios.apis.python.tool_builder¶
Import user-facing workflow and tool-authoring objects from their concrete modules:
from sophios.apis.python.workflow import Step, Workflow
from sophios.apis.python.tool_builder import CommandLineTool, Input, Output
The detailed member documentation lives in the concrete modules below.
sophios.apis.python.workflow¶
Python API for building Sophios workflows that compile to CWL.
- class sophios.apis.python.workflow.DisableEverythingFilter(name='')¶
- class sophios.apis.python.workflow.Step(clt_path, config_path=None, *, step_name=None, tool_registry=None)¶
A workflow step backed by a CWL
CommandLineTool.Attribute writes like
step.message = "hi"bind named step inputs. Attribute reads likestep.output_fileresolve named step outputs. The same ports are also available through the explicitstep.inputs.*andstep.outputs.*namespaces.-
clt:
CommandLineTool|CommandLineTool|CommandLineTool¶
-
inputs:
ParameterNamespace[InputParameter,InputParameter]¶
-
outputs:
ParameterNamespace[OutputParameter,OutputParameter]¶
- __init__(clt_path, config_path=None, *, step_name=None, tool_registry=None)¶
Create a
Stepfrom a CWL file or CommandLineTool-like object.- Parameters:
clt_path (Any) – Path to a CWL tool definition, or an object with
nameandto_dict()such astool_builder.CommandLineTool.config_path (StrPath | None) – Optional YAML config used to pre-bind file-backed step inputs.
step_name (str | None) – Optional workflow step name override.
tool_registry (Tools | None) – Optional fallback registry for known tools.
- Raises:
TypeError – If the source or config uses an unsupported type.
InvalidCLTError – If the CWL tool cannot be loaded from disk or the registry.
- Returns:
The step is initialized in place.
- Return type:
None
- classmethod from_cwl(document, *, process_name=None, run_path=None, config=None, tool_registry=None)¶
Create a
Stepfrom an in-memory CWL CommandLineTool document.- Parameters:
document (Mapping[str, Any]) – Parsed CWL CommandLineTool fields.
process_name (str | None) – Optional step name override.
run_path (StrPath | None) – Optional virtual
.cwlpath for compiler bookkeeping.config (Mapping[str, Any] | None) – Optional input values to pre-bind.
tool_registry (Tools | None) – Optional tool registry retained on the step.
- Raises:
TypeError – If
run_pathuses an unsupported type.InvalidCLTError – If the CWL document cannot be parsed.
- Returns:
A fully initialized step backed by the in-memory tool.
- Return type:
- bind_input(name, value)¶
Bind a value or upstream output to a named step input parameter.
- Parameters:
name (str) – The input parameter name.
value (Any) – A literal value, a workflow input reference, or a step output.
- Raises:
AttributeError – If the named input does not exist on the step.
- Returns:
The step is mutated in place.
- Return type:
None
- scatter_on(*inputs, method='dotproduct')¶
Scatter this step over one or more already-bound input parameters.
- get_inp_attr(name)¶
Return a named input parameter from this step.
- Parameters:
name (str) – The input parameter name.
- Raises:
AttributeError – If the input does not exist.
- Returns:
The requested step input parameter.
- Return type:
InputParameter
- get_output(name)¶
Return a named output parameter from this step.
- Parameters:
name (str) – The output parameter name.
- Raises:
AttributeError – If the output does not exist.
- Returns:
The requested step output parameter.
- Return type:
OutputParameter
- flatten_steps()¶
Return this step as a single-item list for recursive traversal.
-
clt:
- class sophios.apis.python.workflow.Workflow(steps, workflow_name)¶
A Sophios workflow composed from
Stepobjects and nestedWorkflowobjects.-
inputs:
ParameterNamespace[InputParameter,WorkflowInputReference]¶
-
outputs:
ParameterNamespace[OutputParameter,OutputParameter]¶
- __init__(steps, workflow_name)¶
Create a workflow from steps and/or nested subworkflows.
- add_input(name, parameter_type=None)¶
Declare a workflow input explicitly.
- Parameters:
name (str) – The workflow input name.
parameter_type (Any) – Optional CWL type expression for the input.
- Returns:
The created or existing workflow input parameter.
- Return type:
InputParameter
- add_output(name, source=None, *, parameter_type=None, implicit=False)¶
Declare a workflow output explicitly.
- Parameters:
name (str) – The workflow output name.
source (Any) – Optional step output or workflow input reference to expose.
parameter_type (Any) – Optional CWL type expression for the output.
- Returns:
The created or existing workflow output parameter.
- Return type:
OutputParameter
- bind_input(name, value)¶
Bind a literal value or upstream output to a workflow input.
- Parameters:
name (str) – The workflow input name.
value (Any) – A literal value, workflow reference, or step output.
- Returns:
The workflow is mutated in place.
- Return type:
None
- bind_output(name, value)¶
Bind a named workflow output to a step output or workflow input.
- Parameters:
name (str) – The workflow output name.
value (Any) – A step output or workflow input reference to expose.
- Returns:
The workflow is mutated in place.
- Return type:
None
- get_inp_attr(name)¶
Return a named workflow input, creating it if needed.
- Parameters:
name (str) – The workflow input name.
- Returns:
The created or existing workflow input parameter.
- Return type:
InputParameter
- append(step_)¶
Append a step or nested workflow to this workflow.
- Parameters:
step (Any) – The
SteporWorkflowto append.- Raises:
TypeError – If
step_is neither aStepnor aWorkflow.- Returns:
The workflow is mutated in place.
- Return type:
None
- write_ast_to_disk(directory)¶
Write this workflow tree to disk as sibling
.wicfiles.This compatibility method is retained for existing callers. New code should prefer
write_wic(), which can write either one inline document or a sibling-file tree.- Parameters:
directory (Path) – Directory where the workflow AST should be written.
- Returns:
Files are written to disk as a side effect.
- Return type:
None
- to_wic(*, inline_subworkflows=True)¶
Return this workflow as
.wicYAML text.
- write_wic(path=None, *, inline_subworkflows=True)¶
Write this workflow as a
.wicfile.- Parameters:
path (StrPath | None) – Destination
.wicpath or output directory. When omitted, writes<workflow>.wicin the current directory.inline_subworkflows (bool) – Whether nested workflows should be embedded in the root file. When false, nested workflows are written as sibling
.wicfiles beside the root document.
- Returns:
The root
.wicfile that was written.- Return type:
Path
- flatten_steps()¶
Return every concrete step in this workflow tree.
- flatten_subworkflows()¶
Return this workflow and all nested subworkflows.
- compile(write_to_disk=False, *, tool_registry=None)¶
Compile this workflow into CWL.
- Parameters:
write_to_disk (bool) – Whether to also write generated CWL to
autogenerated/.tool_registry (Tools | None) – Optional tool registry override.
- Returns:
The compiler result tree for this workflow.
- Return type:
- write_artifacts(*, tool_registry=None)¶
Compile this workflow and write generated CWL artifacts to disk.
- Parameters:
tool_registry (Tools | None) – Optional tool registry override.
- Returns:
The compiler result tree for this workflow.
- Return type:
- get_cwl_workflow(*, tool_registry=None)¶
Return the compiled CWL workflow JSON and generated input object.
- Parameters:
tool_registry (Tools | None) – Optional tool registry override.
- Returns:
A JSON-serializable representation of the compiled CWL workflow.
- Return type:
Json
- run(run_args_dict=None, user_env_vars=None, basepath='autogenerated', tool_registry=None)¶
Compile and execute this workflow locally.
- Parameters:
run_args_dict (dict[str, str] | None) – Runtime CLI options for local execution.
user_env_vars (dict[str, str] | None) – Environment variables to expose to the run.
basepath (str) – Directory used for generated files and execution artifacts.
tool_registry (Tools | None) – Optional tool registry override.
- Returns:
The workflow is executed as a side effect.
- Return type:
None
-
inputs:
sophios.apis.python.tool_builder¶
Public CWL v1.2 CommandLineTool authoring API.
The required core is intentionally small:
`python
inputs = Inputs(input=Input(cwl.directory, position=1))
outputs = Outputs(output=Output(cwl.directory, from_input=inputs.input))
tool = CommandLineTool("example", inputs, outputs)
`
Everything else is optional and chainable.
- exception sophios.apis.python.tool_builder.ToolBuilderValidationError¶
Raised when a generated CLT fails schema validation.
- class sophios.apis.python.tool_builder.CommandArgument(value=None, binding=None, extra=<factory>)¶
A structured CWL command-line argument.
-
binding:
Optional[CommandLineBinding]¶
- __init__(value=None, binding=None, extra=<factory>)¶
-
binding:
- class sophios.apis.python.tool_builder.CommandLineBinding(position=None, prefix=None, separate=None, item_separator=None, value_from=None, shell_quote=None, extra=<factory>)¶
A CWL input binding or argument binding.
- __init__(position=None, prefix=None, separate=None, item_separator=None, value_from=None, shell_quote=None, extra=<factory>)¶
- class sophios.apis.python.tool_builder.CommandLineTool(name, inputs, outputs, cwl_version='v1.2', label_text=None, doc_text=None, _base_command=<factory>, _arguments=<factory>, _requirements=<factory>, _hints=<factory>, _stdin=None, _stdout=None, _stderr=None, _intent=<factory>, _namespaces=<factory>, _schemas=<factory>, _success_codes=<factory>, _temporary_fail_codes=<factory>, _permanent_fail_codes=<factory>, _extra=<factory>)¶
Declarative CWL CommandLineTool authoring object.
- describe(label=None, doc=None)¶
- Return type:
- label(text)¶
- Return type:
- doc(text)¶
- Return type:
- namespace(prefix, iri=None)¶
- Return type:
- schema(iri)¶
- Return type:
- edam()¶
- Return type:
- intent(*identifiers)¶
- Return type:
- base_command(*parts)¶
- Return type:
- stdin(value)¶
- Return type:
- stdout(value)¶
- Return type:
- stderr(value)¶
- Return type:
- add_argument(argument)¶
- Return type:
- argument(value=None, **kwargs)¶
- Return type:
- requirement(requirement, value=None)¶
- Return type:
- hint(requirement, value=None)¶
- Return type:
- docker(image=None, *, as_hint=False, **kwargs)¶
- Return type:
- inline_javascript(*expression_lib, as_hint=False, extra=None)¶
- Return type:
- schema_definitions(*types, as_hint=False, extra=None)¶
- Return type:
- load_listing(value, *, as_hint=False, extra=None)¶
- Return type:
- shell_command(*, as_hint=False, extra=None)¶
- Return type:
- software(packages, *, as_hint=False, extra=None)¶
- Return type:
- initial_workdir(listing, *, as_hint=False, extra=None)¶
- Return type:
- stage(reference, *, writable=False, entryname=None, as_hint=False, extra=None)¶
- Return type:
- env_var(name, value, *, as_hint=False)¶
- Return type:
- resources(*, as_hint=False, extra=None, **kwargs)¶
- Return type:
- gpu(*, cuda_version_min=None, compute_capability=None, device_count_min=None, as_hint=True, extra=None)¶
- Return type:
- work_reuse(enable, *, as_hint=False, extra=None)¶
- Return type:
- network_access(enable, *, as_hint=False, extra=None)¶
- Return type:
- inplace_update(enable=True, *, as_hint=True, extra=None)¶
- Return type:
- time_limit(seconds, *, as_hint=False, extra=None)¶
- Return type:
- success_codes(*codes)¶
- Return type:
- temporary_fail_codes(*codes)¶
- Return type:
- permanent_fail_codes(*codes)¶
- Return type:
- extra(**values)¶
- Return type:
- to_step(*, step_name=None, run_path=None, config=None, tool_registry=None)¶
Convert this built CLT into an in-memory workflow Step.
- Parameters:
- Returns:
A workflow step backed by this CLT without writing to disk.
- Return type:
- validate(*, skip_schemas=False)¶
- Return type:
- __init__(name, inputs, outputs, cwl_version='v1.2', label_text=None, doc_text=None, _base_command=<factory>, _arguments=<factory>, _requirements=<factory>, _hints=<factory>, _stdin=None, _stdout=None, _stderr=None, _intent=<factory>, _namespaces=<factory>, _schemas=<factory>, _success_codes=<factory>, _temporary_fail_codes=<factory>, _permanent_fail_codes=<factory>, _extra=<factory>)¶
- class sophios.apis.python.tool_builder.CommandOutputBinding(glob=None, load_contents=None, output_eval=None, extra=<factory>)¶
A CWL output binding.
- __init__(glob=None, load_contents=None, output_eval=None, extra=<factory>)¶
- class sophios.apis.python.tool_builder.Dirent(entry, entryname=None, writable=None, extra=<factory>)¶
A CWL InitialWorkDirRequirement listing entry.
- classmethod from_input(reference, *, writable=False, entryname=None, extra=None)¶
- Return type:
- __init__(entry, entryname=None, writable=None, extra=<factory>)¶
- class sophios.apis.python.tool_builder.DockerRequirement(docker_pull=None, docker_load=None, docker_file=None, docker_import=None, docker_image_id=None, docker_output_directory=None, extra=<factory>)¶
DockerRequirement helper.
- __init__(docker_pull=None, docker_load=None, docker_file=None, docker_import=None, docker_image_id=None, docker_output_directory=None, extra=<factory>)¶
- class sophios.apis.python.tool_builder.EnvironmentDef(env_name, env_value)¶
An EnvVarRequirement entry.
- __init__(env_name, env_value)¶
- class sophios.apis.python.tool_builder.EnvVarRequirement(env_def, extra=<factory>)¶
EnvVarRequirement helper.
- __init__(env_def, extra=<factory>)¶
- class sophios.apis.python.tool_builder.FieldSpec(type_, *, name=None, label=None, doc=None, default=<object object>, extra=None)¶
A record field definition.
- __init__(type_, *, name=None, label=None, doc=None, default=<object object>, extra=None)¶
- class sophios.apis.python.tool_builder.InitialWorkDirRequirement(listing, extra=<factory>)¶
InitialWorkDirRequirement helper.
- __init__(listing, extra=<factory>)¶
- class sophios.apis.python.tool_builder.InlineJavascriptRequirement(expression_lib=None, extra=<factory>)¶
InlineJavascriptRequirement helper.
- __init__(expression_lib=None, extra=<factory>)¶
- class sophios.apis.python.tool_builder.InplaceUpdateRequirement(inplace_update=True, extra=<factory>)¶
InplaceUpdateRequirement helper.
- __init__(inplace_update=True, extra=<factory>)¶
- class sophios.apis.python.tool_builder.InputSpec(type_, *, position=None, flag=None, required=True, separate=None, item_separator=None, value_from=None, shell_quote=None, label=None, doc=None, format=None, secondary_files=None, streamable=None, load_contents=None, load_listing=None, default=<object object>, binding_extra=None, extra=None, name=None)¶
A CWL CommandLineTool input.
- __init__(type_, *, position=None, flag=None, required=True, separate=None, item_separator=None, value_from=None, shell_quote=None, label=None, doc=None, format=None, secondary_files=None, streamable=None, load_contents=None, load_listing=None, default=<object object>, binding_extra=None, extra=None, name=None)¶
- class sophios.apis.python.tool_builder.Inputs(**specs)¶
Named CLT inputs. Names come from Python keyword arguments.
- class sophios.apis.python.tool_builder.LoadListingRequirement(load_listing, extra=<factory>)¶
LoadListingRequirement helper.
- __init__(load_listing, extra=<factory>)¶
- class sophios.apis.python.tool_builder.NetworkAccess(network_access, extra=<factory>)¶
NetworkAccess helper.
- __init__(network_access, extra=<factory>)¶
- sophios.apis.python.tool_builder.Output¶
alias of
OutputSpec
- class sophios.apis.python.tool_builder.OutputSpec(type_, *, glob=None, from_input=None, required=True, load_contents=None, output_eval=None, label=None, doc=None, format=None, secondary_files=None, streamable=None, load_listing=None, binding_extra=None, extra=None, name=None)¶
A CWL CommandLineTool output.
- __init__(type_, *, glob=None, from_input=None, required=True, load_contents=None, output_eval=None, label=None, doc=None, format=None, secondary_files=None, streamable=None, load_listing=None, binding_extra=None, extra=None, name=None)¶
- classmethod array(items, **kwargs)¶
- Return type:
- classmethod enum(*symbols, name=None, **kwargs)¶
- Return type:
- classmethod record(fields, *, name=None, **kwargs)¶
- Return type:
- classmethod stdout(**kwargs)¶
- Return type:
- classmethod stderr(**kwargs)¶
- Return type:
- named(name)¶
- Return type:
- label(text)¶
- Return type:
- doc(text)¶
- Return type:
- format(value)¶
- Return type:
- secondary_files(*values)¶
- Return type:
- streamable(value)¶
- Return type:
- load_listing(value)¶
- Return type:
- load_contents(value)¶
- Return type:
- class sophios.apis.python.tool_builder.Outputs(**specs)¶
Named CLT outputs. Names come from Python keyword arguments.
- class sophios.apis.python.tool_builder.ResourceRequirement(cores_min=None, cores_max=None, ram_min=None, ram_max=None, tmpdir_min=None, tmpdir_max=None, outdir_min=None, outdir_max=None, extra=<factory>)¶
ResourceRequirement helper.
- __init__(cores_min=None, cores_max=None, ram_min=None, ram_max=None, tmpdir_min=None, tmpdir_max=None, outdir_min=None, outdir_max=None, extra=<factory>)¶
- class sophios.apis.python.tool_builder.SchemaDefRequirement(types, extra=<factory>)¶
SchemaDefRequirement helper.
- __init__(types, extra=<factory>)¶
- class sophios.apis.python.tool_builder.SecondaryFile(pattern, required=None, extra=<factory>)¶
A CWL secondary file pattern.
- __init__(pattern, required=None, extra=<factory>)¶
- class sophios.apis.python.tool_builder.ShellCommandRequirement(extra=<factory>)¶
ShellCommandRequirement helper.
- __init__(extra=<factory>)¶
- class sophios.apis.python.tool_builder.SoftwarePackage(package, version=None, specs=None, extra=<factory>)¶
A SoftwareRequirement package entry.
- __init__(package, version=None, specs=None, extra=<factory>)¶
- class sophios.apis.python.tool_builder.SoftwareRequirement(packages, extra=<factory>)¶
SoftwareRequirement helper.
- __init__(packages, extra=<factory>)¶
- class sophios.apis.python.tool_builder.ToolTimeLimit(timelimit, extra=<factory>)¶
ToolTimeLimit helper.
- __init__(timelimit, extra=<factory>)¶
- class sophios.apis.python.tool_builder.ValidationResult(path, uri, process)¶
Result of validating a generated CLT with cwltool/schema-salad.
- __init__(path, uri, process)¶
- class sophios.apis.python.tool_builder.WorkReuse(enable_reuse, extra=<factory>)¶
WorkReuse helper.
- __init__(enable_reuse, extra=<factory>)¶
- sophios.apis.python.tool_builder.array_type(items)¶
Return a CWL array type expression.
- sophios.apis.python.tool_builder.enum_type(*symbols, name=None)¶
Return a CWL enum type expression.
- sophios.apis.python.tool_builder.record_field(type_, **kwargs)¶
Return a named CWL record field helper.
- Return type:
- sophios.apis.python.tool_builder.record_type(fields, *, name=None)¶
Return a CWL record type expression.
- sophios.apis.python.tool_builder.secondary_file(pattern, *, required=None, **extra)¶
Create a secondary file specification.
- Return type:
- sophios.apis.python.tool_builder.step_from_command_line_tool(tool, *, step_name=None, run_path=None, config=None, tool_registry=None)¶
Convert a built CLT into a workflow Step entirely in memory.
- Parameters:
tool (CommandLineTool) – Built CLT to wrap as a workflow step.
step_name (str | None) – Optional workflow step name override.
run_path (str | Path | None) – Optional virtual .cwl path for compiler bookkeeping.
config (dict[str, Any] | None) – Optional input values to pre-bind.
tool_registry (Tools | None) – Optional tool registry retained on the step.
- Returns:
A workflow step backed by the CLT without touching disk.
- Return type:
- sophios.apis.python.tool_builder.validate_cwl_document(document, *, filename='tool.cwl', skip_schemas=False)¶
Validate a generated CLT document through cwltool/schema-salad.
- Return type:
sophios.compute_payload¶
Schema-backed compute-slurm payload objects.
- class sophios.compute_payload.ComputeConfig(toil=None, output=None, slurm=None)¶
Schema mirror for computeConfig.
-
toil:
Optional[ToilConfig]¶
-
output:
Optional[OutputConfig]¶
-
slurm:
Optional[SlurmConfig]¶
- to_dict()¶
Render nested compute configuration.
- Returns:
JSON-ready computeConfig.
- Return type:
Json
- __init__(toil=None, output=None, slurm=None)¶
-
toil:
- exception sophios.compute_payload.ComputePayloadValidationError¶
Raised when a compute payload does not match the checked-in schema.
- class sophios.compute_payload.ComputeWorkflowPayload(cwl_workflow, cwl_job_inputs, workflow_id=None, jobs=<factory>, compute_config=None)¶
Schema-backed compute-slurm request payload.
-
compute_config:
Optional[ComputeConfig]¶
- get_compute_payload()¶
Render and validate the compute request payload.
- Raises:
ComputePayloadValidationError – If the rendered payload is invalid.
- Returns:
Schema-valid compute payload.
- Return type:
Json
- __init__(cwl_workflow, cwl_job_inputs, workflow_id=None, jobs=<factory>, compute_config=None)¶
-
compute_config:
- class sophios.compute_payload.OutputConfig(mode=None, output_dir=None)¶
Schema mirror for computeConfig.outputConfig.
- classmethod service_default()¶
Use the service-managed output directory.
- Returns:
Service-default output configuration.
- Return type:
- classmethod workflow_declared()¶
Preserve the workflow’s own output behavior.
- Returns:
Workflow-declared output configuration.
- Return type:
- classmethod user_specified(output_dir)¶
Use a caller-provided output directory.
- Parameters:
output_dir (str | Path) – Directory that compute-slurm should use.
- Returns:
User-specified output configuration.
- Return type:
- classmethod from_json(*, mode=None, outputDir=None)¶
Construct from schema-shaped JSON field names.
- Parameters:
- Returns:
Output configuration using JSON/schema naming.
- Return type:
- to_dict()¶
Render the output configuration.
- Raises:
ValueError – If mode=’userSpecified’ is missing output_dir.
- Returns:
JSON-ready output configuration.
- Return type:
Json
- __init__(mode=None, output_dir=None)¶
- class sophios.compute_payload.SlurmConfig(job_name=None, partition=None, slurm_job_gpu_count=None, cpus_per_task=None, nodes=None, tasks_per_node=None, output=None, error=None, time_limit=None, memory=None)¶
Schema mirror for computeConfig.slurmConfig.
- to_dict()¶
Render the SLURM configuration.
- Returns:
JSON-ready SLURM configuration.
- Return type:
Json
- __init__(job_name=None, partition=None, slurm_job_gpu_count=None, cpus_per_task=None, nodes=None, tasks_per_node=None, output=None, error=None, time_limit=None, memory=None)¶
- class sophios.compute_payload.ToilConfig(log_level=None)¶
Schema mirror for computeConfig.toilConfig.
- to_dict()¶
Render the toil configuration.
- Returns:
JSON-ready toil configuration.
- Return type:
Json
- __init__(log_level=None)¶
- sophios.compute_payload.validate_compute_payload(payload)¶
Validate a compute payload mapping against the checked-in schema.
- Parameters:
payload (Mapping[str, Any]) – Candidate compute payload.
- Raises:
ComputePayloadValidationError – If the payload is invalid.
- Returns:
Schema-valid compute payload.
- Return type:
Json
sophios.compute_submit¶
- sophios.compute_submit.submit_compute_json(payload_json, submit_url, *, timeout=(5, 30), poll_interval_seconds=15, log_path=None)¶
Submit an already-rendered compute payload JSON object.
- Return type: