celestialflow 3.0.1__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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Mr-xiaotian
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,301 @@
1
+ Metadata-Version: 2.4
2
+ Name: celestialflow
3
+ Version: 3.0.1
4
+ Summary: A flexible DAG-based task orchestration framework.
5
+ Author-email: Mr-xiaotian <mingxiaomingtian@gmail.com>
6
+ License: MIT License
7
+
8
+ Copyright (c) 2025 Mr-xiaotian
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+
28
+ Project-URL: Homepage, https://github.com/Mr-xiaotian/CelestialFlow
29
+ Project-URL: Bug Tracker, https://github.com/Mr-xiaotian/CelestialFlow/issues
30
+ Keywords: workflow,task,graph,async,CelestialFlow
31
+ Requires-Python: >=3.8
32
+ Description-Content-Type: text/markdown
33
+ Requires-Dist: tqdm
34
+ Requires-Dist: loguru
35
+ Requires-Dist: fastapi
36
+ Requires-Dist: uvicorn
37
+ Requires-Dist: requests
38
+ Requires-Dist: networkx
39
+ Requires-Dist: redis
40
+ Requires-Dist: httpx
41
+ Requires-Dist: jinja2
42
+
43
+ # CelestialFlow ——一个轻量级、可并行、基于图结构的 Python 任务调度框架
44
+
45
+ ![](img/startup.png)
46
+
47
+ **CelestialFlow**是一个基于节点拼接的任务流调度框架。
48
+
49
+ 框架的基本单元为 **TaskStage**(由 `TaskManager` 派生),每个 stage 内部绑定一个独立的执行函数,并支持四种运行模式:
50
+
51
+ * **线性(serial)**
52
+ * **多线程(thread)**
53
+ * **多进程(process)**
54
+ * **协程(async)**
55
+
56
+ 每个 stage 均可独立运行,也可作为节点互相连接,形成具有上游与下游依赖关系的任务图(**TaskGraph**)。下游 stage 会自动接收上游执行完成的结果作为输入,从而实现数据的流动与传递。
57
+
58
+ 在图级别上,TaskGraph 支持两种布局模式:
59
+
60
+ * **线性执行(serial layout)**:前一节点执行完毕后再启动下一节点(下游节点可提前接收任务但不会立即执行)。
61
+ * **并行执行(process layout)**:所有节点同时启动运行,由队列自动协调任务传递与依赖顺序。
62
+
63
+ TaskGraph 能构建完整的 **有向图结构(Directed Graph)**,不仅支持传统的有向无环图(DAG),也能灵活表达 **环形(loop)** 与 **复杂交叉** 的任务依赖。
64
+
65
+ 在次基础上项目支持 Web 可视化与通过 Redis 外接go代码,弥补 Python 在cpu密集任务上表现欠佳的问题。
66
+
67
+ ## 快速开始(Quick Start)
68
+
69
+ 本节将引导你快速安装并运行 **TaskGraph**,通过示例体验其任务图调度机制。
70
+
71
+
72
+ ### 克隆项目并创建虚拟环境
73
+
74
+ 首先从 GitHub 拉取代码仓库,并创建隔离环境以防依赖冲突。
75
+
76
+ ```bash
77
+ # 克隆项目
78
+ git clone https://github.com/yourname/TaskGraph.git
79
+ cd TaskGraph
80
+
81
+ # (可选) 用mamba创建虚拟环境
82
+ mamba create -n celestialflow_env python=3.10
83
+ mamba activate celestialflow_env
84
+ ```
85
+
86
+ 如果你了解python的包管理工具Anaconda,那么mamba就是将其用C++实现的版本,相比原版有明显的速度提升。你可以在这里获取它的最新版:
87
+
88
+ 👉 [miniforge/Releases](https://github.com/conda-forge/miniforge/releases)
89
+
90
+ ### 安装依赖与环境初始化
91
+
92
+ ```bash
93
+ pip install .
94
+ ```
95
+
96
+ 或开发模式安装(如果你打算修改代码并实时看到结果):
97
+
98
+ ```bash
99
+ pip install -e .
100
+ ```
101
+
102
+ ### 启动 Web 可视化(可选)
103
+
104
+ Web监视界面并不是必须的,但页面设计还不错,推荐使用:
105
+
106
+ ```bash
107
+ python src/celestialflow/task_web.py 5005
108
+ ```
109
+
110
+ 默认监听端口 `5000`,但为了避免冲突,测试代码中使用的都是端口 `5005`,访问:
111
+
112
+ 👉 [http://localhost:5005](http://localhost:5005)
113
+
114
+ 可查看任务结构、执行状态、错误日志、以及实时注入任务等功能。
115
+
116
+ ![](img/web_display.png)
117
+
118
+ ### 运行测试示例
119
+
120
+ 项目提供了多个位于 `tests/` 目录下的示例文件,用于快速了解框架特性。
121
+ 推荐先运行以下两个示例:
122
+
123
+ ```bash
124
+ pytest tests/test_graph.py::test_graph_1
125
+ pytest tests/test_nodes.py::test_splitter_1
126
+ ```
127
+
128
+ 为了保证测试正常运行, 请先安装必要的测试库:
129
+ ```bash
130
+ pip install pytest pytest-asyncio
131
+ ```
132
+
133
+ - test_nodes_1() 在一个简单的树状任务模型下,对比了四种运行组合(节点模式:serial / process × 执行模式:serial / thread),以测试不同调度策略下的整体性能差异。图结构如下:
134
+ ```
135
+ +----------------------------------------------------------------------+
136
+ | Stage_A (stage_mode: serial, func: sleep_random_A) |
137
+ | ╘-->Stage_B (stage_mode: serial, func: sleep_random_B) |
138
+
139
+ - test_graph_1() 在一个简单的树状任务模型下,对比了四种运行组合(节点模式:serial / process × 执行模式:serial / thread),以测试不同调度策略下的整体性能差异。图结构如下:
140
+ ```
141
+ +----------------------------------------------------------------------+
142
+ | Stage_A (stage_mode: serial, func: sleep_random_A) |
143
+ | ╘-->Stage_B (stage_mode: serial, func: sleep_random_B) |
144
+ | ╘-->Stage_D (stage_mode: serial, func: sleep_random_D) |
145
+ | ╘-->Stage_F (stage_mode: serial, func: sleep_random_F) |
146
+ | ╘-->Stage_E (stage_mode: serial, func: sleep_random_E) |
147
+ | ╘-->Stage_C (stage_mode: serial, func: sleep_random_C) |
148
+ | ╘-->Stage_E (stage_mode: serial, func: sleep_random_E) [Visited] |
149
+ +----------------------------------------------------------------------+
150
+ ```
151
+ - test_splitter_1() 模拟了一个爬虫程序的执行流程:从入口页面开始抓取,并在解析过程中动态生成新的爬取任务并返回上游抓取节点;下游节点负责数据清洗与结果处理。图结构如下:
152
+ ```
153
+ +--------------------------------------------------------------------------------+
154
+ | GenURLs (stage_mode: process, func: generate_urls_sleep) |
155
+ | ╘-->Loger (stage_mode: process, func: log_urls_sleep) |
156
+ | ╘-->Splitter (stage_mode: process, func: _split_task) |
157
+ | ╘-->Downloader (stage_mode: process, func: download_sleep) |
158
+ | ╘-->Parser (stage_mode: process, func: parse_sleep) |
159
+ | ╘-->GenURLs (stage_mode: process, func: generate_urls_sleep) [Visited] |
160
+ +--------------------------------------------------------------------------------+
161
+ ```
162
+
163
+ 在代码运行过程中可以通过Web监视页面查看运行情况。
164
+
165
+ ### 我还想了解更多
166
+
167
+ 你可以继续运行更多的测试代码,这里有介绍每个测试文件与里面的测试函数:
168
+ [Test RREADME.md](tests/README.md)
169
+
170
+ 你也可以了解具体的项目文件,以下文档会帮助你:
171
+
172
+ [Src README.md](src\celestialflow/README.md)
173
+
174
+ 如果你想得到一个最简单的可运行代码:
175
+
176
+ ```python
177
+ from celestialflow import TaskManager, TaskGraph
178
+
179
+ def add(x, y):
180
+ return x + y
181
+
182
+ def square(x):
183
+ return x ** 2
184
+
185
+ if __name__ == "__main__":
186
+ # 定义两个任务节点
187
+ stage1 = TaskManager(add, execution_mode="thread", unpack_task_args=True)
188
+ stage2 = TaskManager(square, execution_mode="thread")
189
+
190
+ # 构建任务图结构
191
+ stage1.set_graph_context([stage2], stage_mode="process", stage_name="Adder")
192
+ stage2.set_graph_context([], stage_mode="process", stage_name="Squarer")
193
+ graph = TaskGraph([stage1])
194
+
195
+ # 初始化任务并启动
196
+ graph.start_graph({stage1.get_stage_tag(): [(1, 2), (3, 4), (5, 6)]})
197
+ ```
198
+
199
+ 请不要在.ipynb中运行。
200
+
201
+ ## 环境要求(Requirements)
202
+
203
+ **CelestialFlow** 依赖以下主要组件,请确保你的环境满足最低版本要求。
204
+
205
+ | 依赖包 | 说明 |
206
+ | ---------------- | ----------------------------------- |
207
+ | **Python ≥ 3.8** | 运行环境 |
208
+ | **fastapi** | Web 服务接口框架 |
209
+ | **uvicorn** | FastAPI 的高性能 ASGI 服务器 |
210
+ | **redis** | 可选组件,用于分布式任务通信(TaskRedisTransfer) |
211
+ | **pytest** | 单元测试框架 |
212
+ | **multiprocess** | 多进程支持库 |
213
+ | **rich** | 终端输出与日志美化 |
214
+ | **jinja2** | FastAPI 模板引擎 |
215
+
216
+ ## 项目结构(Project Structure)
217
+
218
+ 以下视图由我的另一个项目[CelestialVault](https://github.com/Mr-xiaotian/CelestialVault)中inst_file生成。
219
+
220
+ ```
221
+ 📁 CelestialFlow (24MB 349KB 185B)
222
+ 📁 experiment (9KB 455B)
223
+ 🐍 experiment_queue.py (4KB 1B)
224
+ 🐍 experiment_redis.py (5KB 454B)
225
+ 📁 go_worker (6MB 967KB 64B)
226
+ 📁 worker (5KB 684B)
227
+ 🌀 parser.go (394B)
228
+ 🌀 processor.go (2KB 612B)
229
+ 🌀 types.go (237B)
230
+ 🌀 worker.go (2KB 465B)
231
+ ❓ go.mod (258B)
232
+ ❓ go.sum (591B)
233
+ ❓ go_worker.exe (6MB 960KB)
234
+ 🌀 main.go (579B)
235
+ 📁 img (129KB 545B)
236
+ 📷 startup.png (836KB)
237
+ 📷 web_display.png (129KB 545B)
238
+ 📁 src (1MB 855KB 679B)
239
+ 📁 celestialflow (1MB 854KB 576B)
240
+ 📁 static (1MB 418KB 529B)
241
+ 📁 css (32KB 164B)
242
+ 🎨 base.css (6KB 114B)
243
+ 🎨 dashboard.css (8KB 463B)
244
+ 🎨 errors.css (5KB 168B)
245
+ 🎨 inject.css (12KB 443B)
246
+ 📁 js (34KB 267B)
247
+ 📜 main.js (4KB 973B)
248
+ 📜 task_errors.js (4KB 544B)
249
+ 📜 task_injection.js (8KB 437B)
250
+ 📜 task_statuses.js (8KB 63B)
251
+ 📜 task_structure.js (6KB 620B)
252
+ 📜 task_topology.js (261B)
253
+ 📜 utils.js (1KB 441B)
254
+ ❓ favicon.ico (1MB 352KB 98B)
255
+ 📁 templates (12KB 924B)
256
+ 🌐 index.html (12KB 924B)
257
+ 📝 README.md (11KB 385B)
258
+ 🐍 task_graph.py (25KB 477B)
259
+ 🐍 task_logging.py (5KB 369B)
260
+ 🐍 task_manage.py (36KB 81B)
261
+ 🐍 task_nodes.py (4KB 964B)
262
+ 🐍 task_progress.py (1KB 477B)
263
+ 🐍 task_report.py (5KB 996B)
264
+ 🐍 task_structure.py (5KB 776B)
265
+ 🐍 task_tools.py (12KB 72B)
266
+ 🐍 task_types.py (1KB 338B)
267
+ 🐍 task_web.py (4KB 1015B)
268
+ 🐍 __init__.py (910B)
269
+ 📁 tests (97KB 158B)
270
+ 🐍 test_graph.py (5KB 763B)
271
+ 🐍 test_manage.py (1KB 721B)
272
+ 🐍 test_nodes.py (9KB 173B)
273
+ 🐍 test_structure.py (10KB 827B)
274
+ ❓ .gitignore (271B)
275
+ ❓ Makefile (501B)
276
+ ⚙️ pytest.ini (254B)
277
+ 📝 README.md (1KB 124B)
278
+ 🐍 setup.py (550B)
279
+ ```
280
+
281
+ ## 更新日志(Change Log)
282
+
283
+ - [2021] 建立一个支持多线程与单线程处理函数的类
284
+ - [2023] 在GPT4帮助下添加多进程与携程运行模式
285
+ - [5/9/2024] 将原有的处理类抽象为节点, 添加TaskChain类, 可以线性连接多个节点, 并设定节点在Chain中的运行模式, 支持serial和process两种, 后者Chain所有节点同时运行
286
+ - [12/12/2024-12/16/2024] 在原有链式结构基础上允许节点有复数下级节点, 实现Tree结构; 将原有TaskChain改名为TaskTree
287
+ - [3/16/2025] 支持web端任务完成情况可视化
288
+ - [6/9/2025] 支持节点拥有复数上级节点, 脱离纯Tree结构, 为之后循环图做准备
289
+ - [6/11/2025] 自[CelestialVault](https://github.com/Mr-xiaotian/CelestialVault)项目instances.inst_task迁入
290
+ - [6/12/2025] 支持循环图, 下级节点可指向上级节点
291
+ - [6/13/2025] 支持loop结构, 即节点可指向自己
292
+ - [6/14/2025] 支持forest结构, 即可有多个根节点
293
+ - [6/16/2025] 多轮评测后, 当前框架已支持完整有向图结构, 故将TaskTree改名为TaskGraph
294
+
295
+ ## License
296
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
297
+
298
+ ## 作者
299
+ Author: Mr-xiaotian
300
+ Email: mingxiaomingtian@gmail.com
301
+ Project Link: [https://github.com/Mr-xiaotian/CelestialFlow](https://github.com/Mr-xiaotian/CelestialFlow)
@@ -0,0 +1,259 @@
1
+ # CelestialFlow ——一个轻量级、可并行、基于图结构的 Python 任务调度框架
2
+
3
+ ![](img/startup.png)
4
+
5
+ **CelestialFlow**是一个基于节点拼接的任务流调度框架。
6
+
7
+ 框架的基本单元为 **TaskStage**(由 `TaskManager` 派生),每个 stage 内部绑定一个独立的执行函数,并支持四种运行模式:
8
+
9
+ * **线性(serial)**
10
+ * **多线程(thread)**
11
+ * **多进程(process)**
12
+ * **协程(async)**
13
+
14
+ 每个 stage 均可独立运行,也可作为节点互相连接,形成具有上游与下游依赖关系的任务图(**TaskGraph**)。下游 stage 会自动接收上游执行完成的结果作为输入,从而实现数据的流动与传递。
15
+
16
+ 在图级别上,TaskGraph 支持两种布局模式:
17
+
18
+ * **线性执行(serial layout)**:前一节点执行完毕后再启动下一节点(下游节点可提前接收任务但不会立即执行)。
19
+ * **并行执行(process layout)**:所有节点同时启动运行,由队列自动协调任务传递与依赖顺序。
20
+
21
+ TaskGraph 能构建完整的 **有向图结构(Directed Graph)**,不仅支持传统的有向无环图(DAG),也能灵活表达 **环形(loop)** 与 **复杂交叉** 的任务依赖。
22
+
23
+ 在次基础上项目支持 Web 可视化与通过 Redis 外接go代码,弥补 Python 在cpu密集任务上表现欠佳的问题。
24
+
25
+ ## 快速开始(Quick Start)
26
+
27
+ 本节将引导你快速安装并运行 **TaskGraph**,通过示例体验其任务图调度机制。
28
+
29
+
30
+ ### 克隆项目并创建虚拟环境
31
+
32
+ 首先从 GitHub 拉取代码仓库,并创建隔离环境以防依赖冲突。
33
+
34
+ ```bash
35
+ # 克隆项目
36
+ git clone https://github.com/yourname/TaskGraph.git
37
+ cd TaskGraph
38
+
39
+ # (可选) 用mamba创建虚拟环境
40
+ mamba create -n celestialflow_env python=3.10
41
+ mamba activate celestialflow_env
42
+ ```
43
+
44
+ 如果你了解python的包管理工具Anaconda,那么mamba就是将其用C++实现的版本,相比原版有明显的速度提升。你可以在这里获取它的最新版:
45
+
46
+ 👉 [miniforge/Releases](https://github.com/conda-forge/miniforge/releases)
47
+
48
+ ### 安装依赖与环境初始化
49
+
50
+ ```bash
51
+ pip install .
52
+ ```
53
+
54
+ 或开发模式安装(如果你打算修改代码并实时看到结果):
55
+
56
+ ```bash
57
+ pip install -e .
58
+ ```
59
+
60
+ ### 启动 Web 可视化(可选)
61
+
62
+ Web监视界面并不是必须的,但页面设计还不错,推荐使用:
63
+
64
+ ```bash
65
+ python src/celestialflow/task_web.py 5005
66
+ ```
67
+
68
+ 默认监听端口 `5000`,但为了避免冲突,测试代码中使用的都是端口 `5005`,访问:
69
+
70
+ 👉 [http://localhost:5005](http://localhost:5005)
71
+
72
+ 可查看任务结构、执行状态、错误日志、以及实时注入任务等功能。
73
+
74
+ ![](img/web_display.png)
75
+
76
+ ### 运行测试示例
77
+
78
+ 项目提供了多个位于 `tests/` 目录下的示例文件,用于快速了解框架特性。
79
+ 推荐先运行以下两个示例:
80
+
81
+ ```bash
82
+ pytest tests/test_graph.py::test_graph_1
83
+ pytest tests/test_nodes.py::test_splitter_1
84
+ ```
85
+
86
+ 为了保证测试正常运行, 请先安装必要的测试库:
87
+ ```bash
88
+ pip install pytest pytest-asyncio
89
+ ```
90
+
91
+ - test_nodes_1() 在一个简单的树状任务模型下,对比了四种运行组合(节点模式:serial / process × 执行模式:serial / thread),以测试不同调度策略下的整体性能差异。图结构如下:
92
+ ```
93
+ +----------------------------------------------------------------------+
94
+ | Stage_A (stage_mode: serial, func: sleep_random_A) |
95
+ | ╘-->Stage_B (stage_mode: serial, func: sleep_random_B) |
96
+
97
+ - test_graph_1() 在一个简单的树状任务模型下,对比了四种运行组合(节点模式:serial / process × 执行模式:serial / thread),以测试不同调度策略下的整体性能差异。图结构如下:
98
+ ```
99
+ +----------------------------------------------------------------------+
100
+ | Stage_A (stage_mode: serial, func: sleep_random_A) |
101
+ | ╘-->Stage_B (stage_mode: serial, func: sleep_random_B) |
102
+ | ╘-->Stage_D (stage_mode: serial, func: sleep_random_D) |
103
+ | ╘-->Stage_F (stage_mode: serial, func: sleep_random_F) |
104
+ | ╘-->Stage_E (stage_mode: serial, func: sleep_random_E) |
105
+ | ╘-->Stage_C (stage_mode: serial, func: sleep_random_C) |
106
+ | ╘-->Stage_E (stage_mode: serial, func: sleep_random_E) [Visited] |
107
+ +----------------------------------------------------------------------+
108
+ ```
109
+ - test_splitter_1() 模拟了一个爬虫程序的执行流程:从入口页面开始抓取,并在解析过程中动态生成新的爬取任务并返回上游抓取节点;下游节点负责数据清洗与结果处理。图结构如下:
110
+ ```
111
+ +--------------------------------------------------------------------------------+
112
+ | GenURLs (stage_mode: process, func: generate_urls_sleep) |
113
+ | ╘-->Loger (stage_mode: process, func: log_urls_sleep) |
114
+ | ╘-->Splitter (stage_mode: process, func: _split_task) |
115
+ | ╘-->Downloader (stage_mode: process, func: download_sleep) |
116
+ | ╘-->Parser (stage_mode: process, func: parse_sleep) |
117
+ | ╘-->GenURLs (stage_mode: process, func: generate_urls_sleep) [Visited] |
118
+ +--------------------------------------------------------------------------------+
119
+ ```
120
+
121
+ 在代码运行过程中可以通过Web监视页面查看运行情况。
122
+
123
+ ### 我还想了解更多
124
+
125
+ 你可以继续运行更多的测试代码,这里有介绍每个测试文件与里面的测试函数:
126
+ [Test RREADME.md](tests/README.md)
127
+
128
+ 你也可以了解具体的项目文件,以下文档会帮助你:
129
+
130
+ [Src README.md](src\celestialflow/README.md)
131
+
132
+ 如果你想得到一个最简单的可运行代码:
133
+
134
+ ```python
135
+ from celestialflow import TaskManager, TaskGraph
136
+
137
+ def add(x, y):
138
+ return x + y
139
+
140
+ def square(x):
141
+ return x ** 2
142
+
143
+ if __name__ == "__main__":
144
+ # 定义两个任务节点
145
+ stage1 = TaskManager(add, execution_mode="thread", unpack_task_args=True)
146
+ stage2 = TaskManager(square, execution_mode="thread")
147
+
148
+ # 构建任务图结构
149
+ stage1.set_graph_context([stage2], stage_mode="process", stage_name="Adder")
150
+ stage2.set_graph_context([], stage_mode="process", stage_name="Squarer")
151
+ graph = TaskGraph([stage1])
152
+
153
+ # 初始化任务并启动
154
+ graph.start_graph({stage1.get_stage_tag(): [(1, 2), (3, 4), (5, 6)]})
155
+ ```
156
+
157
+ 请不要在.ipynb中运行。
158
+
159
+ ## 环境要求(Requirements)
160
+
161
+ **CelestialFlow** 依赖以下主要组件,请确保你的环境满足最低版本要求。
162
+
163
+ | 依赖包 | 说明 |
164
+ | ---------------- | ----------------------------------- |
165
+ | **Python ≥ 3.8** | 运行环境 |
166
+ | **fastapi** | Web 服务接口框架 |
167
+ | **uvicorn** | FastAPI 的高性能 ASGI 服务器 |
168
+ | **redis** | 可选组件,用于分布式任务通信(TaskRedisTransfer) |
169
+ | **pytest** | 单元测试框架 |
170
+ | **multiprocess** | 多进程支持库 |
171
+ | **rich** | 终端输出与日志美化 |
172
+ | **jinja2** | FastAPI 模板引擎 |
173
+
174
+ ## 项目结构(Project Structure)
175
+
176
+ 以下视图由我的另一个项目[CelestialVault](https://github.com/Mr-xiaotian/CelestialVault)中inst_file生成。
177
+
178
+ ```
179
+ 📁 CelestialFlow (24MB 349KB 185B)
180
+ 📁 experiment (9KB 455B)
181
+ 🐍 experiment_queue.py (4KB 1B)
182
+ 🐍 experiment_redis.py (5KB 454B)
183
+ 📁 go_worker (6MB 967KB 64B)
184
+ 📁 worker (5KB 684B)
185
+ 🌀 parser.go (394B)
186
+ 🌀 processor.go (2KB 612B)
187
+ 🌀 types.go (237B)
188
+ 🌀 worker.go (2KB 465B)
189
+ ❓ go.mod (258B)
190
+ ❓ go.sum (591B)
191
+ ❓ go_worker.exe (6MB 960KB)
192
+ 🌀 main.go (579B)
193
+ 📁 img (129KB 545B)
194
+ 📷 startup.png (836KB)
195
+ 📷 web_display.png (129KB 545B)
196
+ 📁 src (1MB 855KB 679B)
197
+ 📁 celestialflow (1MB 854KB 576B)
198
+ 📁 static (1MB 418KB 529B)
199
+ 📁 css (32KB 164B)
200
+ 🎨 base.css (6KB 114B)
201
+ 🎨 dashboard.css (8KB 463B)
202
+ 🎨 errors.css (5KB 168B)
203
+ 🎨 inject.css (12KB 443B)
204
+ 📁 js (34KB 267B)
205
+ 📜 main.js (4KB 973B)
206
+ 📜 task_errors.js (4KB 544B)
207
+ 📜 task_injection.js (8KB 437B)
208
+ 📜 task_statuses.js (8KB 63B)
209
+ 📜 task_structure.js (6KB 620B)
210
+ 📜 task_topology.js (261B)
211
+ 📜 utils.js (1KB 441B)
212
+ ❓ favicon.ico (1MB 352KB 98B)
213
+ 📁 templates (12KB 924B)
214
+ 🌐 index.html (12KB 924B)
215
+ 📝 README.md (11KB 385B)
216
+ 🐍 task_graph.py (25KB 477B)
217
+ 🐍 task_logging.py (5KB 369B)
218
+ 🐍 task_manage.py (36KB 81B)
219
+ 🐍 task_nodes.py (4KB 964B)
220
+ 🐍 task_progress.py (1KB 477B)
221
+ 🐍 task_report.py (5KB 996B)
222
+ 🐍 task_structure.py (5KB 776B)
223
+ 🐍 task_tools.py (12KB 72B)
224
+ 🐍 task_types.py (1KB 338B)
225
+ 🐍 task_web.py (4KB 1015B)
226
+ 🐍 __init__.py (910B)
227
+ 📁 tests (97KB 158B)
228
+ 🐍 test_graph.py (5KB 763B)
229
+ 🐍 test_manage.py (1KB 721B)
230
+ 🐍 test_nodes.py (9KB 173B)
231
+ 🐍 test_structure.py (10KB 827B)
232
+ ❓ .gitignore (271B)
233
+ ❓ Makefile (501B)
234
+ ⚙️ pytest.ini (254B)
235
+ 📝 README.md (1KB 124B)
236
+ 🐍 setup.py (550B)
237
+ ```
238
+
239
+ ## 更新日志(Change Log)
240
+
241
+ - [2021] 建立一个支持多线程与单线程处理函数的类
242
+ - [2023] 在GPT4帮助下添加多进程与携程运行模式
243
+ - [5/9/2024] 将原有的处理类抽象为节点, 添加TaskChain类, 可以线性连接多个节点, 并设定节点在Chain中的运行模式, 支持serial和process两种, 后者Chain所有节点同时运行
244
+ - [12/12/2024-12/16/2024] 在原有链式结构基础上允许节点有复数下级节点, 实现Tree结构; 将原有TaskChain改名为TaskTree
245
+ - [3/16/2025] 支持web端任务完成情况可视化
246
+ - [6/9/2025] 支持节点拥有复数上级节点, 脱离纯Tree结构, 为之后循环图做准备
247
+ - [6/11/2025] 自[CelestialVault](https://github.com/Mr-xiaotian/CelestialVault)项目instances.inst_task迁入
248
+ - [6/12/2025] 支持循环图, 下级节点可指向上级节点
249
+ - [6/13/2025] 支持loop结构, 即节点可指向自己
250
+ - [6/14/2025] 支持forest结构, 即可有多个根节点
251
+ - [6/16/2025] 多轮评测后, 当前框架已支持完整有向图结构, 故将TaskTree改名为TaskGraph
252
+
253
+ ## License
254
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
255
+
256
+ ## 作者
257
+ Author: Mr-xiaotian
258
+ Email: mingxiaomingtian@gmail.com
259
+ Project Link: [https://github.com/Mr-xiaotian/CelestialFlow](https://github.com/Mr-xiaotian/CelestialFlow)
@@ -0,0 +1,32 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "celestialflow"
7
+ version = "3.0.1"
8
+ description = "A flexible DAG-based task orchestration framework."
9
+ readme = "README.md"
10
+ license = { file = "LICENSE" }
11
+ authors = [{ name = "Mr-xiaotian", email = "mingxiaomingtian@gmail.com " }]
12
+ keywords = ["workflow", "task", "graph", "async", "CelestialFlow"]
13
+ requires-python = ">=3.8"
14
+
15
+ dependencies = [
16
+ "tqdm",
17
+ "loguru",
18
+ "fastapi",
19
+ "uvicorn",
20
+ "requests",
21
+ "networkx",
22
+ "redis",
23
+ "httpx",
24
+ "jinja2",
25
+ ]
26
+
27
+ [project.urls]
28
+ "Homepage" = "https://github.com/Mr-xiaotian/CelestialFlow"
29
+ "Bug Tracker" = "https://github.com/Mr-xiaotian/CelestialFlow/issues"
30
+
31
+ [tool.setuptools]
32
+ license-files = []
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,39 @@
1
+ # -*- coding: utf-8 -*-
2
+ # 版本 3.01
3
+ # 作者:Mr-xiaotian, GPT-4o, GPT-5
4
+ # 时间:11/5/2025
5
+ # Github: https://github.com/Mr-xiaotian/CelestialFlow
6
+
7
+ from .task_graph import TaskGraph
8
+ from .task_manage import TaskManager
9
+ from .task_nodes import TaskSplitter, TaskRedisTransfer
10
+ from .task_structure import (
11
+ TaskChain,
12
+ TaskLoop,
13
+ TaskCross,
14
+ TaskComplete,
15
+ TaskWheel,
16
+ TaskGrid,
17
+ )
18
+ from .task_types import TerminationSignal
19
+ from .task_tools import load_task_by_stage, load_task_by_error, make_hashable, format_table
20
+ from .task_web import TaskWebServer
21
+
22
+ __all__ = [
23
+ "TaskGraph",
24
+ "TaskChain",
25
+ "TaskLoop",
26
+ "TaskCross",
27
+ "TaskComplete",
28
+ "TaskWheel",
29
+ "TaskGrid",
30
+ "TaskManager",
31
+ "TaskSplitter",
32
+ "TaskRedisTransfer",
33
+ "TerminationSignal",
34
+ "TaskWebServer",
35
+ "load_task_by_stage",
36
+ "load_task_by_error",
37
+ "make_hashable",
38
+ "format_table",
39
+ ]