by common-workflow-language

common-workflow-language / cwltool

Common Workflow Language reference implementation

224 Stars 157 Forks Last release: 3 months ago (3.0.20200720165847) Apache License 2.0 4.0K Commits 164 Releases

Available items

No Items, yet!

The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:


Common Workflow Language tool description reference implementation

|Linux Status| |Windows Status| |Coverage Status| |Downloads|

.. |Linux Status| image:: :target:

.. |Windows Status| image:: :target:

.. |Coverage Status| image:: :target:

.. |Downloads| image:: :target:

This is the reference implementation of the Common Workflow Language. It is intended to be feature complete and provide comprehensive validation of CWL files as well as provide other tools related to working with CWL.

This is written and tested for

3.x {x = 6, 7, 8}

The reference implementation consists of two packages. The

package is the primary Python module containing the reference implementation in the
module and console executable by the same name.


package is optional and provides an additional entry point under the alias
, which is the implementation-agnostic name for the default CWL interpreter installed on a host.

is provided by the CWL project,
a member project of Software Freedom Conservancy 
_ and our
many contributors 


Your operating system may offer cwltool directly. For

_ or
_ try

.. code:: bash

apt-get install cwltool

For MacOS X, other UNIXes or Windows packages prepared by the conda-forge project. Please follow instructions of conda-forge ( for its installation, then perform:

.. code:: bash

conda install -c conda-forge cwltool

Under the hood, conda setups virtual environments before installing

to avoid conflicting versions of the same library. When installing cwltool directly, it is recommended to do the same manually:

.. code:: bash

virtualenv -p python3 venv # Create a virtual environment source venv/bin/activate # Activate environment before installing


Installing the official package from PyPi (will install "cwltool" package as well)

.. code:: bash

pip install cwlref-runner

If installing alongside another CWL implementation then

.. code:: bash

pip install cwltool

Or you can install from source:

.. code:: bash

git clone # clone cwltool repo cd cwltool # Switch to source directory pip install . # Install

from source cwltool --version # Check if the installation works correctly

Remember, if co-installing multiple CWL implementations then you need to maintain which implementation

points to via a symbolic file system link or
another facility 

You may also want to have the following installed: node.js Docker, udocker, or Singularity (optional)

Without these, some examples in the CWL tutorials at may not work.

Run on the command line

Simple command::

cwl-runner [tool-or-workflow-description] [input-job-settings]

Or if you have multiple CWL implementations installed and you want to override the default cwl-runner use::

cwltool [tool-or-workflow-description] [input-job-settings]

You can set cwltool options in the environment with CWLTOOL_OPTIONS, these will be inserted at the beginning of the command line::

export CWLTOOL_OPTIONS="--debug"

Use with boot2docker

boot2docker runs Docker inside a virtual machine and it only mounts

on it. The default behavior of CWL is to create temporary directories under e.g.
which is not accessible to Docker containers.

To run CWL successfully with boot2docker you need to set the

to somewhere under
$ cwl-runner --tmp-outdir-prefix=/Users/username/project --tmpdir-prefix=/Users/username/project wc-tool.cwl wc-job.json

Using user-space replacements for Docker

Some shared computing environments don't support Docker software containers for technical or policy reasons. As a work around, the CWL reference runner supports using alternative

implementations on Linux with the

One such "user space" friendly docker replacement is


udocker installation:


just as you normally would, but with the new option, e.g. from the conformance tests:

.. code:: bash

cwltool --user-space-docker-cmd=udocker

can use
_ version 2.6.1 or later as a Docker container runtime.
with Singularity will run software containers specified in
and therefore works with Docker images only, native Singularity images are not supported. To use Singularity as the Docker container runtime, provide
command line option to
. With Singularity,
can pass all CWL v1.0 conformance tests, except those involving Docker container ENTRYPOINTs.

.. code:: bash

cwltool --singularity

Running a tool or workflow from remote or local locations

can run tool and workflow descriptions on both local and remote systems via its support for HTTP[S] URLs.

Input job files and Workflow steps (via the

directive) can reference CWL documents using absolute or relative local filesytem paths. If a relative path is referenced and that document isn't found in the current directory then the following locations will be searched:

You can also use

to manage dependencies on external tools and workflows.

Overriding workflow requirements at load time

Sometimes a workflow needs additional requirements to run in a particular environment or with a particular dataset. To avoid the need to modify the underlying workflow, cwltool supports requirement "overrides".

The format of the "overrides" object is a mapping of item identifier (workflow, workflow step, or command line tool) to the process requirements that should be applied.

.. code:: yaml

cwltool:overrides: echo.cwl: requirements: EnvVarRequirement: envDef: MESSAGE: override_value

Overrides can be specified either on the command line, or as part of the job input document. Workflow steps are identified using the name of the workflow file followed by the step name as a document fragment identifier "#id". Override identifiers are relative to the toplevel workflow document.

.. code:: bash

cwltool --overrides overrides.yml my-tool.cwl my-job.yml

.. code:: yaml

inputparameter1: value1 inputparameter2: value2 cwltool:overrides: workflow.cwl#step1: requirements: EnvVarRequirement: envDef: MESSAGE: override_value

.. code:: bash

cwltool my-tool.cwl my-job-with-overrides.yml

Combining parts of a workflow into a single document


to combine a workflow made up of multiple files into a single compound document. This operation takes all the CWL files referenced by a workflow and builds a new CWL document with all Process objects (CommandLineTool and Workflow) in a list in the
field. Cross references (such as
fields) are updated to internal references within the new packed document. The top level workflow is named

.. code:: bash

cwltool --pack my-wf.cwl > my-packed-wf.cwl

Running only part of a workflow

You can run a partial workflow with the

) option. This takes the name of an output parameter, workflow step, or input parameter in the top level workflow. You may provide multiple targets.

