stageflow-framework 0.1.6__tar.gz → 0.9.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- stageflow_framework-0.9.0/LICENSE +21 -0
- stageflow_framework-0.9.0/PKG-INFO +478 -0
- stageflow_framework-0.9.0/README.md +448 -0
- stageflow_framework-0.9.0/pyproject.toml +50 -0
- stageflow_framework-0.9.0/stageflow/__init__.py +97 -0
- {stageflow_framework-0.1.6 → stageflow_framework-0.9.0}/stageflow/builtins/__init__.py +12 -15
- stageflow_framework-0.9.0/stageflow/builtins/_args.py +35 -0
- {stageflow_framework-0.1.6 → stageflow_framework-0.9.0}/stageflow/builtins/dicts.py +12 -15
- stageflow_framework-0.9.0/stageflow/builtins/lists.py +171 -0
- stageflow_framework-0.9.0/stageflow/builtins/logic.py +100 -0
- stageflow_framework-0.9.0/stageflow/builtins/strings.py +75 -0
- stageflow_framework-0.9.0/stageflow/builtins/vars.py +114 -0
- stageflow_framework-0.9.0/stageflow/core/__init__.py +67 -0
- stageflow_framework-0.9.0/stageflow/core/cel.py +75 -0
- stageflow_framework-0.9.0/stageflow/core/context.py +48 -0
- stageflow_framework-0.9.0/stageflow/core/debug.py +146 -0
- {stageflow_framework-0.1.6 → stageflow_framework-0.9.0}/stageflow/core/event.py +19 -33
- stageflow_framework-0.9.0/stageflow/core/inputs.py +63 -0
- stageflow_framework-0.9.0/stageflow/core/nodes/__init__.py +26 -0
- stageflow_framework-0.9.0/stageflow/core/nodes/base.py +110 -0
- stageflow_framework-0.9.0/stageflow/core/nodes/bindings.py +88 -0
- stageflow_framework-0.9.0/stageflow/core/nodes/branching.py +89 -0
- stageflow_framework-0.9.0/stageflow/core/nodes/entry.py +152 -0
- stageflow_framework-0.9.0/stageflow/core/nodes/parallel.py +159 -0
- stageflow_framework-0.9.0/stageflow/core/nodes/recovery.py +92 -0
- stageflow_framework-0.9.0/stageflow/core/nodes/stage.py +149 -0
- stageflow_framework-0.9.0/stageflow/core/nodes/subpipeline.py +89 -0
- stageflow_framework-0.9.0/stageflow/core/nodes/terminal.py +36 -0
- stageflow_framework-0.9.0/stageflow/core/nodes/try_block.py +130 -0
- stageflow_framework-0.9.0/stageflow/core/payload_schema.py +106 -0
- stageflow_framework-0.9.0/stageflow/core/pipeline.py +146 -0
- stageflow_framework-0.9.0/stageflow/core/registry.py +36 -0
- stageflow_framework-0.9.0/stageflow/core/session.py +344 -0
- stageflow_framework-0.9.0/stageflow/core/spec.py +79 -0
- stageflow_framework-0.9.0/stageflow/core/stage.py +115 -0
- stageflow_framework-0.9.0/stageflow/core/typesys.py +402 -0
- stageflow_framework-0.9.0/stageflow/docs/__init__.py +13 -0
- stageflow_framework-0.9.0/stageflow/docs/schema.py +35 -0
- stageflow_framework-0.9.0/stageflow/docs/schemas/pipeline.json +698 -0
- stageflow_framework-0.9.0/stageflow/exceptions.py +54 -0
- stageflow_framework-0.9.0/stageflow/py.typed +0 -0
- stageflow_framework-0.9.0/stageflow/testing.py +84 -0
- stageflow_framework-0.9.0/stageflow_framework.egg-info/PKG-INFO +478 -0
- {stageflow_framework-0.1.6 → stageflow_framework-0.9.0}/stageflow_framework.egg-info/SOURCES.txt +30 -8
- stageflow_framework-0.9.0/stageflow_framework.egg-info/requires.txt +9 -0
- stageflow_framework-0.9.0/tests/test_core_flow.py +283 -0
- stageflow_framework-0.9.0/tests/test_debug.py +253 -0
- stageflow_framework-0.9.0/tests/test_docs_schema.py +184 -0
- stageflow_framework-0.9.0/tests/test_entry_node.py +334 -0
- {stageflow_framework-0.1.6 → stageflow_framework-0.9.0}/tests/test_full_pipeline.py +57 -50
- stageflow_framework-0.9.0/tests/test_packaging.py +29 -0
- stageflow_framework-0.9.0/tests/test_parallel.py +132 -0
- {stageflow_framework-0.1.6 → stageflow_framework-0.9.0}/tests/test_payload_validation.py +7 -8
- {stageflow_framework-0.1.6 → stageflow_framework-0.9.0}/tests/test_pipeline_tester.py +8 -5
- stageflow_framework-0.9.0/tests/test_removed_local_scope.py +110 -0
- stageflow_framework-0.9.0/tests/test_session_control.py +89 -0
- {stageflow_framework-0.1.6 → stageflow_framework-0.9.0}/tests/test_session_wait_input.py +16 -6
- {stageflow_framework-0.1.6 → stageflow_framework-0.9.0}/tests/test_snapshot.py +4 -10
- stageflow_framework-0.9.0/tests/test_std_stages.py +196 -0
- stageflow_framework-0.9.0/tests/test_subpipeline.py +155 -0
- stageflow_framework-0.9.0/tests/test_try_block.py +255 -0
- stageflow_framework-0.9.0/tests/test_typesystem.py +397 -0
- stageflow_framework-0.1.6/PKG-INFO +0 -167
- stageflow_framework-0.1.6/README.md +0 -157
- stageflow_framework-0.1.6/pyproject.toml +0 -24
- stageflow_framework-0.1.6/stageflow/__init__.py +0 -25
- stageflow_framework-0.1.6/stageflow/builtins/lists.py +0 -71
- stageflow_framework-0.1.6/stageflow/builtins/lists_extra.py +0 -110
- stageflow_framework-0.1.6/stageflow/builtins/logic.py +0 -84
- stageflow_framework-0.1.6/stageflow/builtins/strings.py +0 -81
- stageflow_framework-0.1.6/stageflow/builtins/vars.py +0 -118
- stageflow_framework-0.1.6/stageflow/core/__init__.py +0 -7
- stageflow_framework-0.1.6/stageflow/core/context.py +0 -86
- stageflow_framework-0.1.6/stageflow/core/jsonlogic.py +0 -43
- stageflow_framework-0.1.6/stageflow/core/node.py +0 -254
- stageflow_framework-0.1.6/stageflow/core/pipeline.py +0 -105
- stageflow_framework-0.1.6/stageflow/core/session.py +0 -407
- stageflow_framework-0.1.6/stageflow/core/stage.py +0 -168
- stageflow_framework-0.1.6/stageflow/core/utils.py +0 -108
- stageflow_framework-0.1.6/stageflow/docs/__init__.py +0 -4
- stageflow_framework-0.1.6/stageflow/docs/html.py +0 -479
- stageflow_framework-0.1.6/stageflow/docs/schema.py +0 -38
- stageflow_framework-0.1.6/stageflow/docs/schemas/pipeline.json +0 -134
- stageflow_framework-0.1.6/stageflow/py.typed +0 -1
- stageflow_framework-0.1.6/stageflow/testing.py +0 -59
- stageflow_framework-0.1.6/stageflow_framework.egg-info/PKG-INFO +0 -167
- stageflow_framework-0.1.6/stageflow_framework.egg-info/requires.txt +0 -2
- stageflow_framework-0.1.6/tests/test_core_flow.py +0 -79
- stageflow_framework-0.1.6/tests/test_docs_schema.py +0 -99
- stageflow_framework-0.1.6/tests/test_jsonlogic.py +0 -34
- stageflow_framework-0.1.6/tests/test_stage_wait_input.py +0 -64
- stageflow_framework-0.1.6/tests/test_std_stages.py +0 -53
- stageflow_framework-0.1.6/tests/test_subpipeline.py +0 -187
- {stageflow_framework-0.1.6 → stageflow_framework-0.9.0}/setup.cfg +0 -0
- {stageflow_framework-0.1.6 → stageflow_framework-0.9.0}/stageflow_framework.egg-info/dependency_links.txt +0 -0
- {stageflow_framework-0.1.6 → stageflow_framework-0.9.0}/stageflow_framework.egg-info/top_level.txt +0 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025-2026 лень
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,478 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: stageflow-framework
|
|
3
|
+
Version: 0.9.0
|
|
4
|
+
Summary: StageFlow: pipeline framework for stages
|
|
5
|
+
Author-email: лень <pzrnqt1vrss@protonmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Repository, https://github.com/leo-need-more-coffee/stageflow
|
|
8
|
+
Project-URL: Issues, https://github.com/leo-need-more-coffee/stageflow/issues
|
|
9
|
+
Keywords: pipeline,workflow,orchestration,state-machine,cel
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
16
|
+
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
|
|
17
|
+
Classifier: Typing :: Typed
|
|
18
|
+
Requires-Python: >=3.11
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
License-File: LICENSE
|
|
21
|
+
Requires-Dist: pyyaml
|
|
22
|
+
Requires-Dist: jsonschema>=4.0.0
|
|
23
|
+
Requires-Dist: immutables>=0.20
|
|
24
|
+
Requires-Dist: common-expression-language>=0.9
|
|
25
|
+
Provides-Extra: dev
|
|
26
|
+
Requires-Dist: flake8; extra == "dev"
|
|
27
|
+
Requires-Dist: build; extra == "dev"
|
|
28
|
+
Requires-Dist: twine; extra == "dev"
|
|
29
|
+
Dynamic: license-file
|
|
30
|
+
|
|
31
|
+
# StageFlow
|
|
32
|
+
|
|
33
|
+
[](https://github.com/leo-need-more-coffee/stageflow/actions/workflows/tests.yml)
|
|
34
|
+
|
|
35
|
+
A framework for describing and running JSON-defined pipelines: a graph of
|
|
36
|
+
nodes, user-defined stages, an immutable data frame, CEL expressions, retry
|
|
37
|
+
and block-scoped `try/except`, parallel branches, nested pipelines.
|
|
38
|
+
|
|
39
|
+
Requires Python 3.11+ (the `common-expression-language` CEL binding does).
|
|
40
|
+
|
|
41
|
+
## Installation
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
python -m venv .venv
|
|
45
|
+
source .venv/bin/activate
|
|
46
|
+
pip install -e .
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Quick start
|
|
50
|
+
|
|
51
|
+
Register a stage:
|
|
52
|
+
|
|
53
|
+
```python
|
|
54
|
+
from stageflow import BaseStage, register_stage
|
|
55
|
+
|
|
56
|
+
@register_stage("HelloStage")
|
|
57
|
+
class HelloStage(BaseStage):
|
|
58
|
+
"""
|
|
59
|
+
description: "Custom stage example"
|
|
60
|
+
icon: "👋"
|
|
61
|
+
arguments:
|
|
62
|
+
name: string
|
|
63
|
+
outputs:
|
|
64
|
+
greeting: string
|
|
65
|
+
"""
|
|
66
|
+
async def run(self):
|
|
67
|
+
name = self.get_arguments().get("name", "world")
|
|
68
|
+
self.set_outputs({"greeting": f"Hello, {name}!"})
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Describe a pipeline:
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
pipeline_dict = {
|
|
75
|
+
"nodes": [
|
|
76
|
+
{
|
|
77
|
+
"id": "start",
|
|
78
|
+
"type": "entry",
|
|
79
|
+
"variables": {"user_name": "Alice"},
|
|
80
|
+
"next": "hello",
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
"id": "hello",
|
|
84
|
+
"type": "stage",
|
|
85
|
+
"stage": "HelloStage",
|
|
86
|
+
"arguments": {"vars": {"name": "user_name"}},
|
|
87
|
+
"outputs": {"greeting": "greeting"},
|
|
88
|
+
"next": "finish",
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
"id": "finish",
|
|
92
|
+
"type": "terminal",
|
|
93
|
+
"result": {"status": "ok"},
|
|
94
|
+
"artifacts": ["greeting"],
|
|
95
|
+
},
|
|
96
|
+
],
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Run it:
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
import asyncio
|
|
104
|
+
from stageflow import Pipeline, Session
|
|
105
|
+
|
|
106
|
+
async def main():
|
|
107
|
+
session = Session(id="demo", pipeline=Pipeline.from_dict(pipeline_dict))
|
|
108
|
+
result = await session.run()
|
|
109
|
+
print(result.result) # {'status': 'ok'}
|
|
110
|
+
print(result.artifacts) # {'greeting': 'Hello, Alice!'}
|
|
111
|
+
|
|
112
|
+
asyncio.run(main())
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
Values declared by the `entry` node are defaults: anything supplied from the
|
|
116
|
+
outside overrides them, so the same pipeline can be parameterised without
|
|
117
|
+
editing its JSON.
|
|
118
|
+
|
|
119
|
+
```python
|
|
120
|
+
from stageflow import Context
|
|
121
|
+
session = Session(id="demo", pipeline=pipeline, context=Context({"user_name": "Bob"}))
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## Node types
|
|
125
|
+
|
|
126
|
+
| `type` | Purpose | Key fields |
|
|
127
|
+
|---|---|---|
|
|
128
|
+
| `entry` | graph start and the variables it begins with | `variables`, `next` |
|
|
129
|
+
| `stage` | run a registered stage | `stage`, `arguments`, `outputs`, `consume`, `next` |
|
|
130
|
+
| `condition` | binary branch on a CEL expression | `condition`, `then`, `else` |
|
|
131
|
+
| `switch` | n-way branch, first matching case wins | `cases: [{when, next}]`, `default` |
|
|
132
|
+
| `parallel` | concurrent branches with independent frames | `branches`, `cancel_on_error`, `next` |
|
|
133
|
+
| `try` | block-scoped error handling over a graph region | `body`, `except`, `next` |
|
|
134
|
+
| `subpipeline` | nested pipeline with a fresh frame | `subpipeline_id`, `inputs`, `artifact_outputs`, `result_output`, `next` |
|
|
135
|
+
| `terminal` | end of execution | `result`, `artifacts` |
|
|
136
|
+
|
|
137
|
+
Every node additionally accepts `retry`, `consume` (drop names from the frame
|
|
138
|
+
after the step) and `expose` (copy or rename a variable without a stage).
|
|
139
|
+
|
|
140
|
+
## Data model
|
|
141
|
+
|
|
142
|
+
Pipeline data is a single frame, `vars`, carried along the execution path.
|
|
143
|
+
The frame is immutable: every write produces a new one, so `parallel` branches
|
|
144
|
+
diverge independently and the same object can safely be handed to several
|
|
145
|
+
concurrent consumers. The only visibility boundary is `subpipeline`: a child
|
|
146
|
+
starts with a fresh frame and receives data through `inputs`.
|
|
147
|
+
|
|
148
|
+
A node's `arguments` are split into buckets: `vars` holds references to frame
|
|
149
|
+
variables, `const` holds literals. Buckets can be mixed in one node; on a name
|
|
150
|
+
collision the variable reference wins over the literal. A `stage` node has no
|
|
151
|
+
separate settings field — a literal setting is a `const` argument.
|
|
152
|
+
|
|
153
|
+
```json
|
|
154
|
+
{
|
|
155
|
+
"id": "auth",
|
|
156
|
+
"type": "stage",
|
|
157
|
+
"stage": "AuthStage",
|
|
158
|
+
"arguments": { "vars": { "creds": "creds" }, "const": { "timeout_s": 30 } },
|
|
159
|
+
"outputs": { "token": "token" },
|
|
160
|
+
"consume": ["creds"],
|
|
161
|
+
"next": "fetch"
|
|
162
|
+
}
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
In `outputs` the key is the name of a field in the stage result and the value
|
|
166
|
+
is the variable to store it in. A field the stage does not return is rejected
|
|
167
|
+
by `Pipeline.validate()` against the stage specification. If a stage declares
|
|
168
|
+
no outputs at all, the contract is considered undeclared and the check is
|
|
169
|
+
skipped.
|
|
170
|
+
|
|
171
|
+
A node's outputs are applied as a simultaneous assignment: values are computed
|
|
172
|
+
against the frame as it was on entry and only then written, so key order does
|
|
173
|
+
not affect the result.
|
|
174
|
+
|
|
175
|
+
## Expressions
|
|
176
|
+
|
|
177
|
+
The expression language is [CEL](https://github.com/google/cel-spec). An
|
|
178
|
+
expression is allowed in `condition` of a `condition` node, in `when` of a
|
|
179
|
+
`switch` node, and in any value whose key carries the `.$` suffix in
|
|
180
|
+
`arguments`, `outputs` and `variables`.
|
|
181
|
+
|
|
182
|
+
```json
|
|
183
|
+
"outputs": {
|
|
184
|
+
"value": "n",
|
|
185
|
+
"attempts.$": "0",
|
|
186
|
+
"greeting.$": "'hello ' + string(vars.user_name)"
|
|
187
|
+
}
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
Frame variables are addressed through the `vars` namespace (`vars.n`). A name
|
|
191
|
+
that is not an ASCII identifier is addressed by index: `vars['итог']`.
|
|
192
|
+
|
|
193
|
+
A key with the `.$` suffix in `outputs` names a variable rather than a stage
|
|
194
|
+
field, so a single node can introduce any number of pipeline variables.
|
|
195
|
+
|
|
196
|
+
Backend: `common-expression-language` (native), falling back to `cel-python`.
|
|
197
|
+
|
|
198
|
+
## The `entry` node
|
|
199
|
+
|
|
200
|
+
The graph starts at a node, not at a field in the JSON header, and that node
|
|
201
|
+
declares the pipeline's initial variables.
|
|
202
|
+
|
|
203
|
+
```json
|
|
204
|
+
{
|
|
205
|
+
"id": "start",
|
|
206
|
+
"type": "entry",
|
|
207
|
+
"variables": {
|
|
208
|
+
"n": 5,
|
|
209
|
+
"items": [1, 2, 3],
|
|
210
|
+
"total.$": "vars.n * 2"
|
|
211
|
+
},
|
|
212
|
+
"next": "check"
|
|
213
|
+
}
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
- A name already present in the frame (session seed, a parent's `inputs`) is
|
|
217
|
+
neither overwritten nor evaluated.
|
|
218
|
+
- Variables are bound in dependency order: an expression may reference a
|
|
219
|
+
sibling variable of the same node, key order in the JSON is irrelevant, and
|
|
220
|
+
a cycle is a `validate()` error.
|
|
221
|
+
- There is exactly one `entry` node per graph and jumping back into it is
|
|
222
|
+
forbidden. The pipeline-level `entry` field is optional when such a node
|
|
223
|
+
exists, and must point at it when given.
|
|
224
|
+
- Value types are checked statically, during validation.
|
|
225
|
+
|
|
226
|
+
## Parallel branches
|
|
227
|
+
|
|
228
|
+
```json
|
|
229
|
+
{
|
|
230
|
+
"id": "fan_out",
|
|
231
|
+
"type": "parallel",
|
|
232
|
+
"branches": [{ "id": "hash", "entry": "hash_step" },
|
|
233
|
+
{ "id": "thumb", "entry": "thumb_step" }],
|
|
234
|
+
"next": "merge"
|
|
235
|
+
}
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
Only names that were not in the frame before `parallel` leave a branch; a
|
|
239
|
+
write to a name that existed on entry stays branch-local. Such names are
|
|
240
|
+
listed in the `parallel_completed` event:
|
|
241
|
+
`{"merged": ["fresh"], "dropped": ["left.n"]}`. Two branches writing the same
|
|
242
|
+
name raise `BranchError` naming both.
|
|
243
|
+
|
|
244
|
+
`cancel_on_error` (default `true`) decides the fate of sibling branches when
|
|
245
|
+
one fails: `true` cancels them immediately (the `parallel_cancelled` event),
|
|
246
|
+
`false` lets them finish. Either way the node fails with the error of the
|
|
247
|
+
first branch that failed.
|
|
248
|
+
|
|
249
|
+
## Errors: `retry` per node, `try`/`except` per region
|
|
250
|
+
|
|
251
|
+
Retrying is a property of an operation, so `retry` is a node field:
|
|
252
|
+
|
|
253
|
+
```json
|
|
254
|
+
{ "retry": [{ "error_equals": ["TimeoutError"], "max_attempts": 3, "backoff_rate": 2.0 }] }
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
`max_attempts` counts every run of the node including the first: `3` means one
|
|
258
|
+
run and two retries. Each policy in the list keeps its own counter.
|
|
259
|
+
|
|
260
|
+
Error handling is block-scoped: a `try` node covers a region of the graph, and
|
|
261
|
+
an error raised by any node inside it goes to the matching `except`.
|
|
262
|
+
|
|
263
|
+
```json
|
|
264
|
+
{
|
|
265
|
+
"id": "safe_fetch",
|
|
266
|
+
"type": "try",
|
|
267
|
+
"body": "fetch",
|
|
268
|
+
"except": [
|
|
269
|
+
{ "error_equals": ["TimeoutError"], "next": "on_timeout", "result_var": "error" },
|
|
270
|
+
{ "error_equals": ["*"], "next": "on_any" }
|
|
271
|
+
],
|
|
272
|
+
"next": "after"
|
|
273
|
+
}
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
- The region is every node reachable from `body` but not reachable from
|
|
277
|
+
`next`; it is derived from the graph rather than listed by hand.
|
|
278
|
+
- The failing node's `retry` policies are exhausted first, then the error
|
|
279
|
+
propagates to the nearest enclosing `try`; an error no handler matches keeps
|
|
280
|
+
propagating outwards.
|
|
281
|
+
- Nested `try` nodes work as expected: the inner one simply lies inside the
|
|
282
|
+
outer one's region.
|
|
283
|
+
- A handler sees the frame as the last successfully completed node of the body
|
|
284
|
+
left it.
|
|
285
|
+
- `result_var` puts the error object into the frame with the fields `type`,
|
|
286
|
+
`full_type`, `message` and `node`.
|
|
287
|
+
- `error_equals` accepts a bare exception class name, a fully qualified path,
|
|
288
|
+
or `*`.
|
|
289
|
+
|
|
290
|
+
## Variable typing
|
|
291
|
+
|
|
292
|
+
Typing is gradual: an undeclared variable is not checked, and the type
|
|
293
|
+
sections are optional.
|
|
294
|
+
|
|
295
|
+
```json
|
|
296
|
+
{
|
|
297
|
+
"types": {
|
|
298
|
+
"UserId": "int",
|
|
299
|
+
"User": {
|
|
300
|
+
"id": "UserId",
|
|
301
|
+
"name": "string",
|
|
302
|
+
"email?": "string",
|
|
303
|
+
"settings": { "theme": "string" }
|
|
304
|
+
},
|
|
305
|
+
"Point": { "fields": { "x": "int", "y": "int" }, "strict": true },
|
|
306
|
+
"Tree": { "value": "int", "children": "list<Tree>" }
|
|
307
|
+
},
|
|
308
|
+
"variables": { "user": "User", "attempts": "int", "tags": "list<string>" }
|
|
309
|
+
}
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
The type language: primitives `string`, `int`, `float`, `number` (int|float),
|
|
313
|
+
`bool`, `any`, `null`; containers `list<T>` and `map<T>` (string keys); unions
|
|
314
|
+
`T|U`; the shorthand `T?` for `T|null`; names from the `types` section.
|
|
315
|
+
Structures support optional fields (a `?` suffix on the name), nested
|
|
316
|
+
anonymous structures, recursion, and a strict mode (`strict` forbids extra
|
|
317
|
+
fields).
|
|
318
|
+
|
|
319
|
+
Checks come in two layers:
|
|
320
|
+
|
|
321
|
+
- statically, during graph validation: a variable's declared type is matched
|
|
322
|
+
against the type hints in the stage specification, and `expose` requires the
|
|
323
|
+
source and destination to be compatible; a mismatch is a
|
|
324
|
+
`Pipeline.validate()` error raised before the run starts;
|
|
325
|
+
- dynamically, during execution: every write to a declared variable (`entry`,
|
|
326
|
+
`outputs`, `expose`, `except.result_var`, subpipeline artifacts) and the
|
|
327
|
+
session's input context are checked against the full structure of the value;
|
|
328
|
+
a mismatch raises `TypeCheckError` carrying the node and the path to it.
|
|
329
|
+
|
|
330
|
+
A subpipeline inherits its parent's named types and may declare its own;
|
|
331
|
+
variable types are its own.
|
|
332
|
+
|
|
333
|
+
## Session control
|
|
334
|
+
|
|
335
|
+
```python
|
|
336
|
+
session.stop(); session.pause(); session.resume()
|
|
337
|
+
await session.input("command", {"name": "skip"})
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
User input: a stage declares `allowed_inputs` and awaits
|
|
341
|
+
`await self.wait_input("user_input", timeout=...)`; input is delivered from
|
|
342
|
+
outside with `await session.input("user_input", {...})`. The payload is
|
|
343
|
+
validated against the `payload_schema` from the declaration.
|
|
344
|
+
|
|
345
|
+
Snapshots: `session.snapshot()` returns a dict, `Session.from_snapshot(snap)`
|
|
346
|
+
restores the session, and `run()` resumes from the saved node.
|
|
347
|
+
|
|
348
|
+
## Step debugging
|
|
349
|
+
|
|
350
|
+
`Session` accepts a debugger that is given control before and after every
|
|
351
|
+
node. The in-core implementation is `StepDebugger`.
|
|
352
|
+
|
|
353
|
+
```python
|
|
354
|
+
from stageflow import Pipeline, Session, StepDebugger
|
|
355
|
+
|
|
356
|
+
debugger = StepDebugger(mode="step", delay=0.0, on_event=print)
|
|
357
|
+
session = Session("s1", Pipeline.from_dict(data), debugger=debugger)
|
|
358
|
+
task = asyncio.create_task(session.run()) # stops before the first node
|
|
359
|
+
|
|
360
|
+
debugger.step() # let one node run, then stop again
|
|
361
|
+
debugger.set_vars({"n": 42}) # applied before the next node
|
|
362
|
+
debugger.set_delay(0.5) # run on its own, pausing between nodes
|
|
363
|
+
debugger.resume() # continue without stopping
|
|
364
|
+
result = await task
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
Available from outside: the stop point (`debugger.node`), the frame at that
|
|
368
|
+
point (`debugger.vars`), and the `on_event` stream: `node_enter`, `node_exit`,
|
|
369
|
+
`paused`, `var_set`, `var_rejected`. Frame edits are checked against declared
|
|
370
|
+
types — a mismatch is rejected with an event rather than crashing the session.
|
|
371
|
+
|
|
372
|
+
The debugger also applies inside a `try` body, inside `parallel` branches and
|
|
373
|
+
inside a subpipeline: every node goes through `Session.execute_node`, and a
|
|
374
|
+
child session inherits the debugger. Commands are thread-safe.
|
|
375
|
+
|
|
376
|
+
## Built-in stages
|
|
377
|
+
|
|
378
|
+
| Category | Stages |
|
|
379
|
+
|---|---|
|
|
380
|
+
| vars | `SetValueStage`, `CopyValueStage`, `IncrementStage`, `MergeDictStage` |
|
|
381
|
+
| lists | `AppendListStage`, `ExtendListStage`, `FilterListStage`, `UniqueListStage`, `PopListStage` |
|
|
382
|
+
| dicts | `PickKeysStage`, `DropKeysStage` |
|
|
383
|
+
| strings | `ConcatStage`, `TemplateStage` |
|
|
384
|
+
| logic | `AssertStage`, `FailStage`, `LogStage`, `SleepStage` |
|
|
385
|
+
|
|
386
|
+
All of them return new values and never mutate their input.
|
|
387
|
+
|
|
388
|
+
## Stage specification
|
|
389
|
+
|
|
390
|
+
A stage is specified by YAML in its docstring: `description`, `arguments`,
|
|
391
|
+
`outputs`, plus visual hints for the editor.
|
|
392
|
+
|
|
393
|
+
```yaml
|
|
394
|
+
description: "Increment numeric value by delta"
|
|
395
|
+
icon: "+" # glyph, SVG link, data URI or inline <svg> markup
|
|
396
|
+
icon_mono: false # recolour the SVG to the node colour (monochrome sets)
|
|
397
|
+
color: "#ff8800" # card accent (defaults to the category colour)
|
|
398
|
+
```
|
|
399
|
+
|
|
400
|
+
`icon` accepts four forms:
|
|
401
|
+
|
|
402
|
+
| Value | What gets drawn |
|
|
403
|
+
|---|---|
|
|
404
|
+
| `"+"`, `"👋"` | the glyph or emoji itself |
|
|
405
|
+
| `"/icons/globe.svg"`, `"https://…/x.svg"` | an SVG by link |
|
|
406
|
+
| `"data:image/svg+xml;utf8,…"` | a data URI |
|
|
407
|
+
| `"<svg …>…</svg>"` | markup straight from the docstring |
|
|
408
|
+
|
|
409
|
+
`icon_mono: true` draws the SVG as a mask in the node colour, which suits
|
|
410
|
+
monochrome sets (lucide, feather, tabler) that paint via `currentColor`.
|
|
411
|
+
Without `icon` the editor draws a monogram of the stage name
|
|
412
|
+
(`IncrementStage` → `IS`); without `color` it picks a deterministic colour for
|
|
413
|
+
the category.
|
|
414
|
+
|
|
415
|
+
A stage may also declare `allowed_events` and `allowed_inputs` (`EventSpec` /
|
|
416
|
+
`InputSpec` with a `payload_schema`), a `category` and a `timeout`. All of it
|
|
417
|
+
ends up in `get_specs()`.
|
|
418
|
+
|
|
419
|
+
## Schema and stage specifications
|
|
420
|
+
|
|
421
|
+
The pipeline JSON Schema and the specifications of registered stages:
|
|
422
|
+
|
|
423
|
+
```python
|
|
424
|
+
from stageflow.docs import generate_pipeline_schema, generate_stages_json, load_pipeline_schema
|
|
425
|
+
from stageflow import get_stages
|
|
426
|
+
|
|
427
|
+
schema = generate_pipeline_schema(get_stages()) # schema with the stage-name enum
|
|
428
|
+
stages = generate_stages_json(get_stages()) # stage specs for an editor
|
|
429
|
+
```
|
|
430
|
+
|
|
431
|
+
`load_pipeline_schema()` returns the schema without the injected enum; it is
|
|
432
|
+
the one `Pipeline.validate()` uses. These two functions supply everything an
|
|
433
|
+
external tool needs: an editor, a CI validator, a documentation generator.
|
|
434
|
+
|
|
435
|
+
## Tests
|
|
436
|
+
|
|
437
|
+
```bash
|
|
438
|
+
python -m unittest discover -s tests
|
|
439
|
+
```
|
|
440
|
+
|
|
441
|
+
For declarative pipeline testing there is `stageflow.testing`:
|
|
442
|
+
|
|
443
|
+
```python
|
|
444
|
+
from stageflow.testing import PipelineTestSpec, run_pipeline_test
|
|
445
|
+
```
|
|
446
|
+
|
|
447
|
+
## Releasing
|
|
448
|
+
|
|
449
|
+
Pushing a tag builds the package and publishes it to PyPI
|
|
450
|
+
(`.github/workflows/publish.yml`):
|
|
451
|
+
|
|
452
|
+
```bash
|
|
453
|
+
# bump project.version in pyproject.toml first — the workflow refuses
|
|
454
|
+
# a tag that does not match it
|
|
455
|
+
git tag -a 1.0.0 -m "StageFlow 1.0.0"
|
|
456
|
+
git push origin 1.0.0
|
|
457
|
+
```
|
|
458
|
+
|
|
459
|
+
The workflow runs the test suite, builds an sdist and a wheel, validates both
|
|
460
|
+
with `twine check`, and uploads them through PyPI Trusted Publishing, so no
|
|
461
|
+
API token is stored in the repository. The upload step runs in the `pypi`
|
|
462
|
+
environment, which can be configured to require a manual approval.
|
|
463
|
+
|
|
464
|
+
## License
|
|
465
|
+
|
|
466
|
+
MIT — see [LICENSE](LICENSE).
|
|
467
|
+
|
|
468
|
+
## Package layout
|
|
469
|
+
|
|
470
|
+
```
|
|
471
|
+
stageflow/
|
|
472
|
+
core/ the engine: pipeline, session, nodes/, context, cel, stage, typesys, inputs, debug
|
|
473
|
+
builtins/ built-in stages
|
|
474
|
+
docs/ pipeline JSON Schema and stage specifications
|
|
475
|
+
exceptions.py exception hierarchy
|
|
476
|
+
testing.py pipeline testing helper
|
|
477
|
+
tests/ unit tests
|
|
478
|
+
```
|