🌊 hexastack-flow
Hexagonal workflow engine adapter integrating
hexaflowwith Hexastack CQRS, Relational Persistence, and Event Streaming.
Part of the Hexastack Framework · Powered by Hexaflow · Governed by Hexaqual.
🎯 Architectural Intent
hexastack-flow provides first-class hexagonal adapters connecting the lightweight hexaflow workflow engine to Hexastack:
- CQRS Bridge:
CommandStepandQueryStepallow workflow steps to dispatch typed commands and queries directly onto theCommandBusandQueryBus, inheriting all CQRS middleware (auth, tracing, logging, metrics, retries). - Durable Distributed Sagas: Workflows natively subsume the Saga pattern by pairing forward command execution stages with compensating rollback stages, backed by durable checkpoints.
- Enterprise Persistence:
SqlAlchemyWorkflowStorepersists workflow execution records and step checkpoints directly to PostgreSQL/SQLite/MySQL within transactional boundaries. - Event Streaming: Emits domain events (
WorkflowStartedEvent,WorkflowStepCompletedEvent,WorkflowSuspendedEvent,WorkflowCompletedEvent,WorkflowAbortedEvent) wrapped in standardCloudEventEnvelopes throughhexastack-events. - Pluggable Graph Subsystem & Visualizers: Render workflows directly to Mermaid diagrams (
wf.render("mermaid")), Graphviz DOT, or terminal ASCII trees with automatic critical path bottleneck detection (critical_path=True). - Dry-Run Simulation: In-memory pre-flight saga validation (
wf.simulate()) executing pure steps and mocking mutating steps fail-closed with zero external side-effects. - Step Execution Middleware: Interceptors (
StepMiddlewarePort) for latency instrumentation, execution logging, and OpenTelemetry distributed tracing cascades. - DevTools Visualizer: Backing engine for NiceGUI reactive DAG monitoring, orientation toggling, and step highlighting.
🔄 Implementing the Saga Pattern as a Workflow
Historically, the Saga Pattern structures a distributed business transaction across multiple microservices or bounded contexts as a sequence of local transactions:
- Forward transactions: $T_1, T_2, \dots, T_n$
- Compensating transactions: $C_{k-1}, \dots, C_1$ executed in reverse (LIFO) order if step $k$ fails.
In hexastack-flow, you do not need a separate, restricted saga engine. A Saga is simply a workflow DAG that dispatches CQRS commands and executes compensating commands on failure.
Example: Trip Booking Saga with CQRS & Hexaflow
from hexaflow import Workflow
from hexastack_cqrs.ports.buses import CommandBusPort
from hexastack_flow.adapters.cqrs.runner import CqrsWorkflowRunner
from hexastack_flow.adapters.cqrs.steps import as_command_step
# 1. Define CQRS commands for forward actions & compensations
from my_domain.commands import (
BookFlightCommand,
CancelFlightCommand,
BookHotelCommand,
CancelHotelCommand,
ChargePaymentCommand,
)
def build_trip_booking_workflow(bus: CommandBusPort, customer_id: str) -> Workflow:
"""Construct a durable distributed saga as a hexaflow Workflow."""
workflow = (
Workflow("trip-booking-saga")
# Step 1: Reserve Flight
.stage(
"flight",
as_command_step(
lambda ctx: BookFlightCommand(
customer_id=customer_id, destination="JFK"
),
bus,
name="book_flight",
),
)
# Step 2: Reserve Hotel (runs after flight is confirmed)
.stage(
"hotel",
as_command_step(
lambda ctx: BookHotelCommand(
customer_id=customer_id, room_type="deluxe"
),
bus,
name="book_hotel",
),
depends_on=["flight"],
)
# Step 3: Process Payment
.stage(
"payment",
as_command_step(
lambda ctx: ChargePaymentCommand(
customer_id=customer_id, amount_cents=50000
),
bus,
name="charge_payment",
),
depends_on=["hotel"],
)
)
return workflow
# 2. Execute via CqrsWorkflowRunner (with durable DB checkpoints)
runner = CqrsWorkflowRunner(engine=engine)
result = await runner.run(workflow.build())
Why Workflows are Superior to Linear Sagas
| Feature | Legacy In-Memory Saga | hexastack-flow Workflow |
|---|---|---|
| Execution Topologies | Strictly sequential ($T_1 \to T_2 \to T_3$) | Arbitrary DAGs (e.g. reserve Flight & Hotel in parallel) |
| Crash Recovery | In-memory only (lost if process restarts) | Durable Checkpoints (SqlAlchemyWorkflowStore) |
| Step Retries | Manual loop or fail immediately | Configurable RetryPolicy (exponential backoff, jitter) |
| Observability | Console logs | CloudEvents (WorkflowStepCompletedEvent) + OTel spans |
| Human-in-the-Loop | Not supported | Pause / Resume (engine.suspend(), engine.resume()) |
📦 Installation
pip install hexastack[flow]
Or standalone:
pip install hexastack-flow
📄 License
Apache 2.0
Metadata
Release files for hexastack-flow 0.11.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| hexastack_flow-0.11.3.tar.gz | 23.8 kB | Without provenance | Details for hexastack_flow-0.11.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| hexastack_flow-0.11.3-py3-none-any.whl | Python 3 | none | any | Details for hexastack_flow-0.11.3-py3-none-any.whl |
Total release size: 55.8 kB
Release files / hexastack_flow-0.11.3.tar.gz
| Download URL | hexastack_flow-0.11.3.tar.gz |
|---|---|
| Size | 23.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6352015b929deb6e2e1c5922d9f548c45c579d07be3bf6a4fe6d77891b456ca5
|
|
BLAKE2b-256 checksum How to use checksums |
456fdcac7307c1198b78504a37d62608644756f57f6c72f61799f695069e5747
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Release files / hexastack_flow-0.11.3-py3-none-any.whl
| Download URL | hexastack_flow-0.11.3-py3-none-any.whl |
|---|---|
| Size | 32.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f3cbc58b8599478ad2f2b277b33fa5e49106ab4d232f7148cefed5e68d4669f9
|
|
BLAKE2b-256 checksum How to use checksums |
c34934054a5d1ae98edda6abb813f305571664285a5685dd3de7f3a529dd3dbb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Security for hexastack-flow 0.11.3
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.