.. code:: bash

cwltool --target step3 my-wf.cwl

If a target is an output parameter, it will only run only the steps that contribute to that output. If a target is a workflow step, it will run the workflow starting from that step. If a target is an input parameter, it will only run only the steps that are connected to that input.


to get a listing of the targets of a workflow. To see exactly which steps will run, use
to get a printout of the workflow subgraph for the selected targets.

.. code:: bash

cwltool --print-targets my-wf.cwl

cwltool --target step3 --print-subgraph my-wf.cwl > my-wf-starting-from-step3.cwl

Visualizing a CWL document


option will print a file suitable for Graphviz
program. Here is a bash onliner to generate a Scalable Vector Graphic (SVG) file:

.. code:: bash

cwltool --print-dot my-wf.cwl | dot -Tsvg > my-wf.svg

Modeling a CWL document as RDF

CWL documents can be expressed as RDF triple graphs.

.. code:: bash

cwltool --print-rdf --rdf-serializer=turtle mywf.cwl

Leveraging SoftwareRequirements (Beta)

CWL tools may be decorated with

hints that cwltool may in turn use to resolve to packages in various package managers or dependency management systems such as
Environment Modules


hints using cwltool requires an optional dependency, for this reason be sure to use specify the
modifier when installing cwltool. For instance::

$ pip install 'cwltool[deps]'

Installing cwltool in this fashion enables several new command line options. The most general of these options is

. This option allows one to specify a dependency resolver's configuration file. This file may be specified as either XML or YAML and very simply describes various plugins to enable to "resolve"

To discuss some of these plugins and how to configure them, first consider the following

definition for an example CWL tool.

.. code:: yaml

SoftwareRequirement: packages: - package: seqtk version: - r93

Now imagine deploying cwltool on a cluster with Software Modules installed and that a

module is available at version
. This means cluster users likely won't have the binary
on their
by default, but after sourcing this module with the command
modulecmd sh load seqtk/r93
is available on the
. A simple dependency resolvers configuration file, called
for instance, that would enable cwltool to source the correct module environment before executing the above tool would simply be:

.. code:: yaml

  • type: modules

The outer list indicates that one plugin is being enabled, the plugin parameters are defined as a dictionary for this one list item. There is only one required parameter for the plugin above, this is

and defines the plugin type. This parameter is required for all plugins. The available plugins and the parameters available for each are documented (incompletely)
__. Unfortunately, this documentation is in the context of Galaxy tool
s instead of CWL
s, but the concepts map fairly directly.

cwltool is distributed with an example of such seqtk tool and sample corresponding job. It could executed from the cwltool root using a dependency resolvers configuration file such as the above one using the command::

