Taskflow

6.2.0 · active · verified Thu Apr 16

Taskflow is a Python 3.10+ library for structured state management, task orchestration, and error handling in complex asynchronous workflows. It enables defining tasks and flows using decorators or classes, facilitating robust and scalable application development. The current version is 6.2.0, with an active development cadence that includes significant API changes in major releases.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates defining and executing a simple asynchronous task and flow using Taskflow's decorator API. It showcases the basic structure for creating a workflow and running it with asyncio.

import asyncio
from taskflow import task, flow

@task
async def greet_task(name: str) -> str:
    """A simple task that greets a given name."""
    print(f"Task received: {name}")
    return f"Hello, {name}!"

@flow
async def greeting_flow(input_name: str) -> str:
    """A flow that orchestrates the greeting task."""
    # Inputs/outputs are now dictionaries in v6+
    greeting_message = await greet_task(input_name)
    print(f"Flow processed: {greeting_message}")
    return f"Flow finished with: {greeting_message}"

async def main():
    name_to_greet = "World"
    final_output = await greeting_flow(name_to_greet)
    print(f"Final output from flow: {final_output}")

if __name__ == "__main__":
    asyncio.run(main())

view raw JSON →