Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Python SDK for Serverless Workflow

License

NotificationsYou must be signed in to change notification settings

serverlessworkflow/sdk-python

Repository files navigation

Provides the Python API/SPI for theServerless Workflow Specification

With the SDK you can:

  • Programmatically build workflow definitions
  • Parse workflow JSON and YAML definitions
  • Validate workflow definitions

Status

Current sdk version conforms to theServerless Workflow specification v0.8.

Install dependencies and run test

  • Python 3 required

  • pipenv requiredpip install pipenv

pipenv install --dev pipenv shellpython setup.py pytest

Programmatically build workflow definitions

 workflow = Workflow(       ,        name="Greeting Workflow",        description="Greet Someone",        version='1.0',        specVersion='0.8',        start="Greet",        states=[            OperationState(                name="Greet",                type="operation",                actions=[                    Action(                        functionRef=FunctionRef(                            refName="greetingFunction",                            arguments={                                "name": "${ .person.name }"                            }                        ),                        actionDataFilter=ActionDataFilter(                            results="${ .greeting }"                        )                    )                ],                end=True            )        ],        functions=[            Function(name="greetingFunction",                     operation="file://myapis/greetingapis.json#greeting")        ]    )

You can see a full example in thetest_workflow.py file

Parse workflow JSON and YAML definitions

Convert from JSON or YAML source

swf_content = """id: greetingname: Greeting Workflowversion: '1.0'description: Greet SomeonespecVersion: '0.8'start: Greetstates:- name: Greet  type: operation  actions:  - functionRef:      refName: greetingFunction      arguments:        name: ${ .person.name }    actionDataFilter:      results: ${ .greeting }  end: truefunctions:- name: greetingFunction  operation: file://myapis/greetingapis.json#greeting"""  workflow = Workflow.from_source(swf_content)

You can see a full example in thetest_workflow.py file

Parse workflow to JSON / YAML

workflow = Workflow(id_="greeting",                    name="Greeting Workflow",                    description="Greet Someone",                    version='1.0',                    specVersion='0.8',                    start="Greet",                    states=[],                    functions=[])                print(workflow.to_json())print(workflow.to_yaml())

You can see a full example in thetest_workflow.py file

Validate workflow definitions

workflow = Workflow(id_="greeting",                    name="Greeting Workflow",                    description="Greet Someone",                    version='1.0',                    specVersion='0.8',                    start="Greet",                    states=[],                    functions=[])WorkflowValidator(Workflow(workflow)).validate()

Thevalidate method will raise an exception if the provided workflow does not complaint specification.

You can see a full example in thetest_workflow_validator file

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp