🧪 v0.8.1 — 全栈反应式 Web 框架🧪 v0.8.1 — Full-Stack Reactive Web Framework

融合 Clojure 声明式基因Clojure's Declarative Gene
与 Pythonic 全栈反应式Meets Pythonic Full-Stack Reactivity

纯 Python 编写全栈应用。零构建、零 API 胶水、天生离线就绪。用嵌套列表表达 UI,框架自动完成 WebSocket 双向同步与最小化 DOM 补丁推送。

Build full-stack apps in pure Python. Zero build, zero API glue, air-gapped ready. Express UI with nested lists — the framework handles WebSocket bidirectional sync and minimal DOM patch pushes automatically.

最新版本 v0.8.1 · MIT 开源 · Python ≥ 3.11

Latest v0.8.1 · MIT Open Source · Python ≥ 3.11

⚡️ 核心特性

⚡️ Key Features

Hiccl 继承了 Clojure 的优雅哲学,在 Python 生态中打造现代化全栈开发体验。

Hiccl inherits Clojure's elegant philosophy, crafting a modern full-stack development experience within the Python ecosystem.

🧩

Hiccup 声明式 UI

Hiccup Declarative UI

纯 Python 嵌套列表表达整个 DOM 结构,告别模板语言和 JSX。自动绑定事件到服务端方法。

Express entire DOM structures with pure Python nested lists. Say goodbye to template languages and JSX. Events auto-bind to server-side methods.

🔌

Signal 反应式状态

Signal Reactive State

signal / computed / effect 三大原语,搭配 batch() 批量事务。状态变更自动触发最小化虚拟 DOM Diff。

Three primitives — signal / computed / effect — plus batch() transactions. State changes auto-trigger minimal virtual-DOM diffs.

🛡️

Spec 运行时契约

Spec Runtime Contracts

Clojure-like 声明式数据契约守卫 @server 方法边界。结构化 explain_data 报错,赋能 AI Agent 自愈闭环。

Clojure-like declarative data contracts guarding @server method boundaries. Structured explain_data errors empower AI agent self-healing loops.

🔀

MQTT 通配符 EventBus

MQTT Wildcard EventBus

