Skip to main content

zongyuan-gateway 枢纽网关

路由网关内核:路由在册、默认拒绝、通行留痕、重放可验,纯标准库。

|元枢体系 YUANSHU

定名语义

  • 道统出处:枢纽者,众辐所凑;网关者,门以限行——所向有表,所禁有门
  • 工程映射:纯标准库的路由网关内核——路由注册制,未注册路径一律拒,裁决留痕可重演

这是什么

一个纯标准库的路由网关内核:路由在册(精确路径与前缀路径分册注册,重复注册即拒);过门裁决按「精确优先于前缀、前缀最长者胜」定序,未注册路径默认拒绝,不静默放行;每次放行或拒绝都记入只追加的通行簿(路径、路由、裁决、序号);任意时刻可从通行簿重放裁决序,逐位一致——「裁决可重演」是本内核的第一契约;通行簿摘要在册,一字被改必现形。

道统映射

道统名 内核对象 职责
路由在册 register 精确与前缀分册注册,重复即拒,不静默覆盖
所向有表 match 精确优先于前缀,前缀最长者胜
所禁有门 handle 未注册路径默认拒绝,裁决一律留痕
通行留痕 ledger 只追加通行簿:路径、路由、裁决、序号
重放核验 replay 按簿重演裁决序,逐位一致
摘要 digest SHA-256(canonical 通行簿),篡改现形

快速开始

from zongyuan_gateway import Gateway

gw = Gateway()
gw.register("/health", "体检门")
gw.register("/api/", "总门", prefix=True)
gw.register("/api/v2/", "二版门", prefix=True)

gw.handle("/api/v2/users")   # 放行(二版门:最长前缀胜)
gw.handle("/secret")          # 拒绝(未注册路径默认拒)

print(gw.ledger())            # 通行留痕
print(gw.replay() == gw.ledger())  # True:裁决可重演
print(gw.digest())            # 摘要:篡改现形

命令行:

python tools/zongyuan_gateway.py stats  ledger.json
python tools/zongyuan_gateway.py digest ledger.json
python tools/zongyuan_gateway.py replay ledger.json

MCP 门面

内核已拧成 MCP 服务器(stdio,FastMCP,八工具):register_route/match_route/handle_path/ledger_view/replay_ledger/digest/stats/describe。进程内持有网关正本,通行簿随进程累积。

pip install "mcp>=1.0"   # 仅门面需要,内核保持纯标准库
python run_mcp_server.py

注册配置(server.json:io.github.tanbopiao/zongyuan-gateway,v0.2.0)。

设计约定

  • 纯标准库(json/hashlib),无第三方依赖,无网络服务。
  • 路由注册制:路径须以 / 开头,重复注册(含跨册同路径)一律 GatewayError,不静默覆盖。
  • 路径合制:非字符串路径在匹配与过门入口一律拒以 GatewayError,不撞裸异常。
  • 默认拒绝:未注册路径不猜测、不放行,裁决与拒绝理由同簿留痕。
  • 摘要基于通行簿原字节序:任何一字被改,重放摘要必不一致——「篡改现形」是本内核的第一契约。
  • 防篡改前提(统一声明):本链可发现局部或单点篡改;持有全量记录的攻击者可整体重写并重算通过——链头哈希需带外留存(或对链头签名)方可对抗整体重写。

回归

regression.md 登记回归铁律(路由、匹配、拒绝、日志、摘要五域契约)。运行:

python3 -m unittest discover -s . -p "test_*.py"

许可证

Dual-licensed: AGPL-3.0 (default) or a commercial license for closed-source use — see DUAL-LICENSE.md。仓库:https://github.com/tanbopiao/zongyuan-gateway


生态导航:本作品属于 元枢工具货架(21 件 MCP,自动聚合)。 同门:tanze(深研) · pialuo(网页提取) · wengu(跨会话记忆) · jiwei(像素特效) · constraint-runtime(约束治理) · agent-eval-engine(可验证评测) · 全部作品

Metadata

Release files for zongyuan-gateway 0.2.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 zongyuan-gateway 0.2.0
File Size Uploaded Provenance Actions
zongyuan_gateway-0.2.0.tar.gz 18.1 kB Without provenance Details for zongyuan_gateway-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for zongyuan-gateway 0.2.0
File Interpreter ABI Platform Actions
zongyuan_gateway-0.2.0-py3-none-any.whl Python 3 none any Details for zongyuan_gateway-0.2.0-py3-none-any.whl

Total release size: 37.4 kB

Release files / zongyuan_gateway-0.2.0.tar.gz

Download URL zongyuan_gateway-0.2.0.tar.gz
Size 18.1 kB
Tags Source
SHA-256 checksum
How to use checksums
096668b3ff90a076fc4b4f835fe040884e452844d6f0b39228980052eaf03c47
BLAKE2b-256 checksum
How to use checksums
72993002205b10f184b27b885c7939d166f29113b2990788e42c1115e9ed0834
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / zongyuan_gateway-0.2.0-py3-none-any.whl

Download URL zongyuan_gateway-0.2.0-py3-none-any.whl
Size 19.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0237761f69d3727b0ce90d5cf9dad3840c77e36da0f70576493c62c8eb4ef68b
BLAKE2b-256 checksum
How to use checksums
ef0ac193b02c6f4c0d1073fb77fa303c1774282fa4d50ec3eddaf8af77545c41
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Security for zongyuan-gateway 0.2.0

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files No provenance

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