cwltool

3.2.20260411152607 · active · verified Wed Apr 15

cwltool is the reference implementation for the Common Workflow Language (CWL), enabling users to parse, validate, and execute CWL workflows and command-line tools. It supports various execution environments, including Docker and Singularity. The current version is 3.2.20260411152607, and it maintains a rapid, date-based release cadence, with version numbers reflecting both CWL specification and release date.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to programmatically load and validate a Common Workflow Language (CWL) CommandLineTool definition using `cwltool.load_tool`. This is the primary method for parsing CWL documents into Python objects for inspection or further processing.

import os
from cwltool.load_tool import load_tool
from cwltool.context import LoadingContext

# 1. Define a simple CWL CommandLineTool
cwl_content = """
cwlVersion: v1.0
class: CommandLineTool
id: my_echo_tool
baseCommand: echo
inputs:
  message:
    type: string
    inputBinding:
      position: 1
outputs:
  output_message:
    type: stdout
stdout: output.txt
"""

# 2. Save it to a temporary file
cwl_file_path = "simple_echo.cwl"
with open(cwl_file_path, "w") as f:
    f.write(cwl_content)

try:
    # 3. Load and validate the CWL document
    # A LoadingContext is often required for proper resolution of includes/imports
    # and setting the base URI.
    loadingContext = LoadingContext({"$base": os.path.abspath(os.path.dirname(cwl_file_path))})
    loadingContext.fileuri = f"file://{os.path.abspath(cwl_file_path)}"
    
    # load_tool returns a Process object (CommandLineTool, Workflow, or ExpressionTool)
    tool = load_tool(cwl_file_path, loadingContext)

    print(f"Successfully loaded and validated CWL tool: {tool.tool_id}")
    print(f"Tool class: {tool.class_}")
    print(f"Inputs: {[i.id for i in tool.inputs]}")
    print(f"Outputs: {[o.id for o in tool.outputs]}")

    # To actually *run* it, you would typically use cwltool.main.main
    # or a custom executor with an input object.
    # The `load_tool` function is primarily for parsing and validation.

except Exception as e:
    print(f"Error loading CWL tool: {e}")
finally:
    # Clean up the temporary file
    if os.path.exists(cwl_file_path):
        os.remove(cwl_file_path)

view raw JSON →