PipeSay
一个可插拔的「句子流水线」框架:抓取 → 加工 → 输出。
PipeSay 将句子处理抽象为一条可配置的流水线。每个环节都通过装饰器注册、通过 YAML 组合,你无需改动核心代码,就能拼装出自己的玩法。
设计理念
- 三段式流水线:
Fetcher→Processor→Outputer,职责清晰,互不耦合。 - 注册式插件系统:
@processor('name')/@outputer('name')一键注册,签名自动反射为可配置参数。 - YAML 驱动:处理器与输出器均以声明式配置组合,支持全局参数与步骤级参数合并。
- 面向扩展:核心只提供约定与调度,具体能力全部来自插件。
安装
pip install -r requirements.txt
快速开始
从网络获取一言并输出到终端:
python -m pipesay.main hitokoto -o test2.yaml
从本地文件读取、加工后输出:
python -m pipesay.main local -f ./cowsay.txt -s test.yaml -o test2.yaml
命令行
usage: main.py [-h] [-g GENERATIONS] [-s PROCESSER_CONFIG] [-o OUTPUTCONFIG] {local,hitokoto} ...
| 参数 | 说明 | 默认值 |
|---|---|---|
-g, --generations |
生成次数 | 1 |
-s, --processor-config |
处理器流水线配置 | None |
-o, --outputer-config |
输出器流水线配置 | None |
子命令:
local:-f/--file指定本地文件(默认./cowsay.txt)。hitokoto:-c/--category指定分类(可多选,默认全部)。
配置
处理器配置:
pipeline:
- processor: to_weak
- processor: i18n
params:
lan: [en, ja]
global: {}
输出器配置:
outputs:
- outputer: term
params:
auto_clear: True
global: {}
params 会与 global 中同名步骤的配置合并,步骤级优先。
扩展
新增处理器:
from pipesay.processor.base import processor
@processor('shout')
def shout(sentences: list, mark: str = '!', log=None):
"""给每句话加上强调符号"""
return [s + mark for s in sentences]
新增输出器:
from pipesay.outputers.base import outputer
@outputer('count')
def count(sentences: list, log=None):
"""只统计句子数量"""
log(f"共 {len(sentences)} 句")
注册后即可在 YAML 中直接引用。函数签名中的 sentences 与 log 会被自动跳过,其余参数反射为可配置项。
查看已注册的步骤:
from pipesay.processor.base import Processor
from pipesay.outputers.base import Outputer
Processor.list_all()
Outputer.list_all()
项目结构
src/pipesay/
├── main.py # 入口
├── constants/ # 常量
├── fetcher/ # 获取器
├── processor/ # 处理器与注册表
├── outputers/ # 输出器与注册表
├── core/ # 流水线执行器与注册装饰器
├── parser/ # 命令行解析
└── utils/ # 通用工具
工作原理
Fetcher ──▶ Processor ──▶ Outputer
▲ ▲
pipeline.yaml outputs.yaml
Fetcher按模式返回list[str]。Processor读取pipeline段,按序加工并逐级传递。Outputer读取outputs段,将结果交给输出器展示。
License
MIT
Release files for pipesay 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pipesay-0.0.2.tar.gz | 12.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pipesay-0.0.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 28.1 kB
Release files / pipesay-0.0.2.tar.gz
| Download URL | pipesay-0.0.2.tar.gz |
|---|---|
| Size | 12.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e749e45aa55b9d804bacb1e4cd88f7a8496b9a29b378c9ea8fd4f0c71252bd62
|
|
BLAKE2b-256 checksum How to use checksums |
75f92744746c02699b710aaa8856acc460996051f2be3b7dbaffc37ed229bbad
|
| 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 Sep 13, 2026.
Transparency logRelease files / pipesay-0.0.2-py3-none-any.whl
| Download URL | pipesay-0.0.2-py3-none-any.whl |
|---|---|
| Size | 15.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
142b277d64aa5fedc334988d4da62ffa193cb82cb6998966048ed09d058fc27d
|
|
BLAKE2b-256 checksum How to use checksums |
e33a29d4ebc01a957b75b1685180fc038d930a6382c73383a94bd5c4ba00a4f1
|
| 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 Sep 13, 2026.
Transparency log