Yanked
This release has been yanked by its maintainers, and will be ignored by installers, except when explicitly specified.
Consider using release 0.0.10 instead.
PipeSay
一个可插拔的「句子流水线」框架:抓取 → 加工 → 输出。
PipeSay 将句子处理抽象为一条可配置的流水线。每个环节都通过装饰器注册、通过 YAML 组合,你无需改动核心代码,就能拼装出自己的玩法。
设计理念
- 三段式流水线:
Fetcher→Processor→Outputer,职责清晰,互不耦合。 - 注册式插件系统:
@processor('name')/@outputer('name')一键注册,签名自动反射为可配置参数。 - YAML 驱动:处理器与输出器均以声明式配置组合,支持全局参数与步骤级参数合并。
- 面向扩展:核心只提供约定与调度,具体能力全部来自插件。
安装
pip install -r requirements.txt
快速开始
从网络获取一言并输出到终端:
python -m src.pipesay.main hitokoto -o test2.yaml
从本地文件读取、加工后输出:
python -m src.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 src.pipesay.processor.base import processor
@processor('shout')
def shout(sentences: list, mark: str = '!', log=None):
"""给每句话加上强调符号"""
return [s + mark for s in sentences]
新增输出器:
from src.pipesay.outputers.base import outputer
@outputer('count')
def count(sentences: list, log=None):
"""只统计句子数量"""
log(f"共 {len(sentences)} 句")
注册后即可在 YAML 中直接引用。函数签名中的 sentences 与 log 会被自动跳过,其余参数反射为可配置项。
查看已注册的步骤:
from src.pipesay.processor.base import Processor
from src.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.1
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.1.tar.gz | 12.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pipesay-0.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 28.2 kB
Release files / pipesay-0.0.1.tar.gz
| Download URL | pipesay-0.0.1.tar.gz |
|---|---|
| Size | 12.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
efdd9f0411a673f59d474a88ca70d1f0180a598b2f852a09cd6b2437f73fd45d
|
|
BLAKE2b-256 checksum How to use checksums |
614d6afcafa531ad68be1268152549e0b1f3b2fd651f197b33a95ef68aaec158
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|
Release files / pipesay-0.0.1-py3-none-any.whl
| Download URL | pipesay-0.0.1-py3-none-any.whl |
|---|---|
| Size | 15.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f490bf31ac0e982bd2ead6bdde996cc76a3d955e3dc2c69cf759a0f1e11b9494
|
|
BLAKE2b-256 checksum How to use checksums |
21824a1a87ea122656e97cec98542f0e9828facabc59bb44f494098de1612e8d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|