CNCF Serverless Workflow v1.0 validator and executor
Project description
CNCF Serverless Workflow Python v1.0
A Python 3 library for parsing, validating, and executing workflows defined in the CNCF Serverless Workflow v1.0 specification. Supports all state types (OperationState, ForEachState, SwitchState, SubflowState, ParallelState, EndState, EventState, DelayState, InjectState), JQ-based data filtering, events, retries, and authentication. Optimized for agentic workflows with LLM-friendly design.
Features
- Parse and Validate: Validates YAML/JSON workflows against the v1.0 schema, enforcing
transitionorend: truefor non-EndStatetypes, collecting all errors. - Execute Workflows: Handles all state types, including event-driven, delay, and data injection.
- JQ Integration: Supports JQ for
stateDataFilter,arguments, andinputCollection. - LLM-Friendly: Structured comments (e.g.,
# MANDATORY Transition) and comprehensive error reporting for LLM generation. - Testing: Pytest suite for validation of multiple error cases.
Installation
- Clone the repository:
git clone https://github.com/rvergis/cncf-serverless-workflow-python-v1.git cd cncf-serverless-workflow-python-v1 - Install dependencies:
pip install pyyaml jq jsonschema pytest - Install as a package:
pip install .
Usage
- Save your workflow (
workflow.yaml) and schema (workflow_schema.yaml). - Validate and execute:
from cncf_serverless_workflow.workflow_validator import load_yaml, validate_workflow from cncf_serverless_workflow.workflowengine import execute_workflow schema = load_yaml("workflow_schema.yaml") workflow = load_yaml("workflow_example.yaml") result = validate_workflow(workflow, schema) if result["status"] == "valid": final_state = execute_workflow(workflow) print(json.dumps(final_state, indent=2)) else: print(json.dumps(result["message"], indent=2))
- Example output for
workflow_example.yaml:{ "context": { "ParallelStartOutput": { "items": [{"value": 60}, {"value": 30}, {"value": 45}], "value": 60, "Branch1Output": 62, "Branch2Output": "Processed: 2" }, "ForEachStateOutput": { "results": [ {"method2": "Processed: 10"}, {"method3": [31, 32]}, {"method3": [46, 47]} ] }, "SwitchStateOutput": {"value": 60}, "OperationStateOutput": { "initOperation": {"value": 70}, "method1": 72, "method2": "Processed: Seq2: 72", "method3": ["Processed: Seq2: 72", "Processed: Seq2: 73"], "method4": {"key": "Processed: Seq2: 72"} } } }
LLM Integration
To generate valid workflows:
- Provide
workflow_example.yamlas a one-shot example. - Use prompt: “Generate a state with
transition(to ParallelStart, ForEachState, etc.) orend: trueaftertype, optionalstateDataFilter, anddataOutput.” - Validate with
workflow_validator.py, retrying up to 3 times with errors: “Regenerate fixing: {errors}.” - Example error:
["State 'GetAllObjectIds' missing mandatory transition or end: true"].
Testing
Run tests to validate workflows:
pytest test_workflow_validator.py
Project Structure
workflowengine.py: Executes workflows.workflow_validator.py: Validates workflows, collecting all errors.test_workflow_validator.py: Pytest suite for multiple error cases.workflow_schema.yaml: Full CNCF v1.0 schema.workflow_example.yaml: Example workflow with LLM-friendly comments.
Contributing
- Fork the repository.
- Create a feature branch (
git checkout -b feature/your-feature). - Commit changes (
git commit -m "Add your feature"). - Push to the branch (
git push origin feature/your-feature). - Open a pull request.
License
MIT License. See LICENSE.
Acknowledgments
- Built on CNCF Serverless Workflow v1.0.
- Inspired by
serverlessworkflow/sdk-python(v0.8).
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 cncf_serverless_workflow-0.1.0.tar.gz.
File metadata
- Download URL: cncf_serverless_workflow-0.1.0.tar.gz
- Upload date:
- Size: 12.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aaf54e9e3e664c972aeb122d2beee3e8d4b3d7b3835ddbca6dc34b69db0f072e
|
|
| MD5 |
68dba17bded57359a99ef7dca1a52240
|
|
| BLAKE2b-256 |
20dcd7baf08680bbcaab0c303b03d53c6bb2cd02016092036d2294582c424748
|
File details
Details for the file cncf_serverless_workflow-0.1.0-py3-none-any.whl.
File metadata
- Download URL: cncf_serverless_workflow-0.1.0-py3-none-any.whl
- Upload date:
- Size: 16.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e2228d215bb7bc16bec5698f9015d2d2ab0fddda74545d418af8ef28b5a13b1b
|
|
| MD5 |
0319b23895077db73732b4d7e8a622bb
|
|
| BLAKE2b-256 |
7987b3627e7cd9ca2390a011c21e84edab4553e3c6ce74d5a329cf0522841b50
|