Skip to main content

PipeSay

一个可插拔的「句子流水线」框架:抓取 → 加工 → 输出。

PipeSay 将句子处理抽象为一条可配置的流水线。每个环节都通过装饰器注册、通过 YAML 组合,你无需改动核心代码,就能拼装出自己的玩法。

设计理念

  • 三段式流水线:Fetcher → Processor → Outputer,职责清晰,互不耦合。
  • 注册式插件系统:@processor('name') / @outputer('name') 一键注册,签名自动反射为可配置参数。
  • YAML 驱动:处理器与输出器均以声明式配置组合,支持全局参数与步骤级参数合并。
  • 面向扩展:核心只提供约定与调度,具体能力全部来自插件。

安装

    pip install -r requirements.txt

快速开始

从网络获取一言并输出到终端:

    python -m pipesay hitokoto -p test2.yaml

从本地文件读取、加工后输出:

    python -m pipesay local -f ./cowsay.txt -p test.yaml

命令行

    usage: pipesay [-h] [-g GENERATIONS] [-p PIPELINE_CONFIG] {local,hitokoto} ...
参数 说明 默认值
-g, --generations 生成次数 1
-s, --pipeline-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┘
  1. Fetcher 按模式返回 list[str]。
  2. Processor 读取 pipeline 段,按序加工并逐级传递。
  3. Outputer 读取 outputs 段,将结果交给输出器展示。

License

MIT

Release files for pipesay 0.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pipesay 0.0.0
File Size Uploaded
pipesay-0.0.0.tar.gz 16.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pipesay 0.0.0
File Interpreter ABI Platform
pipesay-0.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 32.9 kB

Release files / pipesay-0.0.0.tar.gz

Download URL pipesay-0.0.0.tar.gz
Size 16.2 kB
Tags Source
SHA-256 checksum
How to use checksums
3ebcfecae306d1b28f95400aa3ae4265c08ed29eec16818f8545059664564c26
BLAKE2b-256 checksum
How to use checksums
15d420692af1c3e313324494e2e41c2be593207e03bacdfeed29a62012edbbdb
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 15, 2026.

Transparency log

Release files / pipesay-0.0.0-py3-none-any.whl

Download URL pipesay-0.0.0-py3-none-any.whl
Size 16.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8adcf20f59158e55dc33f247ed1e493e9c4756e646fc362e1a2780de04b629ca
BLAKE2b-256 checksum
How to use checksums
a8f64b8d4dcbd0e81de9b23e6825bd2a5105331f2606eaaf020ddbc40806c42b
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 15, 2026.

Transparency log

Release history Release notifications | RSS feed

0.0.10

2 release files

0.0.3

2 release files

0.0.2

2 release files

This release

0.0.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page