celestialflow 3.0.4__tar.gz → 3.0.6__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.
Files changed (49) hide show
  1. celestialflow-3.0.6/PKG-INFO +351 -0
  2. celestialflow-3.0.6/README.md +326 -0
  3. {celestialflow-3.0.4 → celestialflow-3.0.6}/pyproject.toml +1 -1
  4. {celestialflow-3.0.4 → celestialflow-3.0.6}/src/celestialflow/__init__.py +12 -2
  5. celestialflow-3.0.6/src/celestialflow/adapters/__init__.py +0 -0
  6. celestialflow-3.0.6/src/celestialflow/adapters/celestialtree/__init__.py +2 -0
  7. celestialflow-3.0.6/src/celestialflow/adapters/celestialtree/client.py +184 -0
  8. celestialflow-3.0.6/src/celestialflow/adapters/celestialtree/tools.py +36 -0
  9. {celestialflow-3.0.4 → celestialflow-3.0.6}/src/celestialflow/static/css/dashboard.css +87 -141
  10. {celestialflow-3.0.4 → celestialflow-3.0.6}/src/celestialflow/static/js/main.js +21 -14
  11. {celestialflow-3.0.4 → celestialflow-3.0.6}/src/celestialflow/static/js/task_structure.js +31 -96
  12. celestialflow-3.0.6/src/celestialflow/static/js/task_topology.js +54 -0
  13. {celestialflow-3.0.4 → celestialflow-3.0.6}/src/celestialflow/task_graph.py +63 -23
  14. {celestialflow-3.0.4 → celestialflow-3.0.6}/src/celestialflow/task_logging.py +86 -22
  15. {celestialflow-3.0.4 → celestialflow-3.0.6}/src/celestialflow/task_manage.py +271 -120
  16. celestialflow-3.0.6/src/celestialflow/task_nodes.py +290 -0
  17. {celestialflow-3.0.4 → celestialflow-3.0.6}/src/celestialflow/task_queue.py +31 -15
  18. {celestialflow-3.0.4 → celestialflow-3.0.6}/src/celestialflow/task_report.py +28 -39
  19. {celestialflow-3.0.4 → celestialflow-3.0.6}/src/celestialflow/task_tools.py +38 -81
  20. {celestialflow-3.0.4 → celestialflow-3.0.6}/src/celestialflow/task_types.py +26 -0
  21. {celestialflow-3.0.4 → celestialflow-3.0.6}/src/celestialflow/task_web.py +44 -12
  22. {celestialflow-3.0.4 → celestialflow-3.0.6}/src/celestialflow/templates/index.html +42 -32
  23. celestialflow-3.0.6/src/celestialflow.egg-info/PKG-INFO +351 -0
  24. {celestialflow-3.0.4 → celestialflow-3.0.6}/src/celestialflow.egg-info/SOURCES.txt +4 -0
  25. {celestialflow-3.0.4 → celestialflow-3.0.6}/tests/test_graph.py +27 -11
  26. celestialflow-3.0.6/tests/test_manage.py +119 -0
  27. {celestialflow-3.0.4 → celestialflow-3.0.6}/tests/test_nodes.py +106 -22
  28. {celestialflow-3.0.4 → celestialflow-3.0.6}/tests/test_structure.py +18 -11
  29. celestialflow-3.0.4/PKG-INFO +0 -300
  30. celestialflow-3.0.4/README.md +0 -275
  31. celestialflow-3.0.4/src/celestialflow/static/js/task_topology.js +0 -11
  32. celestialflow-3.0.4/src/celestialflow/task_nodes.py +0 -161
  33. celestialflow-3.0.4/src/celestialflow.egg-info/PKG-INFO +0 -300
  34. celestialflow-3.0.4/tests/test_manage.py +0 -64
  35. {celestialflow-3.0.4 → celestialflow-3.0.6}/setup.cfg +0 -0
  36. {celestialflow-3.0.4 → celestialflow-3.0.6}/src/celestialflow/static/css/base.css +0 -0
  37. {celestialflow-3.0.4 → celestialflow-3.0.6}/src/celestialflow/static/css/errors.css +0 -0
  38. {celestialflow-3.0.4 → celestialflow-3.0.6}/src/celestialflow/static/css/inject.css +0 -0
  39. {celestialflow-3.0.4 → celestialflow-3.0.6}/src/celestialflow/static/favicon.ico +0 -0
  40. {celestialflow-3.0.4 → celestialflow-3.0.6}/src/celestialflow/static/js/task_errors.js +0 -0
  41. {celestialflow-3.0.4 → celestialflow-3.0.6}/src/celestialflow/static/js/task_injection.js +0 -0
  42. {celestialflow-3.0.4 → celestialflow-3.0.6}/src/celestialflow/static/js/task_statuses.js +0 -0
  43. {celestialflow-3.0.4 → celestialflow-3.0.6}/src/celestialflow/static/js/utils.js +0 -0
  44. {celestialflow-3.0.4 → celestialflow-3.0.6}/src/celestialflow/task_progress.py +0 -0
  45. {celestialflow-3.0.4 → celestialflow-3.0.6}/src/celestialflow/task_structure.py +0 -0
  46. {celestialflow-3.0.4 → celestialflow-3.0.6}/src/celestialflow.egg-info/dependency_links.txt +0 -0
  47. {celestialflow-3.0.4 → celestialflow-3.0.6}/src/celestialflow.egg-info/entry_points.txt +0 -0
  48. {celestialflow-3.0.4 → celestialflow-3.0.6}/src/celestialflow.egg-info/requires.txt +0 -0
  49. {celestialflow-3.0.4 → celestialflow-3.0.6}/src/celestialflow.egg-info/top_level.txt +0 -0
