Skip to main content

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 transition or end: true for non-EndState types, collecting all errors.
  • Execute Workflows: Handles all state types, including event-driven, delay, and data injection.
  • JQ Integration: Supports JQ for stateDataFilter, arguments, and inputCollection.
  • 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

  1. Clone the repository:
    git clone https://github.com/rvergis/cncf-serverless-workflow-python-v1.git
    cd cncf-serverless-workflow-python-v1
    
  2. Install dependencies:
    pip install pyyaml jq jsonschema pytest
    
  3. Install as a package:
    pip install .
    

Usage

  1. Save your workflow (workflow.yaml) and schema (workflow_schema.yaml).
  2. 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))
    
  3. 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:

  1. Provide workflow_example.yaml as a one-shot example.
  2. Use prompt: “Generate a state with transition (to ParallelStart, ForEachState, etc.) or end: true after type, optional stateDataFilter, and dataOutput.”
  3. Validate with workflow_validator.py, retrying up to 3 times with errors: “Regenerate fixing: {errors}.”
  4. 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

  1. Fork the repository.
  2. Create a feature branch (git checkout -b feature/your-feature).
  3. Commit changes (git commit -m "Add your feature").
  4. Push to the branch (git push origin feature/your-feature).
  5. 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


Download files

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

Source Distribution

cncf_serverless_workflow-0.1.1.tar.gz (12.9 kB view details)

Uploaded Source

Built Distribution

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

cncf_serverless_workflow-0.1.1-py3-none-any.whl (16.3 kB view details)

Uploaded Python 3

File details

Details for the file cncf_serverless_workflow-0.1.1.tar.gz.

File metadata

  • Download URL: cncf_serverless_workflow-0.1.1.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

Hashes for cncf_serverless_workflow-0.1.1.tar.gz
Algorithm Hash digest
SHA256 52d1adce7c5280030fc03fdc1e7a06285665702efe1b02734198bd5201e0c81a
MD5 f761243de0440b12b8b3bb307230231f
BLAKE2b-256 19d1d1abd2bc6d2e6971140f3e6395d11f24aa4ffa759e505e419ccfa1021b68

See more details on using hashes here.

File details

Details for the file cncf_serverless_workflow-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for cncf_serverless_workflow-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6dc0e4ef6b64997972e444ec5bc4d98e8d6b9b47ba19d28788b203fba5c56f38
MD5 4bf094edca2f3ec81d0b76c8dbf98f12
BLAKE2b-256 f24b238f7e6976b2cc01fabfff32e8a6f3e3a180aca2b9257c5462ab7abf19de

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