cwl-utils: Common Workflow Language Utilities

0.41 · active · verified Thu Apr 16

cwl-utils is a Python library providing utilities and autogenerated classes for loading, manipulating, and parsing Common Workflow Language (CWL) v1.0, v1.1, and v1.2 documents. It is the reference implementation of CWL, offering comprehensive validation and various tools for working with CWL files. The library is actively maintained with frequent releases, typically several times a year.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to programmatically load a CWL CommandLineTool document using `cwl-utils` from a local file. It creates a simple 'hello_world.cwl' file, loads it using `load_document_by_uri`, and then prints some attributes of the parsed CWL object. The example also includes cleanup for the created file.

from pathlib import Path
from cwl_utils.parser import load_document_by_uri

# Create a dummy CWL file for the example
cwl_content = """
cwlVersion: v1.2
class: CommandLineTool
baseCommand: echo
inputs:
  message:
    type: string
    default: "Hello World from cwl-utils!"
    inputBinding:
      position: 1
outputs:
  output:
    type: stdout
"""

cwl_file_path = Path("hello_world.cwl")
cwl_file_path.write_text(cwl_content)

try:
    # Load the CWL object from the file URI
    # Note: For local files, str(Path_object) is often needed for older APIs
    cwl_obj = load_document_by_uri(str(cwl_file_path))

    print(f"Successfully loaded CWL Tool ID: {cwl_obj.id}")
    print(f"CWL Version: {cwl_obj.cwlVersion}")
    if hasattr(cwl_obj, 'inputs') and cwl_obj.inputs:
        print(f"First input message default: {cwl_obj.inputs[0].default}")

except Exception as e:
    print(f"An error occurred: {e}")
finally:
    # Clean up the dummy file
    if cwl_file_path.exists():
        cwl_file_path.unlink()

view raw JSON →