@@ -0,0 +1,351 @@
1
+ Metadata-Version: 2.4
2
+ Name: celestialflow
3
+ Version: 3.0.6
4
+ Summary: A flexible GRAPH-based task orchestration framework.
5
+ Author-email: Mr-xiaotian <mingxiaomingtian@gmail.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/Mr-xiaotian/CelestialFlow
8
+ Project-URL: Bug Tracker, https://github.com/Mr-xiaotian/CelestialFlow/issues
9
+ Keywords: workflow,task,graph,async,CelestialFlow
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Framework :: FastAPI
14
+ Classifier: Topic :: Software Development :: Libraries
15
+ Requires-Python: >=3.8
16
+ Description-Content-Type: text/markdown
17
+ Requires-Dist: tqdm
18
+ Requires-Dist: loguru
19
+ Requires-Dist: fastapi
20
+ Requires-Dist: uvicorn
21
+ Requires-Dist: requests
22
+ Requires-Dist: networkx
23
+ Requires-Dist: redis
24
+ Requires-Dist: jinja2
25
+
26
+ # CelestialFlow ——一个轻量级、可并行、基于图结构的 Python 任务调度框架
27
+
28
+ <p align="center">
29
+ <img src="https://raw.githubusercontent.com/Mr-xiaotian/CelestialFlow/main/img/logo.png" width="1080" alt="CelestialFlow Logo">
30
+ </p>
31
+
32
+ <p align="center">
33
+ <a href="https://pypi.org/project/celestialflow/"><img src="https://badge.fury.io/py/celestialflow.svg"></a>
34
+ <a href="https://pepy.tech/projects/celestialflow"><img src="https://static.pepy.tech/personalized-badge/celestialflow?period=total&units=INTERNATIONAL_SYSTEM&left_color=BLACK&right_color=GREEN&left_text=downloads"></a>
35
+ <a href="https://pypi.org/project/celestialflow/"><img src="https://img.shields.io/pypi/l/celestialflow.svg"></a>
36
+ <a href="https://pypi.org/project/celestialflow/"><img src="https://img.shields.io/pypi/pyversions/celestialflow.svg"></a>
37
+ </p>
38
+
39
+ <p align="center">
40
+ <img src="https://img.shields.io/badge/Task%20Graph-DAG-blueviolet">
41
+ <img src="https://img.shields.io/badge/Workflow-Orchestrator-7c3aed">
42
+ <img src="https://img.shields.io/badge/IPC-Redis%20Ready-red">
43
+ <img src="https://img.shields.io/badge/Distributed-Worker%20Friendly-orange">
44
+ </p>
45
+
46
+ **CelestialFlow** 是一个轻量级但功能完全的任务流框架,适合需要 **复杂依赖关系**、**灵活执行模型**、**跨设备运行**与**实时可视化监控** 的中/大型 Python 任务系统。
47
+
48
+ - 相比 Airflow/Dagster 更轻、更快开始
49
+ - 相比 multiprocessing/threading 更结构化,可直接表达 loop / complete graph 等复杂依赖模式
50
+
51
+ 框架的基本单元为 **TaskStage**(由 `TaskManager` 派生),每个 stage 内部绑定一个独立的执行函数,并支持四种运行模式:
52
+
53
+ * **线性(serial)**
54
+ * **多线程(thread)**
55
+ * **多进程(process)**
56
+ * **协程(async)**
57
+
58
+ 每个 stage 均可独立运行,也可作为节点互相连接,形成具有上游与下游依赖关系的任务图(**TaskGraph**)。下游 stage 会自动接收上游执行完成的结果作为输入,从而形成明确的数据流。
59
+
60
+ 在图级别上,每个 Stage 支持两种上下文模式:
61
+
62
+ * **线性执行(serial layout)**:当前节点执行完毕再启动下一节点(下游节点可提前接收任务但不会立即执行)。
63
+ * **并行执行(process layout)**:当前节点启动后立刻前去启动下一节点。
64
+
65
+ TaskGraph 能构建完整的 **有向图结构(Directed Graph)**,不仅支持传统的有向无环图(DAG),也能灵活表达 **树形(Tree)**、**环形(loop)** 乃至于 **完全图(Complete Graph)** 形式的任务依赖。
66
+
67
+ 在此基础上,CelestialFlow 支持 Web 可视化监控,并可通过 Redis 实现跨进程、跨设备协作;同时引入基于 Go 的外部 worker(通过 Redis 通信),用于承载 CPU 密集型任务,弥补 Python 在该场景下的性能瓶颈。
68
+
69
+ ## 项目结构(Project Structure)
70
+
71
+ ```mermaid
72
+ flowchart LR
73
+
74
+ %% ===== TaskGraph =====
75
+ subgraph TG[TaskGraph]
76
+ direction LR
77
+
78
+ S1[TaskStage A]
79
+ S2[TaskStage B]
80
+ S3[TaskStage C]
81
+ S4[TaskStage D]
82
+
83
+ T1[Last Stage]
84
+ T2[Next Stage]
85
+
86
+ TS[[TaskSplitter]]
87
+ TRSI1[/TaskRedisSink/]
88
+ TRSI2[/TaskRedisSink/]
89
+ TRSO[/TaskRedisSource/]
90
+ TRA[/TaskRedisAck/]
91
+
92
+ RE1[(Redis)]
93
+ RE2[(Redis)]
94
+ G1((GoWorker))
95
+ G2((GoWorker))
96
+
97
+ S1 --> S2 --> S3 --> S1
98
+ S1 --> S4
99
+
100
+ T1 -->|1 task| TS
101
+ TS -->|N task| T2
102
+
103
+ TRSI1 -.-> RE1 -.-> TRSO
104
+ TRSI2 -.->|task| RE2 -.->|task| G1
105
+ G2 -.->|result| RE2 -.->|result| TRA
106
+
107
+ end
108
+
109
+ %% 美化 TaskGraph 外框
110
+ style TG fill:#e8f2ff,stroke:#6b93d6,stroke-width:2px,color:#0b1e3f,rx:10px,ry:10px
111
+
112
+ %% 统一美化格式
113
+ classDef blueNode fill:#ffffff,stroke:#6b93d6,rx:6px,ry:6px;
114
+
115
+ %% 美化 TaskStages
116
+ class S1,S2,S3,S4 blueNode;
117
+ class T1,T2 blueNode;
118
+
119
+ %% 美化 特殊Stage
120
+ class TS,TRA,TRSI1,TRSI2,TRSO blueNode;
121
+
122
+ %% 美化 外部结构
123
+ class RE1,RE2,G1,G2 blueNode;
124
+
125
+ %% ===== WebUI =====
126
+ subgraph W[WebUI]
127
+ JS
128
+ HTML
129
+ end
130
+
131
+ style W fill:#ffeaf0,stroke:#d66b8c,stroke-width:2px,rx:10px,ry:10px
132
+ style JS fill:#ffffff,stroke:#d66b8c,rx:5px,ry:5px
133
+ style HTML fill:#ffffff,stroke:#d66b8c,rx:5px,ry:5px
134
+
135
+ R[TaskWeb]
136
+ style R fill:#f0e9ff,stroke:#8a6bc9,stroke-width:2px,rx:8px,ry:8px
137
+
138
+ %% ===== Links =====
139
+ TG --> R
140
+ R --> TG
141
+ R --> W
142
+ W --> R
143
+
144
+ ```
145
+
146
+ ## 快速开始(Quick Start)
147
+
148
+ 安装 CelestialFlow:
149
+
150
+ ```bash
151
+ pip install celestialflow
152
+ ```
153
+
154
+ 一个简单的可运行代码:
155
+
156
+ ```python
157
+ from celestialflow import TaskManager, TaskGraph
158
+
159
+ def add(x, y):
160
+ return x + y
161
+
162
+ def square(x):
163
+ return x ** 2
164
+
165
+ if __name__ == "__main__":
166
+ # 定义两个任务节点
167
+ stage1 = TaskManager(add, execution_mode="thread", unpack_task_args=True)
168
+ stage2 = TaskManager(square, execution_mode="thread")
169
+
170
+ # 构建任务图结构
171
+ stage1.set_graph_context([stage2], stage_mode="process", stage_name="Adder")
172
+ stage2.set_graph_context([], stage_mode="process", stage_name="Squarer")
173
+ graph = TaskGraph([stage1])
174
+
175
+ # 初始化任务并启动
176
+ graph.start_graph({stage1.get_stage_tag(): [(1, 2), (3, 4), (5, 6)]})
177
+ ```
178
+
179
+ 注意不要在.ipynb中运行。
180
+
181
+ 👉 想查看完整Quick Start,请见[Quick Start](https://github.com/Mr-xiaotian/CelestialFlow/blob/main/docs/quick_start.md)
182
+
183
+ ## 深入阅读(Further Reading)
184
+
185
+ (以下文档完善中)
186
+
187
+ 你可以继续运行更多的测试代码,这里记录了各个测试文件与其中的测试函数说明:
188
+
189
+ [📄tests/README.md](https://github.com/Mr-xiaotian/CelestialFlow/blob/main/tests/README.md)
190
+
191
+ 若你想了解框架的整体结构与核心组件,下面的参考文档会对你有帮助:
192
+
193
+ - [🔧TaskManage/TaskStage概念](https://github.com/Mr-xiaotian/CelestialFlow/blob/main/docs/reference/task_manage.md)
194
+ - [🌐TaskGrapg概念](https://github.com/Mr-xiaotian/CelestialFlow/blob/main/docs/reference/task_graph.md)
195
+ - [📚Go Worker概念](https://github.com/Mr-xiaotian/CelestialFlow/blob/main/docs/reference/go_worker.md)
196
+
197
+ 推荐阅读顺序:
198
+
199
+ ```mermaid
200
+ flowchart TD
201
+ classDef whiteNode fill:#ffffff,stroke:#000000,color:#000000;
202
+
203
+ TM[TaskManage] --> TG[TaskGraph]
204
+ TM --> TP[TaskProgress]
205
+
206
+ TG --> TQ[TaskQueue]
207
+ TG --> TN[TaskNodes]
208
+ TG --> TR[TaskReport]
209
+ TG --> TS[TaskStructure]
210
+
211
+ TR --> TW[TaskWeb]
212
+ TN --> GW[Go Worker]
213
+
214
+ class TM,TG,TP,TQ,TN,TR,TS,TW,GW whiteNode;
215
+ ```
216
+
217
+ 以下三篇可以作为补充阅读:
218
+
219
+ - [TaskTools](https://github.com/Mr-xiaotian/CelestialFlow/blob/main/docs/reference/task_tools.md)
220
+ - [TaskTypes](https://github.com/Mr-xiaotian/CelestialFlow/blob/main/docs/reference/task_types.md)
221
+ - [TaskLogging](https://github.com/Mr-xiaotian/CelestialFlow/blob/main/docs/reference/task_logging.md)
222
+
223
+ 如果你更喜欢通过完整案例理解框架的运行方式,可以参考这篇从零开始构建 TaskGraph 的教程:
224
+
225
+ [📘案例教程](https://github.com/Mr-xiaotian/CelestialFlow/blob/main/docs/tutorial.md)
226
+
227
+ ## 环境要求(Requirements)
228
+
229
+ **CelestialFlow** 基于 Python 3.8+,并依赖以下核心组件。
230
+ 请确保你的环境能够正常安装这些依赖(`pip install celestialflow` 会自动安装)。
231
+
232
+ | 依赖包 | 说明 |
233
+ | ---------------- | ---- |
234
+ | **Python ≥ 3.8** | 运行环境,建议使用 3.10 及以上版本 |
235
+ | **tqdm** | 控制台进度条显示,用于任务执行可视化 |
236
+ | **loguru** | 高性能日志系统,支持多进程安全输出 |
237
+ | **fastapi** | Web 服务接口框架(用于任务可视化与远程控制) |
238
+ | **uvicorn** | FastAPI 的高性能 ASGI 服务器 |
239
+ | **requests** | HTTP 客户端库,用于任务状态上报与远程调用 |
240
+ | **networkx** | 任务图(TaskGraph)结构与依赖分析 |
241
+ | **redis** | 可选组件,用于分布式任务通信(`TaskRedis*` 系列模块) |
242
+ | **jinja2** | FastAPI 模板引擎,用于 Web 可视化界面渲染 |
243
+
244
+ ## 文件结构(File Structure)
245
+
246
+ ```
247
+ 📁 CelestialFlow (205MB 169KB 76B)
248
+ 📁 experiments (14KB 536B)
249
+ 🐍 benchmark_datastructures.py (5KB 796B)
250
+ 🐍 benchmark_hash.py (1KB 284B)
251
+ 🐍 benchmark_queue.py (5KB 185B)
252
+ 🐍 benchmark_tqdm.py (1KB 160B)
253
+ 🐍 experiment_tqdm.py (1KB 135B)
254
+ 📁 go_worker (6MB 967KB 64B)
255
+ 📁 worker (5KB 684B)
256
+ 🌀 parser.go (394B)
257
+ 🌀 processor.go (2KB 612B)
258
+ 🌀 types.go (237B)
259
+ 🌀 worker.go (2KB 465B)
260
+ ❓ go.mod (258B)
261
+ ❓ go.sum (591B)
262
+ ❓ go_worker.exe (6MB 960KB)
263
+ 🌀 main.go (579B)
264
+ 📁 img (966KB 63B)
265
+ 📷 logo.png (836KB 542B)
266
+ 📷 web_display.png (129KB 545B)
267
+ 📁 src (1MB 884KB 224B)
268
+ 📁 celestialflow (1MB 869KB 480B)
269
+ 📁 static (1MB 419KB 510B)
270
+ 📁 css (32KB 568B)
271
+ 🎨 base.css (6KB 155B)
272
+ 🎨 dashboard.css (8KB 435B)
273
+ 🎨 errors.css (5KB 168B)
274
+ 🎨 inject.css (12KB 834B)
275
+ 📁 js (34KB 868B)
276
+ 📜 main.js (4KB 973B)
277
+ 📜 task_errors.js (4KB 544B)
278
+ 📜 task_injection.js (8KB 491B)
279
+ 📜 task_statuses.js (8KB 63B)
280
+ 📜 task_structure.js (7KB 143B)
281
+ 📜 task_topology.js (261B)
282
+ 📜 utils.js (1KB 441B)
283
+ ❓ favicon.ico (1MB 352KB 98B)
284
+ 📁 templates (12KB 973B)
285
+ 🌐 index.html (12KB 973B)
286
+ 📁 [1项排除的目录] (314KB 710B)
287
+ 📝 README.md (13KB 131B)
288
+ 🐍 task_graph.py (22KB 530B)
289
+ 🐍 task_logging.py (6KB 291B)
290
+ 🐍 task_manage.py (32KB 66B)
291
+ 🐍 task_nodes.py (4KB 953B)
292
+ 🐍 task_progress.py (1KB 477B)
293
+ 🐍 task_queue.py (7KB 896B)
294
+ 🐍 task_report.py (5KB 511B)
295
+ 🐍 task_structure.py (6KB 93B)
296
+ 🐍 task_tools.py (15KB 182B)
297
+ 🐍 task_types.py (1KB 461B)
298
+ 🐍 task_web.py (5KB 47B)
299
+ 🐍 __init__.py (817B)
300
+ 📁 celestialflow.egg-info (14KB 768B)
301
+ ❓ PKG-INFO (13KB 363B)
302
+ 📄 [5项排除的文件] (1KB 405B)
303
+ 📁 tests (113KB 510B)
304
+ 📁 [1项排除的目录] (81KB 604B)
305
+ 📝 README.md (7KB 231B)
306
+ 🐍 test_graph.py (5KB 83B)
307
+ 🐍 test_manage.py (1KB 785B)
308
+ 🐍 test_nodes.py (7KB 864B)
309
+ 🐍 test_structure.py (9KB 1015B)
310
+ 📁 [6项排除的目录] (195MB 276KB 932B)
311
+ ❓ .gitignore (264B)
312
+ ❓ LICENSE (1KB 65B)
313
+ ❓ Makefile (501B)
314
+ ❓ pyproject.toml (1KB 223B)
315
+ ⚙️ pytest.ini (254B)
316
+ 📝 README.md (15KB 536B)
317
+ ```
318
+
319
+ (该视图由我的另一个项目[CelestialVault](https://github.com/Mr-xiaotian/CelestialVault)中inst_file生成。)
320
+
321
+ ## 更新日志(Change Log)
322
+
323
+ - 2021: 建立一个支持多线程与单线程处理函数的类
324
+ - 2023: 在GPT4帮助下添加多进程与携程运行模式
325
+ - 5/9/2024: 将原有的处理类抽象为节点, 添加TaskChain类, 可以线性连接多个节点, 并设定节点在Chain中的运行模式, 支持serial和process两种, 后者Chain所有节点同时运行
326
+ - 12/12/2024-12/16/2024: 在原有链式结构基础上允许节点有复数下级节点, 实现Tree结构; 将原有TaskChain改名为TaskTree
327
+ - 3/16/2025: 支持Web端任务完成情况可视化
328
+ - 6/9/2025: 支持节点拥有复数上级节点, 脱离纯Tree结构, 为之后循环图做准备
329
+ - 6/11/2025: 自[CelestialVault](https://github.com/Mr-xiaotian/CelestialVault)项目instances.inst_task迁入
330
+ - 6/12/2025: 支持循环图, 下级节点可指向上级节点
331
+ - 6/13/2025: 支持loop结构, 即节点可指向自己
332
+ - 6/14/2025: 支持forest结构, 即可有多个根节点
333
+ - 6/16/2025: 多轮评测后, 当前框架已支持完整有向图结构, 将TaskTree改名为TaskGraph
334
+ - 3.0.1: 上线Pypi, 可喜可贺
335
+ - 3.0.4: 新增一个抽象结构TaskQueue, 用于表示节点的所有"入边"与"出边"; 恢复未消费任务的保存功能
336
+ - 3.0.5: 删除原有的TaskRedisTransfer节点, 并增添三种新的redis交互节点TaskRedisSink TaskRedisSource TaskRedisAck, 用于跨语言 跨进程 跨设备处理任务; 并在Web页面添加展示拓扑信息的卡片
337
+ - 3.0.6: 添加对[CelestialTree](https://github.com/Mr-xiaotian/CelestialTree)系统的支持, 现在可以追踪单个任务的流向
338
+
339
+ ## Star 历史趋势(Star History)
340
+
341
+ 如果对项目感兴趣的话,欢迎star。如果有问题或者建议的话, 欢迎提交[Issues](https://github.com/Mr-xiaotian/CelestialFlow/issues)或者在[Discussion](https://github.com/Mr-xiaotian/CelestialFlow/discussions)中告诉我。
342
+
343
+ [![Star History Chart](https://api.star-history.com/svg?repos=Mr-xiaotian/CelestialFlow&type=Date)](https://star-history.com/#Mr-xiaotian/CelestialFlow&Date)
344
+
345
+ ## 许可(License)
346
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
347
+
348
+ ## 作者(Author)
349
+ Author: Mr-xiaotian
350
+ Email: mingxiaomingtian@gmail.com
351
+ Project Link: [https://github.com/Mr-xiaotian/CelestialFlow](https://github.com/Mr-xiaotian/CelestialFlow)
@@ -0,0 +1,326 @@
1
+ # CelestialFlow ——一个轻量级、可并行、基于图结构的 Python 任务调度框架
2
+
3
+ <p align="center">
4
+ <img src="https://raw.githubusercontent.com/Mr-xiaotian/CelestialFlow/main/img/logo.png" width="1080" alt="CelestialFlow Logo">
5
+ </p>
6
+
7
+ <p align="center">
8
+ <a href="https://pypi.org/project/celestialflow/"><img src="https://badge.fury.io/py/celestialflow.svg"></a>
9
+ <a href="https://pepy.tech/projects/celestialflow"><img src="https://static.pepy.tech/personalized-badge/celestialflow?period=total&units=INTERNATIONAL_SYSTEM&left_color=BLACK&right_color=GREEN&left_text=downloads"></a>
10
+ <a href="https://pypi.org/project/celestialflow/"><img src="https://img.shields.io/pypi/l/celestialflow.svg"></a>
11
+ <a href="https://pypi.org/project/celestialflow/"><img src="https://img.shields.io/pypi/pyversions/celestialflow.svg"></a>
12
+ </p>
13
+
14
+ <p align="center">
15
+ <img src="https://img.shields.io/badge/Task%20Graph-DAG-blueviolet">
16
+ <img src="https://img.shields.io/badge/Workflow-Orchestrator-7c3aed">
17
+ <img src="https://img.shields.io/badge/IPC-Redis%20Ready-red">
18
+ <img src="https://img.shields.io/badge/Distributed-Worker%20Friendly-orange">
19
+ </p>
20
+
21
+ **CelestialFlow** 是一个轻量级但功能完全的任务流框架,适合需要 **复杂依赖关系**、**灵活执行模型**、**跨设备运行**与**实时可视化监控** 的中/大型 Python 任务系统。
22
+
23
+ - 相比 Airflow/Dagster 更轻、更快开始
24
+ - 相比 multiprocessing/threading 更结构化,可直接表达 loop / complete graph 等复杂依赖模式
25
+
26
+ 框架的基本单元为 **TaskStage**(由 `TaskManager` 派生),每个 stage 内部绑定一个独立的执行函数,并支持四种运行模式:
27
+
28
+ * **线性(serial)**
29
+ * **多线程(thread)**
30
+ * **多进程(process)**
31
+ * **协程(async)**
32
+
33
+ 每个 stage 均可独立运行,也可作为节点互相连接,形成具有上游与下游依赖关系的任务图(**TaskGraph**)。下游 stage 会自动接收上游执行完成的结果作为输入,从而形成明确的数据流。
34
+
35
+ 在图级别上,每个 Stage 支持两种上下文模式:
36
+
37
+ * **线性执行(serial layout)**:当前节点执行完毕再启动下一节点(下游节点可提前接收任务但不会立即执行)。
38
+ * **并行执行(process layout)**:当前节点启动后立刻前去启动下一节点。
39
+
40
+ TaskGraph 能构建完整的 **有向图结构(Directed Graph)**,不仅支持传统的有向无环图(DAG),也能灵活表达 **树形(Tree)**、**环形(loop)** 乃至于 **完全图(Complete Graph)** 形式的任务依赖。
41
+
42
+ 在此基础上,CelestialFlow 支持 Web 可视化监控,并可通过 Redis 实现跨进程、跨设备协作;同时引入基于 Go 的外部 worker(通过 Redis 通信),用于承载 CPU 密集型任务,弥补 Python 在该场景下的性能瓶颈。
43
+
44
+ ## 项目结构(Project Structure)
45
+
46
+ ```mermaid
47
+ flowchart LR
48
+
49
+ %% ===== TaskGraph =====
50
+ subgraph TG[TaskGraph]
51
+ direction LR
52
+
53
+ S1[TaskStage A]
54
+ S2[TaskStage B]
55
+ S3[TaskStage C]
56
+ S4[TaskStage D]
57
+
58
+ T1[Last Stage]
59
+ T2[Next Stage]
60
+
61
+ TS[[TaskSplitter]]
62
+ TRSI1[/TaskRedisSink/]
63
+ TRSI2[/TaskRedisSink/]
64
+ TRSO[/TaskRedisSource/]
65
+ TRA[/TaskRedisAck/]
66
+
67
+ RE1[(Redis)]
68
+ RE2[(Redis)]
69
+ G1((GoWorker))
70
+ G2((GoWorker))
71
+
72
+ S1 --> S2 --> S3 --> S1
73
+ S1 --> S4
74
+
75
+ T1 -->|1 task| TS
76
+ TS -->|N task| T2
77
+
78
+ TRSI1 -.-> RE1 -.-> TRSO
79
+ TRSI2 -.->|task| RE2 -.->|task| G1
80
+ G2 -.->|result| RE2 -.->|result| TRA
81
+
82
+ end
83
+
84
+ %% 美化 TaskGraph 外框
85
+ style TG fill:#e8f2ff,stroke:#6b93d6,stroke-width:2px,color:#0b1e3f,rx:10px,ry:10px
86
+
87
+ %% 统一美化格式
88
+ classDef blueNode fill:#ffffff,stroke:#6b93d6,rx:6px,ry:6px;
89
+
90
+ %% 美化 TaskStages
91
+ class S1,S2,S3,S4 blueNode;
92
+ class T1,T2 blueNode;
93
+
94
+ %% 美化 特殊Stage
95
+ class TS,TRA,TRSI1,TRSI2,TRSO blueNode;
96
+
97
+ %% 美化 外部结构
98
+ class RE1,RE2,G1,G2 blueNode;
99
+
100
+ %% ===== WebUI =====
101
+ subgraph W[WebUI]
102
+ JS
103
+ HTML
104
+ end
105
+
106
+ style W fill:#ffeaf0,stroke:#d66b8c,stroke-width:2px,rx:10px,ry:10px
107
+ style JS fill:#ffffff,stroke:#d66b8c,rx:5px,ry:5px
108
+ style HTML fill:#ffffff,stroke:#d66b8c,rx:5px,ry:5px
109
+
110
+ R[TaskWeb]
111
+ style R fill:#f0e9ff,stroke:#8a6bc9,stroke-width:2px,rx:8px,ry:8px
112
+
113
+ %% ===== Links =====
114
+ TG --> R
115
+ R --> TG
116
+ R --> W
117
+ W --> R
118
+
119
+ ```
120
+
121
+ ## 快速开始(Quick Start)
122
+
123
+ 安装 CelestialFlow:
124
+
125
+ ```bash
126
+ pip install celestialflow
127
+ ```
128
+
129
+ 一个简单的可运行代码:
130
+
131
+ ```python
132
+ from celestialflow import TaskManager, TaskGraph
133
+
134
+ def add(x, y):
135
+ return x + y
136
+
137
+ def square(x):
138
+ return x ** 2
139
+
140
+ if __name__ == "__main__":
141
+ # 定义两个任务节点
142
+ stage1 = TaskManager(add, execution_mode="thread", unpack_task_args=True)
143
+ stage2 = TaskManager(square, execution_mode="thread")
144
+
145
+ # 构建任务图结构
146
+ stage1.set_graph_context([stage2], stage_mode="process", stage_name="Adder")
147
+ stage2.set_graph_context([], stage_mode="process", stage_name="Squarer")
148
+ graph = TaskGraph([stage1])
149
+
150
+ # 初始化任务并启动
151
+ graph.start_graph({stage1.get_stage_tag(): [(1, 2), (3, 4), (5, 6)]})
152
+ ```
153
+
154
+ 注意不要在.ipynb中运行。
155
+
156
+ 👉 想查看完整Quick Start,请见[Quick Start](https://github.com/Mr-xiaotian/CelestialFlow/blob/main/docs/quick_start.md)
157
+
158
+ ## 深入阅读(Further Reading)
159
+
160
+ (以下文档完善中)
161
+
162
+ 你可以继续运行更多的测试代码,这里记录了各个测试文件与其中的测试函数说明:
163
+
164
+ [📄tests/README.md](https://github.com/Mr-xiaotian/CelestialFlow/blob/main/tests/README.md)
165
+
166
+ 若你想了解框架的整体结构与核心组件,下面的参考文档会对你有帮助:
167
+
168
+ - [🔧TaskManage/TaskStage概念](https://github.com/Mr-xiaotian/CelestialFlow/blob/main/docs/reference/task_manage.md)
169
+ - [🌐TaskGrapg概念](https://github.com/Mr-xiaotian/CelestialFlow/blob/main/docs/reference/task_graph.md)
170
+ - [📚Go Worker概念](https://github.com/Mr-xiaotian/CelestialFlow/blob/main/docs/reference/go_worker.md)
171
+
172
+ 推荐阅读顺序:
173
+
174
+ ```mermaid
175
+ flowchart TD
176
+ classDef whiteNode fill:#ffffff,stroke:#000000,color:#000000;
177
+
178
+ TM[TaskManage] --> TG[TaskGraph]
179
+ TM --> TP[TaskProgress]
180
+
181
+ TG --> TQ[TaskQueue]
182
+ TG --> TN[TaskNodes]
183
+ TG --> TR[TaskReport]
184
+ TG --> TS[TaskStructure]
185
+
186
+ TR --> TW[TaskWeb]
187
+ TN --> GW[Go Worker]
188
+
189
+ class TM,TG,TP,TQ,TN,TR,TS,TW,GW whiteNode;
190
+ ```
191
+
192
+ 以下三篇可以作为补充阅读:
193
+
194
+ - [TaskTools](https://github.com/Mr-xiaotian/CelestialFlow/blob/main/docs/reference/task_tools.md)
195
+ - [TaskTypes](https://github.com/Mr-xiaotian/CelestialFlow/blob/main/docs/reference/task_types.md)
196
+ - [TaskLogging](https://github.com/Mr-xiaotian/CelestialFlow/blob/main/docs/reference/task_logging.md)
197
+
198
+ 如果你更喜欢通过完整案例理解框架的运行方式,可以参考这篇从零开始构建 TaskGraph 的教程:
199
+
200
+ [📘案例教程](https://github.com/Mr-xiaotian/CelestialFlow/blob/main/docs/tutorial.md)
201
+
202
+ ## 环境要求(Requirements)
203
+
204
+ **CelestialFlow** 基于 Python 3.8+,并依赖以下核心组件。
205
+ 请确保你的环境能够正常安装这些依赖(`pip install celestialflow` 会自动安装)。
206
+
207
+ | 依赖包 | 说明 |
208
+ | ---------------- | ---- |
209
+ | **Python ≥ 3.8** | 运行环境,建议使用 3.10 及以上版本 |
210
+ | **tqdm** | 控制台进度条显示,用于任务执行可视化 |
211
+ | **loguru** | 高性能日志系统,支持多进程安全输出 |
212
+ | **fastapi** | Web 服务接口框架(用于任务可视化与远程控制) |
213
+ | **uvicorn** | FastAPI 的高性能 ASGI 服务器 |
214
+ | **requests** | HTTP 客户端库,用于任务状态上报与远程调用 |
215
+ | **networkx** | 任务图(TaskGraph)结构与依赖分析 |
216
+ | **redis** | 可选组件,用于分布式任务通信(`TaskRedis*` 系列模块) |
217
+ | **jinja2** | FastAPI 模板引擎,用于 Web 可视化界面渲染 |
218
+
219
+ ## 文件结构(File Structure)
220
+
221
+ ```
222
+ 📁 CelestialFlow (205MB 169KB 76B)
223
+ 📁 experiments (14KB 536B)
224
+ 🐍 benchmark_datastructures.py (5KB 796B)
225
+ 🐍 benchmark_hash.py (1KB 284B)
226
+ 🐍 benchmark_queue.py (5KB 185B)
227
+ 🐍 benchmark_tqdm.py (1KB 160B)
228
+ 🐍 experiment_tqdm.py (1KB 135B)
229
+ 📁 go_worker (6MB 967KB 64B)
230
+ 📁 worker (5KB 684B)
231
+ 🌀 parser.go (394B)
232
+ 🌀 processor.go (2KB 612B)
233
+ 🌀 types.go (237B)
234
+ 🌀 worker.go (2KB 465B)
235
+ ❓ go.mod (258B)
236
+ ❓ go.sum (591B)
237
+ ❓ go_worker.exe (6MB 960KB)
238
+ 🌀 main.go (579B)
239
+ 📁 img (966KB 63B)
240
+ 📷 logo.png (836KB 542B)
241
+ 📷 web_display.png (129KB 545B)
242
+ 📁 src (1MB 884KB 224B)
243
+ 📁 celestialflow (1MB 869KB 480B)
244
+ 📁 static (1MB 419KB 510B)
245
+ 📁 css (32KB 568B)
246
+ 🎨 base.css (6KB 155B)
247
+ 🎨 dashboard.css (8KB 435B)
248
+ 🎨 errors.css (5KB 168B)
249
+ 🎨 inject.css (12KB 834B)
250
+ 📁 js (34KB 868B)
251
+ 📜 main.js (4KB 973B)
252
+ 📜 task_errors.js (4KB 544B)
253
+ 📜 task_injection.js (8KB 491B)
254
+ 📜 task_statuses.js (8KB 63B)
255
+ 📜 task_structure.js (7KB 143B)
256
+ 📜 task_topology.js (261B)
257
+ 📜 utils.js (1KB 441B)
258
+ ❓ favicon.ico (1MB 352KB 98B)
259
+ 📁 templates (12KB 973B)
260
+ 🌐 index.html (12KB 973B)
261
+ 📁 [1项排除的目录] (314KB 710B)
262
+ 📝 README.md (13KB 131B)
263
+ 🐍 task_graph.py (22KB 530B)
264
+ 🐍 task_logging.py (6KB 291B)
265
+ 🐍 task_manage.py (32KB 66B)
266
+ 🐍 task_nodes.py (4KB 953B)
267
+ 🐍 task_progress.py (1KB 477B)
268
+ 🐍 task_queue.py (7KB 896B)
269
+ 🐍 task_report.py (5KB 511B)
270
+ 🐍 task_structure.py (6KB 93B)
271
+ 🐍 task_tools.py (15KB 182B)
272
+ 🐍 task_types.py (1KB 461B)
273
+ 🐍 task_web.py (5KB 47B)
274
+ 🐍 __init__.py (817B)
275
+ 📁 celestialflow.egg-info (14KB 768B)
276
+ ❓ PKG-INFO (13KB 363B)
277
+ 📄 [5项排除的文件] (1KB 405B)
278
+ 📁 tests (113KB 510B)
279
+ 📁 [1项排除的目录] (81KB 604B)
280
+ 📝 README.md (7KB 231B)
281
+ 🐍 test_graph.py (5KB 83B)
282
+ 🐍 test_manage.py (1KB 785B)
283
+ 🐍 test_nodes.py (7KB 864B)
284
+ 🐍 test_structure.py (9KB 1015B)
285
+ 📁 [6项排除的目录] (195MB 276KB 932B)
286
+ ❓ .gitignore (264B)
287
+ ❓ LICENSE (1KB 65B)
288
+ ❓ Makefile (501B)
289
+ ❓ pyproject.toml (1KB 223B)
290
+ ⚙️ pytest.ini (254B)
291
+ 📝 README.md (15KB 536B)
292
+ ```
293
+
294
+ (该视图由我的另一个项目[CelestialVault](https://github.com/Mr-xiaotian/CelestialVault)中inst_file生成。)
295
+
296
+ ## 更新日志(Change Log)
297
+
298
+ - 2021: 建立一个支持多线程与单线程处理函数的类
299
+ - 2023: 在GPT4帮助下添加多进程与携程运行模式
300
+ - 5/9/2024: 将原有的处理类抽象为节点, 添加TaskChain类, 可以线性连接多个节点, 并设定节点在Chain中的运行模式, 支持serial和process两种, 后者Chain所有节点同时运行
301
+ - 12/12/2024-12/16/2024: 在原有链式结构基础上允许节点有复数下级节点, 实现Tree结构; 将原有TaskChain改名为TaskTree
302
+ - 3/16/2025: 支持Web端任务完成情况可视化
303
+ - 6/9/2025: 支持节点拥有复数上级节点, 脱离纯Tree结构, 为之后循环图做准备
304
+ - 6/11/2025: 自[CelestialVault](https://github.com/Mr-xiaotian/CelestialVault)项目instances.inst_task迁入
305
+ - 6/12/2025: 支持循环图, 下级节点可指向上级节点
306
+ - 6/13/2025: 支持loop结构, 即节点可指向自己
307
+ - 6/14/2025: 支持forest结构, 即可有多个根节点
308
+ - 6/16/2025: 多轮评测后, 当前框架已支持完整有向图结构, 将TaskTree改名为TaskGraph
309
+ - 3.0.1: 上线Pypi, 可喜可贺
310
+ - 3.0.4: 新增一个抽象结构TaskQueue, 用于表示节点的所有"入边"与"出边"; 恢复未消费任务的保存功能
311
+ - 3.0.5: 删除原有的TaskRedisTransfer节点, 并增添三种新的redis交互节点TaskRedisSink TaskRedisSource TaskRedisAck, 用于跨语言 跨进程 跨设备处理任务; 并在Web页面添加展示拓扑信息的卡片
312
+ - 3.0.6: 添加对[CelestialTree](https://github.com/Mr-xiaotian/CelestialTree)系统的支持, 现在可以追踪单个任务的流向
313
+
314
+ ## Star 历史趋势(Star History)
315
+
316
+ 如果对项目感兴趣的话,欢迎star。如果有问题或者建议的话, 欢迎提交[Issues](https://github.com/Mr-xiaotian/CelestialFlow/issues)或者在[Discussion](https://github.com/Mr-xiaotian/CelestialFlow/discussions)中告诉我。
317
+
318
+ [![Star History Chart](https://api.star-history.com/svg?repos=Mr-xiaotian/CelestialFlow&type=Date)](https://star-history.com/#Mr-xiaotian/CelestialFlow&Date)
319
+
320
+ ## 许可(License)
321
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
322
+
323
+ ## 作者(Author)
324
+ Author: Mr-xiaotian
325
+ Email: mingxiaomingtian@gmail.com
326
+ Project Link: [https://github.com/Mr-xiaotian/CelestialFlow](https://github.com/Mr-xiaotian/CelestialFlow)
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "celestialflow"
7
- version = "3.0.4"
7
+ version = "3.0.6"
8
8
  description = "A flexible GRAPH-based task orchestration framework."
9
9
  readme = "README.md"
10
10
  license = { text = "MIT" }