cwltool --beta-dependency-resolvers-configuration /path/to/dependency-resolvers-conf.yml \ tests/seqtkseq.cwl \ tests/seqtkseq_job.json

This example demonstrates both that cwltool can leverage existing software installations and also handle workflows with dependencies on different versions of the same software and libraries. However the above example does require an existing module setup so it is impossible to test this example "out of the box" with cwltool. For a more isolated test that demonstrates all the same concepts - the resolver plugin type

can be used.

"Galaxy packages" are a lighter weight alternative to Environment Modules that are really just defined by a way to lay out directories into packages and versions to find little scripts that are sourced to modify the environment. They have been used for years in Galaxy community to adapt Galaxy tools to cluster environments but require neither knowledge of Galaxy nor any special tools to setup. These should work just fine for CWL tools.

The cwltool source code repository's test directory is setup with a very simple directory that defines a set of "Galaxy packages" (but really just defines one package named

). The directory layout is simply::

tests/testdepsenv/ random-lines/ 1.0/

If the

plugin is enabled and pointed at the
directory in cwltool's root and a
such as the following is encountered.

.. code:: yaml

hints: SoftwareRequirement: packages: - package: 'random-lines' version: - '1.0'

Then cwltool will simply find that
file and source it before executing the corresponding tool. That
script is only responsible for modifying the job's
to add the required binaries.

This is a full example that works since resolving "Galaxy packages" has no external requirements. Try it out by executing the following command from cwltool's root directory::

cwltool --beta-dependency-resolvers-configuration tests/testdepsenvresolversconf.yml \ tests/randomlines.cwl \ tests/randomlines_job.json

The resolvers configuration file in the above example was simply:

.. code:: yaml

  • type: galaxypackages basepath: ./tests/testdepsenv

It is possible that the

s in a given CWL tool will not match the module names for a given cluster. Such requirements can be re-mapped to specific deployed packages and/or versions using another file specified using the resolver plugin parameter
. We will demonstrate this using
but the concepts apply equally well to Environment Modules or Conda packages (described below) for instance.

