Skip to main content

High performance and flexible event-driven workflow engine.

Project description

A powerful and flexible event-driven workflow engine for Python, designed to build complex asynchronous workflows with ease.

PyPI - Version Testing Ruff Pepy Total Downloads PyPI - License

Installation

pip install donkey-workflows

Quick Start

Here's a simple example to get you started with Donkey Workflows:

from donkey_workflows import Workflow, Context, step
from donkey_workflows.events import Event, StartEvent, StopEvent


class MessageEvent(Event):
    message: str

class MyWorkflow(Workflow):

    @step(when=StartEvent)
    async def start(self, ctx: Context, ev: StartEvent) -> MessageEvent:
        
        input_msg = ev.get("message", "")
        return MessageEvent(message=f"Processed: {input_msg}")

    @step(when=MessageEvent)
    async def process(self, ctx: Context, ev: MessageEvent) -> StopEvent:
        return StopEvent(result=ev.message)


async def main():
    workflow = MyWorkflow()
    result = await workflow.run(input_msg="Hello, World!")

    print(result)

Core Concepts

Workflow

A workflow is a class that inherits from Workflow and contains one or more steps. It orchestrates the execution of steps based on events.

Steps

Steps are asynchronous methods decorated with @step(when=EventType) that define what happens when a specific event is received.

  • Steps receive a Context and an Event.
  • Steps can return new events to trigger subsequent steps.

Events

Events are the building blocks of workflows. They carry data between steps and trigger step execution.

  • StartEvent: Automatically triggered when a workflow starts
  • StopEvent: Signals the end of a workflow and carries the final result
  • Custom Events: Define your own events by inheriting from Event

Context

The Context object provides access to workflow state and allows steps to share data throughout the workflow execution.

# Read-only access
current_value = ctx.state.count

# Edit state
async with ctx.store.edit_state() as state:
    state.count = current_counter + 1

# Send events
ctx.send_event(MyEvent(...))

Features

Feature Donkey Workflows
Event-driven execution
Fan-out (parallelism)
Async execution
Shared state
Event joins
Internal buffer
Declarative API
Observability

License

Apache License 2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

donkey_workflows-0.1.0.tar.gz (27.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

donkey_workflows-0.1.0-py3-none-any.whl (35.3 kB view details)

Uploaded Python 3

File details

Details for the file donkey_workflows-0.1.0.tar.gz.

File metadata

  • Download URL: donkey_workflows-0.1.0.tar.gz
  • Upload date:
  • Size: 27.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.28.1

File hashes

Hashes for donkey_workflows-0.1.0.tar.gz
Algorithm Hash digest
SHA256 0f0309a560c7a361a55bc8650e24e9f8309da684115135a99d91e05aab0e055b
MD5 c76ea8ae4e522e1946a70fcc10f816c7
BLAKE2b-256 47d5b12cf55d9db96dac320cdce3b539e1b73c321bcc2669a5ab45f8f5d3bf07

See more details on using hashes here.

File details

Details for the file donkey_workflows-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for donkey_workflows-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c399a635d9963b20bac097086f7b37e136af6b5a29b6fb31c872120a2ef142df
MD5 93b3b13e339194ac89a4078de338d4b2
BLAKE2b-256 4e8a6a73cc1a1a2f7148d75fc48dcdbe895e9eb817c1b3c922b3d6085c73a7cc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page