astrum 0.1.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.
@@ -0,0 +1,8 @@
1
+ .venv/
2
+ .pytest_cache/
3
+ __pycache__/
4
+ *.py[cod]
5
+
6
+ /dist/
7
+ /site/
8
+ /.idea/
astrum-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 DuskXi
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.
astrum-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,203 @@
1
+ Metadata-Version: 2.4
2
+ Name: astrum
3
+ Version: 0.1.0
4
+ Summary: A lightweight, in-process async DAG orchestrator for high-performance task execution.
5
+ Project-URL: Homepage, https://github.com/DuskXi/astrum
6
+ Project-URL: Documentation, https://duskxi.github.io/astrum/
7
+ Project-URL: Repository, https://github.com/DuskXi/astrum
8
+ Project-URL: Issues, https://github.com/DuskXi/astrum/issues
9
+ Author-email: DuskXi <leizidusk@gmail.com>
10
+ License: MIT
11
+ License-File: LICENSE
12
+ Keywords: agent-orchestration,asyncio,dag,scheduler,task-graph
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
17
+ Requires-Python: >=3.9
18
+ Requires-Dist: loguru>=0.7.3
19
+ Requires-Dist: pydantic>=2.5.0
20
+ Provides-Extra: docs
21
+ Requires-Dist: mkdocs-material>=9.5.0; extra == 'docs'
22
+ Requires-Dist: mkdocs-static-i18n>=1.2.0; extra == 'docs'
23
+ Requires-Dist: mkdocs>=1.6.0; extra == 'docs'
24
+ Requires-Dist: mkdocstrings[python]>=0.25.0; extra == 'docs'
25
+ Provides-Extra: viz
26
+ Requires-Dist: rich>=10.0.0; extra == 'viz'
27
+ Description-Content-Type: text/markdown
28
+
29
+ # Astrum
30
+
31
+ [![Python](https://img.shields.io/badge/python-3.9%2B-blue.svg)](#installation--安装)
32
+ [![License](https://img.shields.io/badge/license-MIT-green.svg)](#license--许可证)
33
+ [![Docs](https://img.shields.io/badge/docs-MkDocs%20%2B%20Material-526CFE.svg)](https://duskxi.github.io/astrum/)
34
+ [![PyPI](https://img.shields.io/pypi/v/astrum.svg)](https://pypi.org/project/astrum/)
35
+
36
+ **A lightweight, in-process async DAG orchestrator for Python.**
37
+ Astrum 是一个轻量、进程内运行的 async DAG 编排库,用 Python 函数声明任务图,自动并行执行无依赖分支,并返回结构化执行报告。
38
+
39
+ Astrum is designed for local workflow orchestration where you want the ergonomics of plain Python functions, the clarity of a DAG, and the performance profile of `asyncio` without introducing a distributed workflow service.
40
+
41
+ ## Installation / 安装
42
+
43
+ ```bash
44
+ pip install astrum
45
+ ```
46
+
47
+ If you want terminal visualization powered by Rich:
48
+
49
+ ```bash
50
+ pip install "astrum[viz]"
51
+ ```
52
+
53
+ 如果需要在终端查看 DAG 和数据传输可视化,请安装 `viz` 可选依赖。
54
+
55
+ Examples that render Rich tables or trees, such as the coffee shop workflow, require the `viz` extra.
56
+
57
+ ## Quick Start / 快速开始
58
+
59
+ The recommended entry point is decorator mode: register functions with `@task`, declare execution dependencies with `depends_on`, pass upstream values with `Ref` / `F`, and call `run()`.
60
+
61
+ 推荐从装饰器模式开始:用 `@task` 注册任务,用 `depends_on` 声明执行依赖,用 `Ref` / `F` 传递上游返回值,然后调用 `run()`。
62
+
63
+ ```python
64
+ import asyncio
65
+
66
+ from astrum import F, AstrumConfig, Ref, run, task
67
+
68
+
69
+ @task("load_users")
70
+ async def load_users() -> dict:
71
+ await asyncio.sleep(0.1)
72
+ return {"users": ["Alice", "Bob"]}
73
+
74
+
75
+ @task("load_orders")
76
+ async def load_orders() -> dict:
77
+ await asyncio.sleep(0.1)
78
+ return {"orders": ["A-001", "A-002", "A-003"]}
79
+
80
+
81
+ @task("build_report", depends_on=["load_users", "load_orders"])
82
+ async def build_report(
83
+ users: Ref[list, F("load_users", "users")],
84
+ orders: Ref[list, F("load_orders", "orders")],
85
+ ) -> dict:
86
+ return {"summary": f"{len(users)} users, {len(orders)} orders"}
87
+
88
+
89
+ @task("publish_report", depends_on=["build_report"])
90
+ async def publish_report(
91
+ summary: Ref[str, F("build_report", "summary")],
92
+ ) -> None:
93
+ print(summary)
94
+
95
+
96
+ async def main() -> None:
97
+ report = await run(
98
+ target_tasks=["publish_report"],
99
+ config=AstrumConfig(skip_type_check=True, silence_warnings=True),
100
+ )
101
+ print(report.execution_state)
102
+ print(f"{report.successful_tasks}/{report.total_tasks} tasks completed")
103
+
104
+
105
+ asyncio.run(main())
106
+ ```
107
+
108
+ Expected output:
109
+
110
+ ```text
111
+ 2 users, 3 orders
112
+ completed
113
+ 4/4 tasks completed
114
+ ```
115
+
116
+ `load_users` and `load_orders` have no input parameters, so they can run in parallel. `build_report` and `publish_report` receive data from upstream task results.
117
+
118
+ `load_users` 和 `load_orders` 没有入参,会并行执行;`build_report` 和 `publish_report` 通过 `Ref/F` 接收上游任务结果。
119
+
120
+ ## Why Astrum / 为什么使用 Astrum
121
+
122
+ - **Plain Python tasks / 普通 Python 函数即任务**:同步函数和异步函数都可以注册为 DAG task。
123
+ - **Async DAG execution / 异步 DAG 执行**:没有依赖关系的任务自动并行启动。
124
+ - **Structured reports / 结构化报告**:执行状态、耗时、失败摘要、取消状态和重试记录都会进入 `ExecutionReport`。
125
+ - **Data transport / 数据传输**:用 `Ref[T, F("task", "field")]` 声明下游参数来自哪里。
126
+ - **Namespaces and registries / 命名空间与注册表**:可用 `namespace`、`use_namespace()` 或 `SchedulerRegistry` 隔离工作流。
127
+ - **Retries / 重试**:用 `@task(..., retry=N)` 为单个任务设置失败重试次数。
128
+
129
+ ## When Not to Use It / 不适合场景
130
+
131
+ Astrum is intentionally small and in-process. It is not a replacement for distributed workflow engines.
132
+
133
+ Astrum 当前不是分布式调度系统。如果你的需求是下面这些场景,通常应该选择更重的工作流平台或队列系统:
134
+
135
+ - Cross-machine scheduling / 跨机器调度
136
+ - Persistent queues / 持久化队列
137
+ - Cron-like scheduled jobs / 定时任务平台
138
+ - Long-running distributed workflows / 长生命周期分布式工作流
139
+ - Worker fleet management / 多 worker 集群管理
140
+
141
+ ## Core Concepts / 核心概念
142
+
143
+ - **Task / 任务**:一个已注册的 Python callable。任务可以是 `async def`,也可以是普通 `def`。
144
+ - **DAG / 有向无环图**:任务之间的依赖关系。某个任务只有在上游依赖完成后才会启动。
145
+ - **Scheduler / 调度器**:把 DAG 拆成执行阶段,启动可并行任务,并收集执行结果。
146
+ - **ExecutionReport / 执行报告**:`run()` 和 `scheduler.execute()` 的返回值,包含状态、耗时、统计和错误摘要。
147
+ - **Data Transport / 数据传输**:把上游任务的返回值注入下游函数参数。推荐使用 `Ref` / `F` 注解。
148
+
149
+ ## Documentation / 文档
150
+
151
+ The full documentation is bilingual and built with MkDocs + Material for MkDocs.
152
+
153
+ 完整文档支持中英文,并使用 MkDocs + Material for MkDocs 构建。
154
+
155
+ - [中文文档入口](https://duskxi.github.io/astrum/)
156
+ - [English documentation](https://duskxi.github.io/astrum/en/)
157
+ - [快速开始 / Quickstart](https://duskxi.github.io/astrum/quickstart/)
158
+ - [中文使用指南](USAGE.zh.md)
159
+ - [English Usage Guide](USAGE.en.md)
160
+ - [外部 API Reference](https://duskxi.github.io/astrum/api/external/)
161
+ - [Internal API Reference](https://duskxi.github.io/astrum/en/api/internal/)
162
+
163
+ The local Markdown files remain available in `docs/` for offline reading and contributions.
164
+
165
+ ## Examples / 示例
166
+
167
+ - [Fast Start](docs/examples/fast-start.zh.md):从串行、并行、fan-in 到异步重试的工作流模式速览。
168
+ - [Coffee Shop](docs/examples/coffee-shop.zh.md):用咖啡店流程解释 `TaskData` / `DataItem` / `DTRela` 数据流。
169
+ - [Stateless Text Retriever](docs/examples/stateless-text-retriever.zh.md):用复杂检索链路展示 fan-out、fan-in、多分支评分和 rerank。
170
+
171
+ The corresponding English pages are available next to the Chinese pages with `.en.md` filenames.
172
+
173
+ ## Development / 开发
174
+
175
+ This project uses `uv` for dependency management.
176
+
177
+ ```bash
178
+ uv sync --extra docs --extra viz
179
+ uv run pytest
180
+ uv run mkdocs serve
181
+ uv run mkdocs build --strict
182
+ ```
183
+
184
+ Common checks before publishing:
185
+
186
+ ```bash
187
+ uv run pytest
188
+ uv run mkdocs build --strict
189
+ ```
190
+
191
+ ## Project Status / 项目状态
192
+
193
+ Current version: **0.1.0**.
194
+
195
+ Astrum is preparing for its first public PyPI release. The core workflow model is usable, while APIs may still receive small refinements as the project stabilizes.
196
+
197
+ Astrum 正在准备首次发布到 PyPI。当前核心工作流模型已经可用,但在 `0.1.x` 阶段仍可能围绕 API 命名、文档和类型检查体验做小幅改进。
198
+
199
+ ## License / 许可证
200
+
201
+ Astrum is released under the MIT License.
202
+
203
+ Astrum 使用 MIT 许可证发布。
astrum-0.1.0/README.md ADDED
@@ -0,0 +1,175 @@
1
+ # Astrum
2
+
3
+ [![Python](https://img.shields.io/badge/python-3.9%2B-blue.svg)](#installation--安装)
4
+ [![License](https://img.shields.io/badge/license-MIT-green.svg)](#license--许可证)
5
+ [![Docs](https://img.shields.io/badge/docs-MkDocs%20%2B%20Material-526CFE.svg)](https://duskxi.github.io/astrum/)
6
+ [![PyPI](https://img.shields.io/pypi/v/astrum.svg)](https://pypi.org/project/astrum/)
7
+
8
+ **A lightweight, in-process async DAG orchestrator for Python.**
9
+ Astrum 是一个轻量、进程内运行的 async DAG 编排库,用 Python 函数声明任务图,自动并行执行无依赖分支,并返回结构化执行报告。
10
+
11
+ Astrum is designed for local workflow orchestration where you want the ergonomics of plain Python functions, the clarity of a DAG, and the performance profile of `asyncio` without introducing a distributed workflow service.
12
+
13
+ ## Installation / 安装
14
+
15
+ ```bash
16
+ pip install astrum
17
+ ```
18
+
19
+ If you want terminal visualization powered by Rich:
20
+
21
+ ```bash
22
+ pip install "astrum[viz]"
23
+ ```
24
+
25
+ 如果需要在终端查看 DAG 和数据传输可视化,请安装 `viz` 可选依赖。
26
+
27
+ Examples that render Rich tables or trees, such as the coffee shop workflow, require the `viz` extra.
28
+
29
+ ## Quick Start / 快速开始
30
+
31
+ The recommended entry point is decorator mode: register functions with `@task`, declare execution dependencies with `depends_on`, pass upstream values with `Ref` / `F`, and call `run()`.
32
+
33
+ 推荐从装饰器模式开始:用 `@task` 注册任务,用 `depends_on` 声明执行依赖,用 `Ref` / `F` 传递上游返回值,然后调用 `run()`。
34
+
35
+ ```python
36
+ import asyncio
37
+
38
+ from astrum import F, AstrumConfig, Ref, run, task
39
+
40
+
41
+ @task("load_users")
42
+ async def load_users() -> dict:
43
+ await asyncio.sleep(0.1)
44
+ return {"users": ["Alice", "Bob"]}
45
+
46
+
47
+ @task("load_orders")
48
+ async def load_orders() -> dict:
49
+ await asyncio.sleep(0.1)
50
+ return {"orders": ["A-001", "A-002", "A-003"]}
51
+
52
+
53
+ @task("build_report", depends_on=["load_users", "load_orders"])
54
+ async def build_report(
55
+ users: Ref[list, F("load_users", "users")],
56
+ orders: Ref[list, F("load_orders", "orders")],
57
+ ) -> dict:
58
+ return {"summary": f"{len(users)} users, {len(orders)} orders"}
59
+
60
+
61
+ @task("publish_report", depends_on=["build_report"])
62
+ async def publish_report(
63
+ summary: Ref[str, F("build_report", "summary")],
64
+ ) -> None:
65
+ print(summary)
66
+
67
+
68
+ async def main() -> None:
69
+ report = await run(
70
+ target_tasks=["publish_report"],
71
+ config=AstrumConfig(skip_type_check=True, silence_warnings=True),
72
+ )
73
+ print(report.execution_state)
74
+ print(f"{report.successful_tasks}/{report.total_tasks} tasks completed")
75
+
76
+
77
+ asyncio.run(main())
78
+ ```
79
+
80
+ Expected output:
81
+
82
+ ```text
83
+ 2 users, 3 orders
84
+ completed
85
+ 4/4 tasks completed
86
+ ```
87
+
88
+ `load_users` and `load_orders` have no input parameters, so they can run in parallel. `build_report` and `publish_report` receive data from upstream task results.
89
+
90
+ `load_users` 和 `load_orders` 没有入参,会并行执行;`build_report` 和 `publish_report` 通过 `Ref/F` 接收上游任务结果。
91
+
92
+ ## Why Astrum / 为什么使用 Astrum
93
+
94
+ - **Plain Python tasks / 普通 Python 函数即任务**:同步函数和异步函数都可以注册为 DAG task。
95
+ - **Async DAG execution / 异步 DAG 执行**:没有依赖关系的任务自动并行启动。
96
+ - **Structured reports / 结构化报告**:执行状态、耗时、失败摘要、取消状态和重试记录都会进入 `ExecutionReport`。
97
+ - **Data transport / 数据传输**:用 `Ref[T, F("task", "field")]` 声明下游参数来自哪里。
98
+ - **Namespaces and registries / 命名空间与注册表**:可用 `namespace`、`use_namespace()` 或 `SchedulerRegistry` 隔离工作流。
99
+ - **Retries / 重试**:用 `@task(..., retry=N)` 为单个任务设置失败重试次数。
100
+
101
+ ## When Not to Use It / 不适合场景
102
+
103
+ Astrum is intentionally small and in-process. It is not a replacement for distributed workflow engines.
104
+
105
+ Astrum 当前不是分布式调度系统。如果你的需求是下面这些场景,通常应该选择更重的工作流平台或队列系统:
106
+
107
+ - Cross-machine scheduling / 跨机器调度
108
+ - Persistent queues / 持久化队列
109
+ - Cron-like scheduled jobs / 定时任务平台
110
+ - Long-running distributed workflows / 长生命周期分布式工作流
111
+ - Worker fleet management / 多 worker 集群管理
112
+
113
+ ## Core Concepts / 核心概念
114
+
115
+ - **Task / 任务**:一个已注册的 Python callable。任务可以是 `async def`,也可以是普通 `def`。
116
+ - **DAG / 有向无环图**:任务之间的依赖关系。某个任务只有在上游依赖完成后才会启动。
117
+ - **Scheduler / 调度器**:把 DAG 拆成执行阶段,启动可并行任务,并收集执行结果。
118
+ - **ExecutionReport / 执行报告**:`run()` 和 `scheduler.execute()` 的返回值,包含状态、耗时、统计和错误摘要。
119
+ - **Data Transport / 数据传输**:把上游任务的返回值注入下游函数参数。推荐使用 `Ref` / `F` 注解。
120
+
121
+ ## Documentation / 文档
122
+
123
+ The full documentation is bilingual and built with MkDocs + Material for MkDocs.
124
+
125
+ 完整文档支持中英文,并使用 MkDocs + Material for MkDocs 构建。
126
+
127
+ - [中文文档入口](https://duskxi.github.io/astrum/)
128
+ - [English documentation](https://duskxi.github.io/astrum/en/)
129
+ - [快速开始 / Quickstart](https://duskxi.github.io/astrum/quickstart/)
130
+ - [中文使用指南](USAGE.zh.md)
131
+ - [English Usage Guide](USAGE.en.md)
132
+ - [外部 API Reference](https://duskxi.github.io/astrum/api/external/)
133
+ - [Internal API Reference](https://duskxi.github.io/astrum/en/api/internal/)
134
+
135
+ The local Markdown files remain available in `docs/` for offline reading and contributions.
136
+
137
+ ## Examples / 示例
138
+
139
+ - [Fast Start](docs/examples/fast-start.zh.md):从串行、并行、fan-in 到异步重试的工作流模式速览。
140
+ - [Coffee Shop](docs/examples/coffee-shop.zh.md):用咖啡店流程解释 `TaskData` / `DataItem` / `DTRela` 数据流。
141
+ - [Stateless Text Retriever](docs/examples/stateless-text-retriever.zh.md):用复杂检索链路展示 fan-out、fan-in、多分支评分和 rerank。
142
+
143
+ The corresponding English pages are available next to the Chinese pages with `.en.md` filenames.
144
+
145
+ ## Development / 开发
146
+
147
+ This project uses `uv` for dependency management.
148
+
149
+ ```bash
150
+ uv sync --extra docs --extra viz
151
+ uv run pytest
152
+ uv run mkdocs serve
153
+ uv run mkdocs build --strict
154
+ ```
155
+
156
+ Common checks before publishing:
157
+
158
+ ```bash
159
+ uv run pytest
160
+ uv run mkdocs build --strict
161
+ ```
162
+
163
+ ## Project Status / 项目状态
164
+
165
+ Current version: **0.1.0**.
166
+
167
+ Astrum is preparing for its first public PyPI release. The core workflow model is usable, while APIs may still receive small refinements as the project stabilizes.
168
+
169
+ Astrum 正在准备首次发布到 PyPI。当前核心工作流模型已经可用,但在 `0.1.x` 阶段仍可能围绕 API 命名、文档和类型检查体验做小幅改进。
170
+
171
+ ## License / 许可证
172
+
173
+ Astrum is released under the MIT License.
174
+
175
+ Astrum 使用 MIT 许可证发布。