py-tes 🐍

Build Status Test Coverage License PyPI

py-tes is a library for interacting with servers implementing the GA4GH Task Execution Schema.

Quick Start ⚡

TES version

py-tes version

Example Notebook (Coming soon!)

1.1

1.1.0

Open in Colab

1.0

1.0.0

Open in Colab

Installation 🌀

Install py-tes from PyPI and run it in your script:

➜ pip install py-tes

➜ python example.py

Example

import tes
import json

# Define task
task = tes.Task(
    executors=[
        tes.Executor(
            image="alpine",
            command=["echo", "hello"]
        )
    ]
)

# Create client
cli = tes.HTTPClient("http://localhost:8000", timeout=5)

# Create and run task
task_id = cli.create_task(task)
cli.wait(task_id, timeout=5)

# Fetch task info
task_info = cli.get_task(task_id, view="BASIC")
j = json.loads(task_info.as_json())

# Pretty print task info
print(json.dumps(j, indent=2))

How to…

> The following examples make use of the objects above.

…export a model to a dictionary

task_dict = task.as_dict(drop_empty=False)

task_dict contents:

{
    "id": null,
    "state": null,
    ...
}

…export a model to JSON

task_json = task.as_json()  # also accepts `drop_empty` arg

task_json contents:

{"executors": [{"image": "alpine", "command": ["echo", "hello"]}]}

…pretty print a model

print(task.as_json(indent=3))  # keyword args are passed to `json.dumps()`

Output:

{
    "executors": [
        {
            "image": "alpine",
            "command": ["echo", "hello"]
        }
    ]
}

…access a specific task from the task list

specific_task = tasks_list.tasks[5]

specific_task contents:

Task(id='393K43', state='COMPLETE', ...)

…iterate over task list items

for t in tasks_list[:3]:
    print(t.as_json(indent=3))

Output:

{
    "id": "task_A2GFS4",
    "state": "RUNNING"
}
...

…instantiate a model from a JSON representation

task_from_json = tes.client.unmarshal(task_json, tes.Task)

task_from_json contents:

Task(id=None, state=None, ...)

Which is equivalent to task:

print(task_from_json == task)

Output:

True

Additional Resources 📚

  • ga4gh-tes : C# implementation of the GA4GH TES API; provides distributed batch task execution on Microsoft Azure

  • cwl-tes : Submits tasks to a TES server.

  • Funnel : Toolkit for distributed task execution with a simple API.

  • Snakemake : Workflow management system.

  • Nextflow : Scalable and reproducible workflows using containers.

  • GA4GH TES : Standardized schema and API for batch execution tasks.

  • TES GitHub

  • Awesome TES : A curated list of TES projects.