{"id":31821389,"url":"https://github.com/serverlessworkflow/sdk-python","last_synced_at":"2025-10-11T13:24:26.865Z","repository":{"id":42126501,"uuid":"447249919","full_name":"serverlessworkflow/sdk-python","owner":"serverlessworkflow","description":"Python SDK for Serverless Workflow","archived":false,"fork":false,"pushed_at":"2025-07-29T05:44:27.000Z","size":127,"stargazers_count":24,"open_issues_count":7,"forks_count":8,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-07-29T07:44:25.215Z","etag":null,"topics":["cncf","python","sdk","serverless","serverless-workflow","workflow"],"latest_commit_sha":null,"homepage":"https://serverlessworkflow.io/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/serverlessworkflow.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"code-of-conduct.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-01-12T14:30:19.000Z","updated_at":"2025-07-29T05:44:32.000Z","dependencies_parsed_at":"2025-06-20T19:27:25.265Z","dependency_job_id":"14f39d33-ddee-47da-8ccb-a17342cb373c","html_url":"https://github.com/serverlessworkflow/sdk-python","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/serverlessworkflow/sdk-python","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serverlessworkflow%2Fsdk-python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serverlessworkflow%2Fsdk-python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serverlessworkflow%2Fsdk-python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serverlessworkflow%2Fsdk-python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/serverlessworkflow","download_url":"https://codeload.github.com/serverlessworkflow/sdk-python/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serverlessworkflow%2Fsdk-python/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279007325,"owners_count":26084280,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-11T02:00:06.511Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cncf","python","sdk","serverless","serverless-workflow","workflow"],"created_at":"2025-10-11T13:24:25.265Z","updated_at":"2025-10-11T13:24:26.854Z","avatar_url":"https://github.com/serverlessworkflow.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# Serverless Workflow Specification - Python SDK\n\nProvides the Python API/SPI for the [Serverless Workflow Specification](https://github.com/serverlessworkflow/specification)\n\nWith the SDK you can:\n* Programmatically build workflow definitions \n* Parse workflow JSON and YAML definitions\n* Validate workflow definitions\n\n### Status\n\nCurrent sdk version conforms to the [Serverless Workflow specification v0.8](https://github.com/serverlessworkflow/specification/tree/0.8.x).\n\n\n## Install dependencies and run test \n\n- Python 3 required\n\n- pipenv required `pip install pipenv`\n\n```\npipenv install --dev\n\npipenv run pip install 'setuptools==70.3.0'\n\npipenv shell\n\npython setup.py pytest\n```\n\n## Programmatically build workflow definitions \n\n```\n workflow = Workflow(\n        id=\"greeting\",\n        name=\"Greeting Workflow\",\n        description=\"Greet Someone\",\n        version='1.0',\n        specVersion='0.8',\n        start=\"Greet\",\n        states=[\n            OperationState(\n                name=\"Greet\",\n                type=\"operation\",\n                actions=[\n                    Action(\n                        functionRef=FunctionRef(\n                            refName=\"greetingFunction\",\n                            arguments={\n                                \"name\": \"${ .person.name }\"\n                            }\n                        ),\n                        actionDataFilter=ActionDataFilter(\n                            results=\"${ .greeting }\"\n                        )\n                    )\n                ],\n                end=True\n            )\n        ],\n        functions=[\n            Function(name=\"greetingFunction\",\n                     operation=\"file://myapis/greetingapis.json#greeting\")\n        ]\n    )\n```\nYou can see a full example in the [test_workflow.py](tests/serverlessworkflow/sdk/test_workflow.py) file\n\n## Parse workflow JSON and YAML definitions\n\n### Convert from JSON or YAML source\n\n```\nswf_content = \"\"\"id: greeting\nname: Greeting Workflow\nversion: '1.0'\ndescription: Greet Someone\nspecVersion: '0.8'\nstart: Greet\nstates:\n- name: Greet\n  type: operation\n  actions:\n  - functionRef:\n      refName: greetingFunction\n      arguments:\n        name: ${ .person.name }\n    actionDataFilter:\n      results: ${ .greeting }\n  end: true\nfunctions:\n- name: greetingFunction\n  operation: file://myapis/greetingapis.json#greeting\n\"\"\"\n  workflow = Workflow.from_source(swf_content)\n```\n\nYou can see a full example in the [test_workflow.py](tests/serverlessworkflow/sdk/test_workflow.py) file\n\n\n### Parse workflow to JSON / YAML\n\n```\nworkflow = Workflow(id_=\"greeting\",\n                    name=\"Greeting Workflow\",\n                    description=\"Greet Someone\",\n                    version='1.0',\n                    specVersion='0.8',\n                    start=\"Greet\",\n                    states=[],\n                    functions=[]\n)                \nprint(workflow.to_json())\nprint(workflow.to_yaml())\n```\n\nYou can see a full example in the [test_workflow.py](tests/serverlessworkflow/sdk/test_workflow.py) file\n\n\n## Validate workflow definitions\n\n```\nworkflow = Workflow(id_=\"greeting\",\n                    name=\"Greeting Workflow\",\n                    description=\"Greet Someone\",\n                    version='1.0',\n                    specVersion='0.8',\n                    start=\"Greet\",\n                    states=[],\n                    functions=[]\n)\nWorkflowValidator(Workflow(workflow)).validate()\n\n```\nThe `validate` method will raise an exception if the provided workflow does not complaint specification.\n\nYou can see a full example in the [test_workflow_validator](tests/serverlessworkflow/sdk/test_workflow_validator.py) file\n\n## Generate workflow state machine and graph\n\nTo generate the workflow graph diagram:\n\n```python\nfrom serverlessworkflow.sdk.workflow import Workflow\nfrom serverlessworkflow.sdk.state_machine_helper import StateMachineHelper\n\ndef main():\n    subflows = []\n    with open(\"tests/examples/graph.json\") as f:\n        workflow = Workflow.from_source(f.read())\n    with open(\"tests/examples/advertise-listing.json\") as f:\n        subflows.append(Workflow.from_source(f.read()))\n    with open(\"tests/examples/second-subgraph.json\") as f:\n        subflows.append(Workflow.from_source(f.read()))\n    machine_helper = StateMachineHelper(workflow=workflow, get_actions=True, subflows=subflows)\n    machine_helper.draw('diagram.svg')\n\n\nif __name__ == \"__main__\":\n    main()\n```\n\nThe `StateMachineHelper` can be set with `get_actions` as `False` and the produced diagram will not represent the actions inside each state (it will only create a diagram with the states and their transitions). Moreover, the developer may not give any `subflows`, and they simply will not be generated.\nAs for the `draw` method, the developer can also specify `graph_engine='mermaid'`. In that case, the method will not generate a figure, but rather the Mermaid code that can be executed, for instance, in the [Mermaid Live Editor](https://mermaid.live).\n\nIt is also possible to only generate the workflow state machine. An example on how to do so can be analyzed in the [state_machine_helper](serverlessworkflow/sdk/state_machine_helper.py) source code.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fserverlessworkflow%2Fsdk-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fserverlessworkflow%2Fsdk-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fserverlessworkflow%2Fsdk-python/lists"}