So consider the resolvers configuration file (


.. code:: yaml

  • type: galaxypackages basepath: ./tests/testdepsenv mappingfiles: ./tests/testdeps_mapping.yml

And the corresponding mapping configuraiton file (


.. code:: yaml

  • from: name: randomLines version: 1.0.0-rc1 to: name: random-lines version: '1.0'

This is saying if cwltool encounters a requirement of

at version
in a tool, to rewrite to our specific plugin as
at version
. cwltool has such a test tool called
that contains such a source
. To try out this example with mapping, execute the following command from the cwltool root directory::

cwltool --beta-dependency-resolvers-configuration tests/testdepsenvresolversconfrewrite.yml \ tests/randomlinesmapping.cwl \ tests/randomlines_job.json

The previous examples demonstrated leveraging existing infrastructure to provide requirements for CWL tools. If instead a real package manager is used cwltool has the opportunity to install requirements as needed. While initial support for Homebrew/Linuxbrew plugins is available, the most developed such plugin is for the

__ package manager. Conda has the nice properties of allowing multiple versions of a package to be installed simultaneously, not requiring evaluated permissions to install Conda itself or packages using Conda, and being cross platform. For these reasons, cwltool may run as a normal user, install its own Conda environment and manage multiple versions of Conda packages on both Linux and Mac OS X.

The Conda plugin can be endlessly configured, but a sensible set of defaults that has proven a powerful stack for dependency management within the Galaxy tool development ecosystem can be enabled by simply passing cwltool the


With this we can use the seqtk example above without Docker and without any externally managed services - cwltool should install everything it needs and create an environment for the tool. Try it out with the follwing command::

cwltool --beta-conda-dependencies tests/seqtkseq.cwl tests/seqtkseq_job.json

The CWL specification allows URIs to be attached to

s that allow disambiguation of package names. If the mapping files described above allow deployers to adapt tools to their infrastructure, this mechanism allows tools to adapt their requirements to multiple package managers. To demonstrate this within the context of the seqtk, we can simply break the package name we use and then specify a specific Conda package as follows:

.. code:: yaml

hints: SoftwareRequirement: packages: - package: seqtk_seq version: - '1.2' specs: - -

The example can be executed using the command::

cwltool --beta-conda-dependencies tests/seqtkseqwrongname.cwl tests/seqtkseq_job.json

The plugin framework for managing resolution of these software requirements as maintained as part of

__ - a small, portable subset of the Galaxy project. More information on configuration and implementation can be found at the following links:
  • Dependency Resolvers in Galaxy 
  • Conda for [Galaxy] Tool Dependencies 
  • Mapping Files - Implementation 
  • Specifications - Implementation 
  • Initial cwltool Integration Pull Request 

Use with GA4GH Tool Registry API

Cwltool can launch tools directly from

GA4GH Tool Registry API
_ endpoints.

By default, cwltool searches . Use

to add other registries to the search path.

For example ::

cwltool test.json

and (defaults to latest when a version is not specified) ::

cwltool test.json

For this example, grab the test.json (and input file) from ::

wget wget

.. _

GA4GH Tool Registry API

Running MPI-based tools that need to be launched

Cwltool supports an extension to the CWL spec
. When the tool definition has this in its
section, and cwltool has been run with
, then the tool's command line will be extended with the commands needed to launch it with
or similar. You can specify the number of processes to start as either a literal integer or an expression (that will result in an integer). For example::

#!/usr/bin/env cwl-runner cwlVersion: v1.1 class: CommandLineTool $namespaces: cwltool: "" requirements: cwltool:MPIRequirement: processes: $(inputs.nproc) inputs: nproc: type: int

Interaction with containers: the MPIRequirement currently prepends its commands to the front of the command line that is constructed. If you wish to run a containerised application in parallel, for simple use cases this does work with Singularity, depending upon the platform setup. However this combination should be considered "alpha" -- please do report any issues you have! This does not work with Docker at the moment. (More precisely, you get

copies of the same single process image run at the same time that cannot communicate with each other.)

The host-specific parameters are configured in a simple YAML file (specified with the

flag). The allowed keys are given in the following table; all are optional.

+----------------+------------------+----------+------------------------------+ | Key | Type | Default | Description | +================+==================+==========+==============================+ | runner | str | "mpirun" | The primary command to use. | +----------------+------------------+----------+------------------------------+ | nprocflag | str | "-n" | Flag to set number of | | | | | processes to start. | +----------------+------------------+----------+------------------------------+ | defaultnproc | int | 1 | Default number of processes. | +----------------+------------------+----------+------------------------------+ | extraflags | List[str] | [] | A list of any other flags to | | | | | be added to the runner's | | | | | command line before | | | | | the

. | +----------------+------------------+----------+------------------------------+ | envpass | List[str] | [] | A list of environment | | | | | variables that should be | | | | | passed from the host | | | | | environment through to the | | | | | tool (e.g. giving the | | | | | nodelist as set by your | | | | | scheduler). | +----------------+------------------+----------+------------------------------+ | envpassregex | List[str] | [] | A list of python regular | | | | | expressions that will be | | | | | matched against the host's | | | | | environment. Those that match| | | | | will be passed through. | +----------------+------------------+----------+------------------------------+ | env_set | Mapping[str,str] | {} | A dictionary whose keys are | | | | | the environment variables set| | | | | and the values being the | | | | | values. | +----------------+------------------+----------+------------------------------+



Running tests locally

  • Running basic tests

To run the basic tests after installing

execute the following:

.. code:: bash

pip install -rtest-requirements.txt py.test --ignore cwltool/schemas/ --pyarg cwltool

To run various tests in all supported Python environments we use

_. To run the test suite in all supported Python environments first downloading the complete code repository (see the
git clone
instructions above) and then run the following in the terminal:
pip install tox; tox

List of all environment can be seen using:

tox --listenvs
and running a specfic test env using:
tox -e 
and additionally run a specific test using this format:
tox -e py36-unit -- tests/
  • Running the entire suite of CWL conformance tests:

The GitHub repository for the CWL specifications contains a script that tests a CWL implementation against a wide array of valid CWL files using the

_ program

Instructions for running these tests can be found in the Common Workflow Language Specification repository at

Import as a module


.. code:: python

import cwltool

to your script.

The easiest way to use cwltool to run a tool or workflow from Python is to use a Factory

.. code:: python

import cwltool.factory fac = cwltool.factory.Factory()

echo = fac.make("echo.cwl") result = echo(inp="foo")

# result["out"] == "foo"

CWL Tool Control Flow

Technical outline of how cwltool works internally, for maintainers.

. Use CWL
to load document.

#. Fetches the document from file or URL #. Applies preprocessing (syntax/identifier expansion and normalization) #. Validates the document based on cwlVersion #. If necessary, updates the document to latest spec #. Constructs a Process object using

callback.  This yields a
      CommandLineTool, Workflow, or ExpressionTool.  For workflows, this
      recursively constructs each workflow step.
   #. To construct custom types for CommandLineTool, Workflow, or
      ExpressionTool, provide a custom

. Iterate on the
method of the Process object to get back runnable jobs.


is a generator method (uses the Python iterator protocol) #. Each time the
method is invoked in an iteration, it returns one of: a runnable item (an object with a
(indicating there is currently no work ready to run) or end of iteration (indicating the process is complete.) #. Invoke the runnable item by calling
. This runs the tool and gets output. #. Output of a process is reported by an output callback. #.
may be iterated over multiple times. It will yield all the work that is currently ready to run and then yield None.

objects create a corresponding
objects to hold the workflow state for the duration of the job invocation.

#. The WorkflowJob iterates over each WorkflowJobStep and determines if the inputs the step are ready. #. When a step is ready, it constructs an input object for that step and iterates on the

method of the workflow job step. #. Each runnable item is yielded back up to top level run loop #. When a step job completes and receives an output callback, the job outputs are assigned to the output of the workflow step. #. When all steps are complete, the intermediate files are moved to a final workflow output, intermediate directories are deleted, and the output callback for the workflow is called.

job() objects yield a single runnable object.

#. The CommandLineTool

method calls
to create a
object #. The job method configures the CommandLineJob object by setting public attributes #. The job method iterates over file and directories inputs to the CommandLineTool and creates a "path map". #. Files are mapped from their "resolved" location to a "target" path where they will appear at tool invocation (for example, a location inside a Docker container.) The target paths are used on the command line. #. Files are staged to targets paths using either Docker volume binds (when using containers) or symlinks (if not). This staging step enables files to be logically rearranged or renamed independent of their source layout. #. The
method of CommandLineJob executes the command line tool or Docker container, waits for it to complete, collects output, and makes the output callback.

Extension points

The following functions can be passed to main() to override or augment the listed behaviors.

executor ::

executor(tool, job_order_object, runtimeContext, logger)
  (Process, Dict[Text, Any], RuntimeContext) -> Tuple[Dict[Text, Any], Text]

An implementation of the toplevel workflow execution loop, should synchronously run a process object to completion and return the output object.

versionfunc ::

  () -> Text

Return version string.

logger_handler ::


Handler object for logging.

The following functions can be set in LoadingContext to override or augment the listed behaviors.

fetcher_constructor ::

fetcher_constructor(cache, session)
  (Dict[unicode, unicode], requests.sessions.Session) -> Fetcher

Construct a Fetcher object with the supplied cache and HTTP session.

resolver ::

resolver(document_loader, document)
  (Loader, Union[Text, dict[Text, Any]]) -> Text

Resolve a relative document identifier to an absolute one which can be fetched.

The following functions can be set in RuntimeContext to override or augment the listed behaviors.

constructtoolobject ::

construct_tool_object(toolpath_object, loadingContext)
  (MutableMapping[Text, Any], LoadingContext) -> Process

Hook to construct a Process object (eg CommandLineTool) object from a document.

select_resources ::

  (Dict[str, int], RuntimeContext) -> Dict[Text, int]

Take a resource request and turn it into a concrete resource assignment.

makefsaccess ::

  (Text) -> StdFsAccess

Return a file system access object.

In addition, when providing custom subclasses of Process objects, you can override the following methods:

CommandLineTool.makejobrunner ::

  (RuntimeContext) -> Type[JobBase]

Create and return a job runner object (this implements concrete execution of a command line tool).

Workflow.makeworkflowstep ::

make_workflow_step(toolpath_object, pos, loadingContext, parentworkflowProv)
  (Dict[Text, Any], int, LoadingContext, Optional[ProvenanceProfile]) -> WorkflowStep

Create and return a workflow step object.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.