This release is a pre-release and may not be stable for production use.
ui-stream
把后台任务的进度发给 UI,分批保存进度快照,并在发送结束通知前提交最终结果。
ui-stream 适合已经有后台任务和业务存储的 Python 应用。它负责实时发布、归档缓冲和完成顺序;使用它的应用(下文称“宿主”)提供任务调度、权限与真正的存储事务。核心同步、无第三方依赖。
快速上手
需要 Python ≥3.11 和已启用的虚拟环境。仅安装库时固定 alpha 版本,import 名为 ui_stream:
python -m pip install ui-stream==0.1.0a2
要运行示例,请先取得本仓库,并在仓库根目录执行以下命令。Counter 和 Demo 不包含在 wheel/sdist 中,不能仅安装 PyPI 包后直接运行:
python -m pip install --no-deps .
python -m examples.counter
python -m demos.sqlite --database /tmp/ui-stream-demo.sqlite3 --port 8765
Counter 打印实时文本帧和最终内存快照;SQLite Demo 在 http://127.0.0.1:8765 展示进度、故障与恢复,Ctrl-C 停止。Demo 使用合成数据和专用 SQLite,需 macOS/Linux。
下面用 Counter 看一次完整调用。4、9 是先后产生的进度值,13 是业务自己计算的最终结果;最新进度和最终结果是两份不同的数据:
from ui_stream import StreamPolicy
from examples.counter import make_counter
runtime, channel, store = make_counter(policy=StreamPolicy(checkpoint_event_count=1))
runtime.send(4)
runtime.send(9)
runtime.finish(status="DONE", completion=13)
assert store.snapshot.latest == 9 and store.snapshot.result == 13
Counter 用内存演示接口,进程退出即丢失数据。它自定义了 DONE 终态;默认 JSON codec 使用 SUCCESS / FAILED,业务可以自行选择事件和状态。
接入自己的应用
创建一次执行后,组装 StreamRuntime 和三个实现对象:EventCodec 把业务值变成事件,LivePublisher 发送实时事件,ArchiveStore 保存进度和最终结果。无需继承 Runtime;完整实现可从 Counter 开始,再看 架构与接入流程 和 API。
| 能做什么 | 应用还需负责什么 |
|---|---|
| 有界缓冲、分批归档(checkpoint)、提交结果后再通知结束 | 任务调度、用户权限、事务、执行身份校验与重试 |
| 实时进度配合最新快照恢复 UI | HTTP/SSE 响应、快照查询、重连时的读取与衔接 |
| 自定义事件、实时通道与快照存储 | 按业务选择历史保留策略;核心不保证完整历史、断线无损或恰好一次投递 |
| 安装范围 | 用途与依赖 |
|---|---|
| 核心 wheel | 标准库;Runtime、端口和归档辅助函数 |
| 仓库 Counter / SQLite Demo | 标准库 + 已安装核心 |
[json] |
默认 JSON 事件、Redis 游标读取协议和 SSE 帧;Pydantic ≥2.10,<3 |
[redis] |
另含 Redis 实时存储适配器;Pydantic ≥2.10,<3,redis-py ≥3.5.3 |
Demo · 性能图表 · 方案选型 · 贡献 · 安全 · 发布
CI 的源码矩阵覆盖 Python 3.11–3.14 / Linux、macOS;wheel、sdist 与 README 验证在 Linux 执行。
维护者:raja <rajawwang@foxmail.com>(GitHub 0RAJA)。
MIT 及来源说明;原版权声明保持不变。
Metadata
Release files for ui-stream 0.1.0a2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| ui_stream-0.1.0a2.tar.gz | 25.7 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| ui_stream-0.1.0a2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 58.1 kB
Release files / ui_stream-0.1.0a2.tar.gz
| Download URL | ui_stream-0.1.0a2.tar.gz |
|---|---|
| Size | 25.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
49cfb76c9c70351598212830bc131f224cea24fc6e16c42636cc88e96253f5c9
|
|
BLAKE2b-256 checksum How to use checksums |
dc3d03ecf76304509c25a1bea07c3ce0537d4e399d4daf65e1dcaf400a3311c2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 20, 2026.
Transparency logRelease files / ui_stream-0.1.0a2-py3-none-any.whl
| Download URL | ui_stream-0.1.0a2-py3-none-any.whl |
|---|---|
| Size | 32.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9c4ca25cfae7c7030538f8d7d368fbdb7ce27e1751686559e5d90b049696bcc4
|
|
BLAKE2b-256 checksum How to use checksums |
8e7cd0df0ce6a17c25b3ec5d4d935920455296e1238dbb7427bcab2f935c82f6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 20, 2026.
Transparency logSecurity for ui-stream 0.1.0a2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for ui_stream-0.1.0a2.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 20, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.