原生层级通配符订阅(* 单层 / # 多层),高性能正则缓存路由,轻松构建多人实时协作应用。

Native hierarchical wildcard subscriptions (* single / # multi level) with high-performance regex cache routing for real-time collaboration.

🧩

Reagent 纯函数组件

Reagent Functional Components

use_signal() / subscribe() / dispatch() 单向数据流。展示层纯函数 + 状态层 OOP,UI 与副作用深度解耦。

use_signal() / subscribe() / dispatch() unidirectional data flow. Pure-function presentation layer + OOP state layer, deeply decoupled.

📡

CSP 并发管道

CSP Concurrency Channels

Pythonic Channel(背压/缓冲/安全关闭)、alts_ 公平多路选择、@go 后台协程调度器。

Pythonic Channel (backpressure/buffered/safe-close), alts_ fair multiplexing, @go background coroutine scheduler.

🔀

Transducers 渲染中间件

Transducers Middleware

DFS 不可变树变换管线。内置 LoadingTransducer(自动加载态)与 SanitizingTransducer(敏感数据脱敏)。

DFS immutable tree transformation pipeline. Built-in LoadingTransducer (auto-spinner) and SanitizingTransducer (data masking).

时间旅行调试器

Time-Travel Debugger

Signal.with_history() 状态快照,可视化撤销/重做面板,多会话安全隔离。

Signal.with_history() state snapshots. Visual undo/redo panel with multi-session isolation, out of the box.

🧬

Datalog 声明式查询

Datalog Declarative Query

Datomic 风格 EAVT/AVE/VAE 索引,Logic Unification 求解器,GraphQL-like Pull API,as_of 历史回溯。

Datomic-style EAVT/AVE/VAE indices, Logic Unification solver, GraphQL-like Pull API, as_of historical snapshot querying.

🎨

内置 DaisyUI + TailwindCSS

Built-in DaisyUI + TailwindCSS

开箱即用暗色毛玻璃组件库与原子化样式。零构建步骤,纯 Play CDN 运行时。

Dark-mode glassmorphic component library + utility-first styling out of the box. Zero build steps, pure Play CDN runtime.

🌿

Alpine.js 客户端加速

Alpine.js Client Acceleration

高频本地交互(60fps 计时器、滑块、手风琴)无需网络往返,标准 HTML 属性声明式激活。

High-frequency local interactions (60fps timers, sliders, accordions) without network round-trips. Declarative HTML attribute activation.

📦

100% 离线与内网就绪

100% Offline & Air-Gapped

所有静态依赖完全本地托管。物理隔离网络内高速运行,零外部 CDN 依赖。

All static dependencies hosted locally. Run at full speed in physically isolated networks with zero external CDN dependencies.

🛠 技术栈

🛠 Tech Stack

Hiccl 的全栈架构由五个精心编排的层次构成,每一层都聚焦于特定的职责。

Hiccl's full-stack architecture is composed of five carefully orchestrated layers, each focused on a specific responsibility.

🎯 Hiccl 内核

🎯 Hiccl Core

Signal 反应式引擎 · Hiccup DSL 渲染器 · 虚拟 DOM Diff · 会话管理 · 组件生命周期

Signal Reactive Engine · Hiccup DSL Renderer · Virtual DOM Diff · Session Management · Component Lifecycle

⚡ FastAPI / Starlette

⚡ FastAPI / Starlette

高性能异步 HTTP 服务 · WebSocket/SSE 双通道传输 · CORS 中间件 · 静态文件服务

High-Performance Async HTTP · WebSocket/SSE Dual Transport · CORS Middleware · Static File Serving

🌐 通信胶水层

🌐 Communication Glue

HTMX — 声明式请求拦截与降级 · hiccl.js — WebSocket 长连接管理 · DOM 补丁精准替换

HTMX — Declarative Request Interception & Fallback · hiccl.js — WebSocket Keep-Alive · DOM Patch Precision Replacement

🎨 样式 & 组件库

🎨 Styling & Components

TailwindCSS Play CDN 运行时 · DaisyUI 毛玻璃暗色组件 · 完全本地托管,零构建步骤

TailwindCSS Play CDN Runtime · DaisyUI Glassmorphic Dark Components · Fully Local Hosting, Zero Build Steps

🌿 客户端响应式

🌿 Client-Side Reactivity

Alpine.js — 轻量级客户端 MVVM · 高频本地交互无网络延迟 · 与 Hiccl 服务端状态无缝桥接

Alpine.js — Lightweight Client MVVM · High-Frequency Local Interactions · Seamless Bridge with Hiccl Server State

🎮 演示示例

🎮 Live Examples

从极简计数器到全维度特性大秀,探索 Hiccl 的每一种核心能力。每个示例都是可直接运行的完整应用。

From a minimal counter to a full-featured showcase, explore every core capability of Hiccl. Each example is a complete, runnable application.

🔢

响应式计数器

Reactive Counter

examples/counter/app.py · 88 lines

极简的响应式计数器组件。展示 signal 状态声明、@server 自动事件绑定与 Hiccup 声明式渲染——零模板、零 API 胶水。

Minimal reactive counter. Demonstrates signal state, @server auto event binding, and Hiccup declarative rendering — zero templates, zero API glue.

Signal@serverHiccup DSL
▶ 在线体验▶ Try Live
counter/app.py
class Counter(Component):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.count = signal(0)

    @server
    def increment(self, step: int = 1):
        self.count.set(self.count.get() + step)

    def render(self):
        count = self.count.get()
        return div({'class': 'card ...'},
            h2({}, f'Count: {count}'),
            button({'on_click': self.increment(1)}, '+1'),
        )

app = create_hiccl_app(HicclConfig(
    pages=menu(Counter),
))
$ uv run python examples/counter/app.py
🕰️

双时钟实时推送

Two Clocks — Real-Time Push

examples/two-clocks/app.py · 184 lines

服务端时间通过 SSE/WebSocket 高频推送,客户端时间由 Alpine.js 本地驱动。展示服务端推送与客户端加速的无缝协作。

Server time pushed via SSE/WebSocket, client time driven by Alpine.js locally. Demonstrates seamless server-push and client-acceleration collaboration.

SSE/WS PushAlpine.js60fps
▶ 在线体验▶ Try Live
two-clocks/app.py
class TwoClocks(Component):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self._server_time = signal(time.time() * 1000)

    def mount(self):
        self._task = asyncio.create_task(
            self._tick_loop()
        )

    async def _tick_loop(self):
        while self._running:
            if self._session.transport.is_connected():
                self._server_time.set(time.time() * 1000)
            await asyncio.sleep(0.016)  # ~60fps
$ uv run python examples/two-clocks/app.py
💬

多人实时聊天室

Multi-User Chat Room

examples/chat/app.py · 130 lines

多用户聊天室,通过 EventBus 跨会话广播实现所有用户实时同步。展示 topics 声明、on_broadcast 回调与 on_submit 自动绑定。

Multi-user chat with EventBus cross-session broadcasting for real-time sync. Demonstrates topics declaration, on_broadcast callback, and on_submit auto-binding.

EventBusCross-Sessionon_submit
▶ 在线体验▶ Try Live
chat/app.py
class ChatRoom(Component):
    topics = ["chat-messages"]

    @server
    def send_message(self, text: str, user: str = "Anonymous"):
        msg = {'user': user, 'text': text,
               'time': datetime.now().isoformat()}
        messages.append(msg)
        self.messages.set(list(messages))

    def on_broadcast(self, topic: str):
        if topic == "chat-messages":
            self.messages.set(list(messages))
$ uv run python examples/chat/app.py
🐚

WebShell 终端

WebShell Terminal

examples/webshell/app.py · 444 lines

基于 Hiccl 流式传输的 Web 终端。每个浏览器会话获得独立 PTY 伪终端,按键通过二进制流发送,PTY 输出通过流推送至 xterm.js 渲染,支持 ANSI 颜色、窗口尺寸同步与实时双向通信。

A real PTY terminal in the browser powered by Hiccl stream transport. Each session gets its own pseudo-terminal with keystrokes streamed over binary frames and PTY output rendered by xterm.js — full ANSI, window resize sync, and real-time bidirectional communication.

Stream TransportPTYxterm.js
▶ 在线体验▶ Try Live
webshell/app.py
class WebShellComponent(Component):
    async def on_stream_open(self, stream):
        self.pty = PtyProcess(detect_command())
        self.pty.start()
        self._tasks = [
            asyncio.create_task(self._pump_pty_to_stream()),
            asyncio.create_task(self._pump_stream_to_pty()),
            asyncio.create_task(self._watchdog()),
        ]

    async def _pump_pty_to_stream(self):
        data = await self._read_queue.get()
        await self.stream.send(data)

    async def _pump_stream_to_pty(self):
        async for data in self.stream:
            kind, value = parse_terminal_frame(bytes(data))
            if kind == 'resize':
                self.pty.resize(*value)
            else:
                self.pty.write(value)
$ uv run python examples/webshell/app.py

CSP 并发加密交易终端

CSP Crypto Trading Terminal

examples/csp-crypto-trader/app.py · 589 lines

实时加密货币交易模拟器。展示 CSP Channel 背压控制、alts_ 多路复用与超时、@go 后台协程、LoadingTransducer 与 SanitizingTransducer。

Real-time crypto trading simulator. Demonstrates CSP Channel backpressure, alts_ multiplexing with timeout, @go coroutines, LoadingTransducer & SanitizingTransducer.

CSP Channelalts_Transducers
▶ 在线体验▶ Try Live
csp-crypto-trader/app.py
class CryptoTrader(Component):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.trade_queue = Channel(maxsize=3)
        self.price_queue = Channel(maxsize=5)

    def mount(self):
        @go
        async def stream_orchestrator():
            selected, val = await alts_([
                self.price_queue, timeout(1500)
            ])
            if selected is self.price_queue:
                self._btc_price.set(val)
$ uv run python examples/csp-crypto-trader/app.py
🧪

时间旅行调试沙盒

Time-Travel Debug Sandbox

examples/time_travel_demo.py · 446 lines

Signal.with_history() 状态快照与可视化撤销/重做面板。展示局部 HistorySignal 与全局 re-frame DB 自动升级后的时间旅行调试。

Signal.with_history() state snapshots with visual undo/redo panel. Demonstrates local HistorySignal and global re-frame DB auto-upgrade time-travel debugging.

HistorySignalUndo/Redore-frame
▶ 在线体验▶ Try Live
time_travel_demo.py
class CounterBox(Component):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.count = signal_with_history(
            10, max_snapshots=20
        )

    @server
    def step_up(self):
        self.count.set(self.count.get() + 1)

    @server
    def multiply_two(self):
        self.count.set(self.count.get() * 2)
    # Built-in TimeTravelPanel for undo/redo
$ uv run python examples/time_travel_demo.py
🧬

Datalog 声明式查询引擎

Datalog Declarative Query Engine

examples/datalog_web_demo.py · 1250 lines

Datomic 风格的声明式逻辑查询引擎。展示 EAVT 索引、Logic Unification 求解器、GraphQL-like Pull API 与 as_of 历史回溯。

Datomic-style declarative logic query engine. Demonstrates EAVT indices, Logic Unification solver, GraphQL-like Pull API, and as_of historical queries.

DatalogPull APIEntity Graph
▶ 在线体验▶ Try Live
datalog_web_demo.py
# Flatten nested JSON into a queryable Database
db = Database.from_state({
    "name": "Volt Technologies",
    "employees": [
        {"id": "e1", "name": "Alice", "role": "Engineer"},
    ],
})

# Datalog-style declarative logic queries
results = db.solve(
    [Var("name"), Var("role")],
    [("?emp", "name", "?name"),
     ("?emp", "role", "?role")],
)
$ uv run python examples/datalog_web_demo.py
🛡️

全维度特性大秀

Full-Feature Premium Showcase

examples/premium_showcase.py · 1126 lines

Phase 0-4 全特性联合展示。包含 Signal/Computed/batch 反应式沙盒、Spec 契约校验、通配符 EventBus、CSP 管道与 re-frame 纯函数组件。

Phase 0-4 full-feature showcase. Includes Signal/Computed/batch sandbox, Spec contract validation, wildcard EventBus, CSP channels, and re-frame components.

SpecComputedbatchre-frame
▶ 在线体验▶ Try Live
premium_showcase.py
# Spec contracts guard @server method boundaries
UserSpec = spec.keys(req={
    "username": spec.string(min_len=3, max_len=20),
    "age": spec.integer(gte=18, lte=120),
})

@server(spec={"args": {"data": UserSpec}})
def update_profile(self, data: dict) -> bool:
    self.profile.set(data)
    return True
# SpecValidationError -> explain_data introspection
$ uv run python examples/premium_showcase.py

🚀 快速上手

🚀 Quick Start

30 行代码,从零到运行一个全栈响应式计数器。

30 lines of code, from zero to a running full-stack reactive counter.

1

安装 Hiccl

Install Hiccl

使用 pip 或 uv 安装框架本体。

Install the framework via pip or uv.

2

编写组件

Write Component

用 Hiccup DSL 声明 UI,用 @server 声明事件。

Declare UI with Hiccup DSL, declare events with @server.

3

启动服务

Launch Server

一行命令启动,浏览器即刻看到响应式界面。

One command to start the dev server. See your reactive UI instantly.

counter_app.py
from hiccl import (
    Component, ComponentRegistry,
    HicclConfig, create_hiccl_app,
    menu, server, signal,
)
from hiccl.hiccup import button, div, h2

registry = ComponentRegistry()

class Counter(Component):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.count = signal(0)

    @server
    def increment(self, step: int = 1):
        if isinstance(step, str):
            step = int(step)
        self.count.set(self.count.get() + step)

    @server
    def decrement(self, step: int = 1):
        if isinstance(step, str):
            step = int(step)
        self.count.set(self.count.get() - step)

    def render(self):
        count = self.count.get()
        return div(
            {"class": "card w-96 bg-base-200 shadow-xl mx-auto mt-10"},
            div({"class": "card-body items-center text-center"},
                h2({"class": "card-title text-3xl font-extrabold"},
                   f"Count: {count}"),
                div({"class": "card-actions justify-center gap-2"},
                    button({"class": "btn btn-error",
                            "on_click": self.decrement(1)}, "-1"),
                    button({"class": "btn btn-success",
                            "on_click": self.increment(1)}, "+1"),
                ),
            ),
        )

app = create_hiccl_app(HicclConfig(
    component_registry=registry,
    pages=menu(Counter),
    brand_name="Hiccl Quickstart"
))

if __name__ == "__main__":
    import uvicorn
    uvicorn.run(app, host="127.0.0.1", port=8000)

📦 安装 Hiccl

📦 Install Hiccl

一行命令即可将 Hiccl 添加到你的 Python 项目中。

Add Hiccl to your Python project with a single command.

📦使用 pipUsing pip
$ pip install hiccl
使用 uv(推荐)Using uv (recommended)推荐
$ uv add hiccl

GitHub 开源仓库

GitHub Repository

欢迎 ⭐ Star、🐛 Issue、🤝 PR!完整源码、210+ 单元测试、路线图尽在 GitHub。

Welcome ⭐ Star, 🐛 Issue, 🤝 PR! Full source code, 210+ unit tests, and roadmap all on GitHub.

Star