Skip to main content

myssia-classifier

myssia 七大类关键词分类引擎,独立 pip 包:零运行时依赖、免费/付费双信号裁决、数据与代码分离、命中可追溯。

从 myssia 核心的分类层(myssia.classify)拆出,忠实移植生产爬虫关键词分类器(2026-09-28 纠错版,金测集钉住语义)。可脱离 myssia 单独引用,myssia 核心也以固定版本范围依赖本包。

特性

  • 零依赖:纯 Python 标准库(3.11+),pip install 即跑,无任何传递依赖
  • 双信号裁决:免费信号绝对优先于付费信号;注册引流过滤;死词/噪声词过滤
  • 数据与代码分离:词表是包内 data/keywords.json,调关键词/正则不用改代码
  • 命中追溯:每条结果都带命中明细(哪张表、哪个关键词/正则、命中区间)
  • 自定义规则 API:when 表达式走白名单 AST,永不 eval,未知构造加载期即拒
  • 类型完备:全量类型标注(py.typed),mypy strict 友好

安装

尚未上架 PyPI;在那之前从 myssia 仓库以 uv workspace 安装(git clone https://github.com/xinzhuzi/myia && cd myssia && uv sync),PyPI 上架后即可 pip install myssia-classifier。

最小示例

from myssia_classifier import classify_item

result = classify_item({"title": "Claude 免费领100$"})
print(result.category)  # "token"
print(result.tags)      # 自定义规则命中的 tag(无规则时为 [])
for evidence in result.matched:
    print(evidence.describe())  # 命中追溯: 表:类型=值

七大类:credit-card / proxy-node / buying-agent / server / token / ai-news / freebie;另有第八个生产标签 channel(付费信号且无免费信号的导购/渠道帖)。被过滤标题的 category 为 None。

自定义规则

规则读取条目字段(字典键或对象属性),在粗分类之上打 tag:

from myssia_classifier import Rule, classify_item

rule = Rule(name="big-move", when="abs(change_pct) >= 3", tag="大波动")
result = classify_item({"title": "NVDA 盘前大跌", "change_pct": -4.2}, rules=[rule])
print(result.tags)  # ["大波动"]

when 表达式支持的语法(白名单 AST):字面量、字段名、list/tuple、四则与比较运算、and/or/not、白名单函数(abs/min/max/round/len/int/float/str)。属性访问、下标、lambda、f-string、推导式、任意调用等一律在构造期抛 RuleSyntaxError。运行期单条规则失败只按"未命中"处理并记 WARNING,绝不打断整批评测。

自定义词表

默认词表随包分发(myssia_classifier/data/keywords.json);也可以加载自己的 JSON:

from myssia_classifier import load_table, classify_title

table = load_table()  # 缺省即打包词表;自定义时传自己的 JSON 路径(结构非法时结构化报错)
print(classify_title("便宜出极速服务器三台", table).category)  # "server"(打包词表实测命中)

词表 JSON 支持在 keywords(普通关键词)与 patterns(正则)两列增改,case_insensitive 按节可调;顶层未知字段与断裂引用(如 fallback_target 指向不存在的类目)加载即报错,不做静默忽略。

从 YAML 加载规则

load_rules 可直接读取 myssia 插件 YAML 的 classify.rules 节(需要环境里装有 PyYAML;本包不把它列为依赖):

from myssia_classifier import load_rules

rules = load_rules("plugin.yaml")

许可

MIT

Metadata

Release files for myssia-classifier 0.0.6

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

Source distribution (sdist)

Source distribution for myssia-classifier 0.0.6
File Size Uploaded Provenance
myssia_classifier-0.0.6.tar.gz 28.5 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for myssia-classifier 0.0.6
File Interpreter ABI Platform
myssia_classifier-0.0.6-py3-none-any.whl Python 3 none any Details

Total release size: 49.6 kB

Release files / myssia_classifier-0.0.6.tar.gz

Download URL myssia_classifier-0.0.6.tar.gz
Size 28.5 kB
Tags Source
SHA-256 checksum
How to use checksums
1c0fe4c61c60199ed1b478adc4e1d76065b1babce9b9dd06d0727e9c13db5a67
BLAKE2b-256 checksum
How to use checksums
08bb54a4d4bd31f2947221c891a3e2a39edc78f86fa9d97e6f1a42e8a321191f
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 17, 2026.

Transparency log

Release files / myssia_classifier-0.0.6-py3-none-any.whl

Download URL myssia_classifier-0.0.6-py3-none-any.whl
Size 21.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4802c84731ecd76387c952aa331af5374a3e15ff7b1c24eed9d89283e63a2622
BLAKE2b-256 checksum
How to use checksums
45ecf5ccce6279a400363bee140be886362edc4c8abbf6516429a936e1403c62
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 17, 2026.

Transparency log

Security for myssia-classifier 0.0.6

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.

Select from 2 files

Attestation for myssia_classifier-0.0.6.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 17, 2026.

Transparency log

A 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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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