Skip to content

initial implementation (to_json / yaml , from_source and validation #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
jsonschema = "==4.4.0"
pyyaml = "==6.0"

[dev-packages]
pytest = "==6.2.5"
pytest-runner = "==5.3.1"

[requires]
python_version = "3.9"
175 changes: 175 additions & 0 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

104 changes: 102 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,102 @@
# sdk-python
Serverless Workflow Python SDK
# Serverless Workflow Specification - Typescript SDK

Provides the Python API/SPI for the [Serverless Workflow Specification](https://github.com/serverlessworkflow/specification)

> This is a WIP implementation

With the SDK you can:
* **WIP** Programmatically build workflow definitions
* Parse workflow JSON and YAML definitions
* Validate workflow definitions


## Install dependencies and run test

- `pipenv install`
- `python setup.py pytest`

## **WIP** Programmatically build workflow definitions

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

```

## Parse workflow JSON and YAML definitions

### Convert from JSON or YAML source

```
swf_content = """id: greeting
name: Greeting Workflow
version: '1.0'
description: Greet Someone
specVersion: '0.8'
start: Greet
states:
- name: Greet
type: operation
actions:
- functionRef:
refName: greetingFunction
arguments:
name: ${ .person.name }
actionDataFilter:
results: ${ .greeting }
end: true
functions:
- name: greetingFunction
operation: file://myapis/greetingapis.json#greeting
"""
workflow = Workflow.from_source(swf_content)
```

You can see a full example in the [test_workflow.py](./tests/test_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 the [test_workflow.py](./tests/test_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()

```
The `validate` method will raise an exception if the provided workflow does not complaint specification.

You can see a full example in the [test_workflow_validator](./tests/test_workflow_validator.py) file
Empty file.
38 changes: 38 additions & 0 deletions serverlessworkflow_sdk/action.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
class FunctionRef:
pass


class ActionDataFilter:
pass


class Action:
functionRef: FunctionRef
actionDataFilter: ActionDataFilter

def __init__(self, functionRef: FunctionRef = None,
actionDataFilter: ActionDataFilter = None,
**kwargs):
# duplicated
for local in list(locals()):
if local in ["self", "kwargs"]:
continue
value = locals().get(local)
if not value:
continue
if value == "true":
value = True
# duplicated


self.__setattr__(local.replace("_", ""), value)

# duplicated
for k in kwargs.keys():
value = kwargs[k]
if value == "true":
value = True

self.__setattr__(k.replace("_", ""), value)
# duplicated

32 changes: 32 additions & 0 deletions serverlessworkflow_sdk/inject_state.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from serverlessworkflow_sdk.state import State


class InjectState(State):

data: dict

def __init__(self, data: dict = None,
**kwargs):
# duplicated
for local in list(locals()):
if local in ["self", "kwargs"]:
continue
value = locals().get(local)
if not value:
continue
if value == "true":
value = True
# duplicated

self.__setattr__(local.replace("_", ""), value)

# duplicated
for k in kwargs.keys():
value = kwargs[k]
if value == "true":
value = True

self.__setattr__(k.replace("_", ""), value)
# duplicated


Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy