Skip to main content

tedx-flow

A lightweight task flow orchestration library for Python.

Features

  • Zero Dependencies: Uses only Python standard library
  • Thread-Safe: Built-in synchronization for parallel execution
  • Simple API: Easy to define and chain tasks
  • Streaming Support: Real-time output as tasks complete
  • Dynamic Scheduling: Tasks can schedule next tasks at runtime
  • Parallel Execution: Independent tasks run concurrently

Installation

pip install tedx-flow

Quick Start

from concurrent.futures import ThreadPoolExecutor
from tedx_flow import Flow, Context, NextTask, TaskOutput

# Define tasks
def fetch_data(ctx: Context) -> TaskOutput:
    data = {"items": [1, 2, 3, 4, 5]}
    return TaskOutput(output=data, next_tasks=[NextTask("process")])

def process(ctx: Context) -> TaskOutput:
    data = ctx.get("fetch_data")
    result = sum(data["items"])
    return TaskOutput(output=result)

# Create and run flow
with ThreadPoolExecutor(max_workers=4) as executor:
    flow = Flow(executor)
    flow.add_task("fetch_data", fetch_data)
    flow.add_task("process", process)
    
    results = flow.run("fetch_data")
    print(results)  # {"process": 15}

Core Concepts

Task

A task is the basic unit of a flow. Each task:

  1. Receives a Context object (optionally with inputs)
  2. Returns a TaskOutput containing output value and optional next tasks
def my_task(ctx: Context, inputs: dict = None) -> TaskOutput:
    # Access previous task outputs
    previous_result = ctx.get("previous_task")
    
    # Access inputs passed via NextTask
    batch_size = inputs.get("batch_size", 10) if inputs else 10
    
    # Execute business logic
    result = do_something(previous_result, batch_size)
    
    # Return output and schedule next tasks
    return TaskOutput(
        output=result,
        next_tasks=[
            NextTask("next_task", inputs={"processed": True}),
            NextTask("parallel_task")  # Runs in parallel
        ]
    )

Context

Context is a shared data container between tasks:

  • ctx.set(key, value) - Store a value
  • ctx.get(key) - Get a value (blocks until available)
  • ctx.to_dict() - Export as dictionary

TaskOutput

# Terminal task (no next tasks)
TaskOutput(output="done")

# Chain to next task
TaskOutput(output=result, next_tasks=[NextTask("next_step")])

# Fan out to multiple tasks (parallel)
TaskOutput(output=result, next_tasks=[
    NextTask("branch_a"),
    NextTask("branch_b")
])

NextTask

# Simple scheduling
NextTask("task_name")

# With input parameters
NextTask("task_name", inputs={"key": "value"})

# Allow parallel instances of same task
NextTask("task_name", spawn_another=True)

Streaming

Get real-time results as tasks complete:

with ThreadPoolExecutor(max_workers=4) as executor:
    flow = Flow(executor)
    flow.add_task("task_a", task_a)
    flow.add_task("task_b", task_b)
    
    for chunk in flow.stream("task_a"):
        print(f"Task {chunk.task_id} completed: {chunk.value}")

Parallel Task Instances

Run multiple instances of the same task:

def fan_out(ctx: Context) -> TaskOutput:
    return TaskOutput(
        output="started",
        next_tasks=[
            NextTask("worker", inputs={"id": 1}, spawn_another=True),
            NextTask("worker", inputs={"id": 2}, spawn_another=True),
            NextTask("worker", inputs={"id": 3}, spawn_another=True),
        ]
    )

Error Handling

Exceptions in tasks are automatically propagated:

try:
    results = flow.run("start_task")
except Exception as e:
    print(f"Flow execution failed: {e}")

API Reference

Classes

Class Description
Flow Main orchestration engine
Context Shared state between tasks
TaskOutput Task return type
NextTask Specifies next task to run
StreamChunk Streaming output container
State Thread-safe value container

Flow Methods

Method Description
add_task(name, action) Register a task
run(start_task_id, inputs) Execute flow synchronously
stream(start_task_id, inputs) Execute with streaming output
get_context() Get flow context

Use Cases

  • Data Processing Pipelines: ETL, data cleaning, transformation
  • AI Workflows: Multi-step LLM calls, RAG pipelines
  • Batch Processing: Parallel sub-task processing
  • Business Processes: Order processing, approval workflows

License

MIT License

Metadata

Release files for tedx-flow 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tedx-flow 0.1.2
File Size Uploaded
tedx_flow-0.1.2.tar.gz 12.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tedx-flow 0.1.2
File Interpreter ABI Platform
tedx_flow-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 23.4 kB

Release files / tedx_flow-0.1.2.tar.gz

Download URL tedx_flow-0.1.2.tar.gz
Size 12.6 kB
Tags Source
SHA-256 checksum
How to use checksums
017ac8db6cbacd834b69fdc79a2e5afde60d0ca89a816c5ce24299ad68125bd0
BLAKE2b-256 checksum
How to use checksums
065a2339e680e7987b436731561fa4a5edb2525e76f1694c4109815aed644cf9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 24, 2025.

Transparency log

Release files / tedx_flow-0.1.2-py3-none-any.whl

Download URL tedx_flow-0.1.2-py3-none-any.whl
Size 10.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
33324c0b802894a34b893c073960a2e2f0f51b5110a7aeb35972b27d0d0d1205
BLAKE2b-256 checksum
How to use checksums
8d820b8ea8c1b84a9e7c787e10d0fd671e59a5cdd5d001385c5655b05f026185
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 24, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page