Skip to main content

triplane

面向长连接、有状态业务自动化与实时 Web 控制台的纯 Python 三平面隔离运行时框架(无 Redis / NATS / gRPC / PostgreSQL 依赖)。

核心设计理念

  1. 三平面彻底隔离
    • Plane 1 · SessionGateway:多渠道鉴权、长连接保活心跳、有界 PacketRingBuffer 与上行幂等去重;账号在线态唯一真相源,长期常驻不重启。
    • Plane 2 · StateEngine:原生极简共用无状态状态机(StrEnum + dataclass + TRANSITIONS)、按账号串行队列、heapq + gen 统一业务定时器、engine.sqlite3(WAL)、5 步无感热更新。
    • Plane 3 · WebBackend:无状态 HTTP API、只读视图缓存、事件日志热环与 Last-Event-ID SSE 断线续传。
  2. 统一启动入口 + 延迟工厂加载
    • 业务项目仅维护一份声明字符串路径的 TriplaneApp 配置(延迟导入,启动单个平面时绝不加载其他平面的代码)。
    • 本机一键拉起三进程(内置轻量 Supervisor)与容器单平面独立启动共用同一个 triplane CLI。

安装(Installation)

# 完整安装(包含 gateway / engine / web 三个平面运行时依赖)
pip install "triplane[all]"
# 或使用 uv
uv add "triplane[all]"

# 容器场景按平面精简安装
pip install "triplane[gateway]"
pip install "triplane[engine]"
pip install "triplane[web]"

快速开始(CLI)

# 脚手架生成最小三平面项目
triplane init mygame --dir .

# 本机一键拉起三平面(顺序健康探活 gateway -> engine -> web)
triplane up myapp.app:app --data-dir .private

# 运行内置零依赖本地 Demo(登录 / 状态机 / 不确定故障注入 / 热重启 / SSE 续传)
PYTHONPATH=src:. triplane up examples.demo_game.app:app --data-dir .private

# 容器 / 独立进程按平面启动
triplane run gateway myapp.app:app --port 18761
triplane run engine  myapp.app:app --port 18762
triplane run web     myapp.app:app --port 8765

# 本机开发态单平面热更新(例如仅重启 engine,保持 gateway 长连接不断)
triplane reload engine --data-dir .private

# 查看运行状态 & 初始化/重置 Web 管理员账号
triplane status --data-dir .private
triplane admin init --data-dir .private --username admin
triplane admin init --data-dir .private --username admin --reset-password

核心运行时保障与高阶抽象(v0.3.0)

  • 崩溃隔离与可信重同步:PlaneSupervisor 隔离单平面故障并保持 Gateway 长连接不断;跨 Gateway 硬重启通过进程级 stream_epoch 与认证全量基线实现确定性重同步(resync_account)。
  • 外发对账、节流与读写分流:SEND_RAW_ACK 按 (account_id, request_id, conn_gen) 严格归属;支持可选持久化 Outbox、全局/分组发包节流与退避 OutboundPacer(R1),以及免锁定低优先级的 SendPacket(read_only=True) 只读查询分流(R4)。
  • 跨状态机仲裁与策略演化:通过 IFocusPolicy / TurnAllocator 实现跨状态机专注独占与限时公平时间片轮转(R2);支持 ctx_version 检查点门禁与 policy_version 策略归一化/自动迁移(P2-2 / R3)。
  • 共享数据源与增量看板 Diff:SharedFeedRunner 在 Engine 单例周期抓取跨账号共享 Feed(R6);ReadModelCache.get_slice_diff 结合 reuse_unchanged_fields 为 GET /api/accounts/{account_id}/board/{domain}?since_revision= 提供增量字段 Diff(R5)。
  • 插件化、多副本与多片路由:支持 TriplanePluginSpec 统一三平面钩子、IGatewayStore/IEngineStore/IWebStore 可插拔协议、Prometheus 指标(/metrics/prometheus)以及一致性哈希分片客户端 Sharded*ControlClient(P0~P2)。

文档与基准

Metadata

Release files for triplane 0.3.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 triplane 0.3.0
File Size Uploaded Provenance Actions
triplane-0.3.0.tar.gz 223.2 kB With provenance Details for triplane-0.3.0.tar.gz

Built distribution (wheel)

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

Total release size: 365.6 kB

Release files / triplane-0.3.0.tar.gz

Download URL triplane-0.3.0.tar.gz
Size 223.2 kB
Tags Source
SHA-256 checksum
How to use checksums
0577f852246e8ea367c19bd79835afc792ca7bdce4081c4e2897e1a92ed2dc9a
BLAKE2b-256 checksum
How to use checksums
2fc23f746eaceb9f45b2e68df402089bcaea145c8107f2744f782e0f6f0eeb57
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 30, 2026.

Transparency log

Release files / triplane-0.3.0-py3-none-any.whl

Download URL triplane-0.3.0-py3-none-any.whl
Size 142.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3d57ee97a746b2eeae5587a276af47975ce5b355cf53834b9abb67a681252a08
BLAKE2b-256 checksum
How to use checksums
ff070778cb23aae68b78b0b0230eca542aa1441ef09b18bb627d4ba47e52419f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 30, 2026.

Transparency log

Security for triplane 0.3.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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for triplane-0.3.0.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 Nov 30, 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