Available in latch >= 2.62.0
The Latch SDK provides a Python API to programmatically launch workflows and monitor their status. This is useful for integrating workflows into automated test suites (e.g., GitHub CI/CD). There are two ways to launch a workflow programmatically:
  1. Call the workflow with Python parameter values.
  2. Use a LaunchPlan from a previously registered workflow.

Pre-requisites

  • Please make sure you have registered your workflow to Latch using latch register. This creates a new workflow version, which you will reference in your script.

Usage

from latch.types.file import LatchFile
from latch_cli.services.launch.launch_v2 import launch

# Import workflow parameter types from the original location in which it was
# defined. Else the `launch` command will fail validation. 
from wf.entrypoint import GenomeReference, Sample 

# Using python parameter values
execution_id = launch(
    wf_name="my_workflow",
    version="0.1.0",
    params={
        "input": [
            Sample(
                patient="TestSample",
                fastq_1=LatchFile(
                    "latch:///test_L1_1.fastq.gz"
                ),
                ...
            ),
            ...
        ],
        "genome": GenomeReference.GATK_GRCh37,
        ...
    }
)
Parameters:
  • wf_name: Name of the workflow function. This is the function defined immediately after the @workflow decorator in your code (Example)
  • version: Workflow version registered on Latch
  • params: The Python types passed here must exactly match the types used in the workflow function signature. Even if two types have the same structure, validation will fail if they come from different modules.
    Best practice: Import the types directly from the file where they were originally defined. For example, in Nextflow workflows, types are often defined in wf.entrypoint; import them from there as shown in the example above.
Important note on Python version: The Python version in the Docker image used during workflow registration must match the Python version running the script that calls launch or launch_from_launch_plan.