Workflow management in Litestar
Project description
litestar-workflows
Workflow automation for Litestar with human approval chains, automated pipelines, and web-based workflow management.
Documentation: https://jacobcoffee.github.io/litestar-workflows
Source Code: https://github.com/JacobCoffee/litestar-workflows
Overview
litestar-workflows is a flexible, async-first workflow automation framework built specifically for the Litestar ecosystem. It enables you to define complex business processes as code, combining automated steps with human approval checkpoints.
Key Features
- Async-First Design: Native
async/awaitthroughout, leveraging Litestar's async foundation - Human + Machine Tasks: Combine automated processing with human approval checkpoints
- Composable Workflows: Build complex workflows from simple, reusable primitives
- Type-Safe: Full typing with Protocol-based interfaces for IDE support
- Litestar Integration: Deep integration with Litestar's DI, guards, and plugin system
- Flexible Execution: Local execution engine with optional distributed backends (Celery, SAQ)
- Visual Debugging: MermaidJS workflow visualization support
Use Cases
- Approval Workflows: Expense reports, vacation requests, document reviews
- Multi-Stage Pipelines: Feature releases requiring team, QA, and product approval
- Provisioning Workflows: VM creation, access requests with manager approval
- Content Publishing: Blog posts requiring editorial review before publication
- Any Sequential Process: Anything with an arbitrary series of steps and approvals
Installation
Install using pip:
pip install litestar-workflows
Or with optional extras:
# With database persistence (SQLAlchemy)
pip install litestar-workflows[db]
# With web UI templates
pip install litestar-workflows[ui]
# All extras
pip install litestar-workflows[db,ui]
Quick Start
Here's a simple approval workflow that demonstrates the core concepts:
from litestar_workflows import (
WorkflowDefinition,
Edge,
BaseMachineStep,
BaseHumanStep,
LocalExecutionEngine,
WorkflowRegistry,
WorkflowContext,
)
# Define automated steps
class SubmitRequest(BaseMachineStep):
"""Initial submission step - runs automatically."""
name = "submit"
description = "Submit a new request for processing"
async def execute(self, context: WorkflowContext) -> None:
# Record submission timestamp
context.set("submitted", True)
context.set("submitted_by", context.user_id)
# Define human approval steps
class ManagerApproval(BaseHumanStep):
"""Human task - waits for manager input."""
name = "manager_approval"
title = "Approve Request"
description = "Manager reviews and approves or rejects the request"
form_schema = {
"type": "object",
"properties": {
"approved": {"type": "boolean", "title": "Approve this request?"},
"comments": {"type": "string", "title": "Comments"},
},
"required": ["approved"],
}
class ProcessRequest(BaseMachineStep):
"""Final processing step - runs after approval."""
name = "process"
description = "Process the approved request"
async def execute(self, context: WorkflowContext) -> None:
if context.get("approved"):
context.set("status", "processed")
# Perform actual processing here
else:
context.set("status", "rejected")
# Create workflow definition
definition = WorkflowDefinition(
name="approval_workflow",
version="1.0.0",
description="Simple request approval workflow",
steps={
"submit": SubmitRequest(),
"manager_approval": ManagerApproval(),
"process": ProcessRequest(),
},
edges=[
Edge("submit", "manager_approval"),
Edge("manager_approval", "process"),
],
initial_step="submit",
terminal_steps={"process"},
)
# Register and run
registry = WorkflowRegistry()
registry.register_definition(definition)
engine = LocalExecutionEngine(registry)
# Start a new workflow instance
async def main():
instance = await engine.start_workflow(
"approval_workflow",
initial_data={"request_id": "REQ-001", "amount": 500.00},
)
print(f"Workflow started: {instance.id}")
print(f"Current step: {instance.current_step}") # "manager_approval"
# Later, when a manager completes the approval...
await engine.complete_human_task(
instance_id=instance.id,
step_name="manager_approval",
user_id="manager@example.com",
data={"approved": True, "comments": "Looks good!"},
)
Documentation
For comprehensive documentation, tutorials, and API reference, visit: https://jacobcoffee.github.io/litestar-workflows
Quick Links
Versioning
This project uses Semantic Versioning.
- Major versions introduce breaking changes
- Major versions support the currently supported version(s) of Litestar
- See the Litestar Versioning Policy for details
Contributing
Contributions are welcome! Please see CONTRIBUTING.rst for guidelines.
Development Setup
# Clone the repository
git clone https://github.com/JacobCoffee/litestar-workflows.git
cd litestar-workflows
# Install with development dependencies
pip install -e ".[dev-lint,dev-test]"
# Run tests
pytest tests
# Run linting
pre-commit run --all-files
License
This project is licensed under the MIT License. See LICENSE for details.
Acknowledgments
This library draws inspiration from:
- Joeflow - Human/machine task model and lean automation philosophy
- Prefect - Dynamic execution and event-driven patterns
- Celery Canvas - Composable task primitives
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file litestar_workflows-0.2.0.tar.gz.
File metadata
- Download URL: litestar_workflows-0.2.0.tar.gz
- Upload date:
- Size: 50.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
da065c266b589be788138f92b3124ccba80ed3aea6231e72a7605fb13d87869d
|
|
| MD5 |
3dc523857e3513758022aa422fdb6d0b
|
|
| BLAKE2b-256 |
0cbe1f37561be4f55661804091a401d2726bb4d9d51ba939b298aa1693d142da
|
Provenance
The following attestation bundles were made for litestar_workflows-0.2.0.tar.gz:
Publisher:
publish.yml on JacobCoffee/litestar-workflows
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
litestar_workflows-0.2.0.tar.gz -
Subject digest:
da065c266b589be788138f92b3124ccba80ed3aea6231e72a7605fb13d87869d - Sigstore transparency entry: 726426396
- Sigstore integration time:
-
Permalink:
JacobCoffee/litestar-workflows@0a2553ac4945d39f5ed86037474b3ee8f6a3b5c7 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/JacobCoffee
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@0a2553ac4945d39f5ed86037474b3ee8f6a3b5c7 -
Trigger Event:
release
-
Statement type:
File details
Details for the file litestar_workflows-0.2.0-py3-none-any.whl.
File metadata
- Download URL: litestar_workflows-0.2.0-py3-none-any.whl
- Upload date:
- Size: 66.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1a0a1b4715d5427ac158643fd43fda5595fcc2f7f573cedf50d296dadcc19c6b
|
|
| MD5 |
6262002fed645d00984501b6bf686a22
|
|
| BLAKE2b-256 |
47e48d82cfd89f4a6aba7703672d87f9ea1caaef1497312096f97bbd1c7ba71b
|
Provenance
The following attestation bundles were made for litestar_workflows-0.2.0-py3-none-any.whl:
Publisher:
publish.yml on JacobCoffee/litestar-workflows
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
litestar_workflows-0.2.0-py3-none-any.whl -
Subject digest:
1a0a1b4715d5427ac158643fd43fda5595fcc2f7f573cedf50d296dadcc19c6b - Sigstore transparency entry: 726426402
- Sigstore integration time:
-
Permalink:
JacobCoffee/litestar-workflows@0a2553ac4945d39f5ed86037474b3ee8f6a3b5c7 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/JacobCoffee
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@0a2553ac4945d39f5ed86037474b3ee8f6a3b5c7 -
Trigger Event:
release
-
Statement type: