hiccl 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
hiccl-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,11 @@
1
+ Metadata-Version: 2.4
2
+ Name: hiccl
3
+ Version: 0.1.0
4
+ Summary: Hiccl Reactive Web Framework — Hiccup DSL + Python Pickle-like State
5
+ Author: Hiccl Contributors
6
+ License-Expression: MIT
7
+ Project-URL: Documentation, https://github.com/shiunko/hiccl
8
+ Project-URL: Repository, https://github.com/shiunko/hiccl
9
+ Requires-Python: >=3.11
10
+ Requires-Dist: fastapi>=0.110.0
11
+ Requires-Dist: python-multipart>=0.0.6
hiccl-0.1.0/README.md ADDED
@@ -0,0 +1,195 @@
1
+ # Hiccl — 全栈反应式 Python Web 框架 🧪🥒
2
+
3
+ <p align="center">
4
+ <strong>基于 Hiccup 声明式 DSL 表达与 Pythonic 状态序列化流动的现代化 Web 框架</strong>
5
+ </p>
6
+
7
+ <p align="center">
8
+ <a href="#-设计理念">设计理念</a> •
9
+ <a href="#-核心特性">核心特性</a> •
10
+ <a href="#-快速上手">快速上手</a> •
11
+ <a href="#-架构设计">架构设计</a> •
12
+ <a href="#-极速离线体验">极速离线体验</a>
13
+ </p>
14
+
15
+ ---
16
+
17
+ ## 🎨 命名与设计理念
18
+
19
+ **Hiccl**(读作 `/ˈhɪk.l̩/`,“Hick-le”)是 **Hiccup** 与 **Pickle** 的灵魂结晶:
20
+
21
+ * **Hiccup**:继承了 Clojure 的高贵血统。在 Hiccl 中,你不必编写任何 HTML 样板,全部 DOM 结构都可以用极其优雅的 Python 嵌套列表与数据结构(DSL)声明式表达。
22
+ * **Pickle**:散发着浓郁的 Pythonic 风味。代表着组件状态(State/Signal)的自动追踪与生命周期持久化。组件的状态随连接会话建立而自动管理,并通过极速的网络传输机制实现增量更新(Diff Patch)。
23
+
24
+ **Hiccl** 让 Clojure 式极简的声明式 UI 设计与 Pythonic 的全栈反应式交互在 FastAPI 上完美绽放!
25
+
26
+ ---
27
+
28
+ ## ⚡️ 核心特性
29
+
30
+ * **⚡️ 100% 声明式组件**:仅用嵌套 Python 列表(Hiccup)描述 UI,框架自动将 `on_click` 等事件绑定转化为底层的高能网络动作,没有繁琐的 AJAX/Fetch 胶水代码。
31
+ * **🔌 双向反应式状态**:基于 `Signal` 和 `Effect`,任何状态改变都会在服务端自动生成新的虚拟 DOM 并计算最小 Diff 补丁,通过 WebSockets 或 SSE(服务器发送事件)实时推送至前端。
32
+ * **🎨 内置 DaisyUI & TailwindCSS**:默认集成顶级暗色调毛玻璃组件库(DaisyUI)和原子化样式(TailwindCSS),开箱即用构建极其现代、高级的用户界面。
33
+ * **🌿 Alpine.js 客户端加速**:完全移除传统的 Hyperscript,深度整合 Alpine.js,支持以标准的 HTML 属性在浏览器端运行极速的交互渲染(如每秒 60 帧的高频计时器与毫秒级时差偏差计算)。
34
+ * **📦 100% 离线与内网就绪(Air-gapped Ready)**:所有静态依赖(`tailwind.js`、`daisyui.css`、`alpine.js`、`htmx.js`)完全本地托管于 `static/` 目录下。无需任何互联网连接即可在隔离的物理内网高速运行。
35
+ * **🔀 优雅的组件路由与自动导航菜单**:只需通过 `pages=menu(Counter, TwoClocks, ChatRoom)` 即可全自动生成对应的 kebab-case 格式路由路径与毛玻璃渐变顶栏导航。
36
+
37
+ ---
38
+
39
+ ## 🚀 快速上手
40
+
41
+ ### 1. 简易计数器组件 (`examples/counter/app.py`)
42
+
43
+ Hiccl 组件非常清爽,毫无杂质:
44
+
45
+ ```python
46
+ from hiccl import (
47
+ Component,
48
+ ComponentRegistry,
49
+ HicclConfig, # 全局配置依然保持极简
50
+ create_hiccl_app,
51
+ menu,
52
+ server,
53
+ signal,
54
+ )
55
+ from hiccl.hiccup import button, div, h2
56
+
57
+ registry = ComponentRegistry()
58
+
59
+
60
+ class Counter(Component):
61
+ """极简的响应式计数器。"""
62
+
63
+ def __init__(self, **kwargs):
64
+ super().__init__(**kwargs)
65
+ self.count = signal(0)
66
+
67
+ @server
68
+ def increment(self, step: int = 1):
69
+ if isinstance(step, str):
70
+ step = int(step)
71
+ self.count.set(self.count.get() + step)
72
+
73
+ @server
74
+ def decrement(self, step: int = 1):
75
+ if isinstance(step, str):
76
+ step = int(step)
77
+ self.count.set(self.count.get() - step)
78
+
79
+ @server
80
+ def reset(self):
81
+ self.count.set(0)
82
+
83
+ def render(self):
84
+ count = self.count.get()
85
+ return div(
86
+ {"class": "card w-96 bg-base-200 shadow-xl border border-base-300 mx-auto"},
87
+ div(
88
+ {"class": "card-body items-center text-center"},
89
+ h2(
90
+ {"class": "card-title text-3xl font-extrabold mb-4"},
91
+ f"Count: {count}",
92
+ ),
93
+ div(
94
+ {"class": "card-actions justify-center gap-2"},
95
+ button(
96
+ {
97
+ "class": "btn btn-outline btn-error",
98
+ "on_click": self.decrement(5),
99
+ },
100
+ "-5",
101
+ ),
102
+ button(
103
+ {"class": "btn btn-error", "on_click": self.decrement(1)}, "-1"
104
+ ),
105
+ button(
106
+ {"class": "btn btn-neutral", "on_click": self.reset}, "Reset"
107
+ ),
108
+ button(
109
+ {"class": "btn btn-success", "on_click": self.increment(1)},
110
+ "+1",
111
+ ),
112
+ button(
113
+ {
114
+ "class": "btn btn-outline btn-success",
115
+ "on_click": self.increment(5),
116
+ },
117
+ "+5",
118
+ ),
119
+ ),
120
+ ),
121
+ )
122
+
123
+
124
+ # 一键自动生成路由并挂载!
125
+ app = create_hiccl_app(HicclConfig(component_registry=registry, pages=menu(Counter)))
126
+
127
+ if __name__ == "__main__":
128
+ import uvicorn
129
+
130
+ uvicorn.run(app, host="127.0.0.1", port=8000)
131
+ ```
132
+
133
+ ---
134
+
135
+ ## 🛠 架构设计
136
+
137
+ Hiccl 在架构上高度分工,每个部分各司其职,保证了全栈反应式通信的极致顺畅:
138
+
139
+ ```mermaid
140
+ graph TD
141
+ Client[浏览器/客户端] -->|htmx / WebSockets| Server[FastAPI / Starlette 服务端]
142
+ Server -->|Session 管理| SessionStore[会话状态持久化]
143
+ SessionStore -->|挂载渲染| VDOM[Hiccup 声明式树]
144
+ VDOM -->|Signal 改变| DiffEngine[增量 Diff 引擎]
145
+ DiffEngine -->|最小补丁 HTML| WSChannel[WebSocket 实时推送通道]
146
+ WSChannel -->|自动局部置换 DOM| Client
147
+ ```
148
+
149
+ 1. **Hiccup UI 引擎**:负责将 Python 列表转化为标准 HTML。渲染时,带有 `@server` 修饰器的属性(如 `on_click`)会被智能捕捉并转化为底层的网络事件。
150
+ 2. **增量 Diff 引擎**:任何服务端的 `Signal` 状态变更触发 Effect。框架仅重新渲染脏组件,计算并提取最小补丁,以最小的数据开销实时更新客户端。
151
+ 3. **多路传输层(SSE/WebSockets)**:无缝支持高频实时状态同步。
152
+
153
+ ---
154
+
155
+ ## 🤖 为什么 Hiccl 天生适合 AI 时代?
156
+
157
+ 在 AI Agent(如 Antigravity)与 Copilot 成为核心生产力的今天,**传统的前后端分离(React/Vue + API + Backend)开发范式正在成为 AI 编写代码的沉重枷锁**。Hiccl 从底层架构上彻底消除了这一痛点:
158
+
159
+ 1. **🧩 单一语言与统一心智模型**:
160
+ - 告别在 TypeScript (前端) 与 Python (后端) 之间的频繁上下文切换。
161
+ - 整个应用(UI、响应式状态、事件处理器)100% 采用纯 Python 声明式编写。AI 程序员只需专注在一种语言、一个类中完成全栈功能。
162
+
163
+ 2. **🔌 零 API 胶水代码,杜绝接口对不齐**:
164
+ - 无需编写任何 REST 路由、Pydantic 序列化 Schema、Axios 抓取钩子或前端 Redux 状态管理。
165
+ - AI 只需要调用 `self.count.set(self.count.get() + 1)`,网络传输与状态同步完全由框架自动搞定,从根本上杜绝了接口不一致导致的“AI 幻觉”与联调报错。
166
+
167
+ 3. **🌿 纯数据结构声明 UI (Hiccup)**:
168
+ - Hiccl 使用声明式的 Python 数据结构表达 DOM(Hiccup DSL),规避了 HTML/JSX 标签未闭合或缩进错乱的问题。
169
+ - LLM 极其擅长生成结构化数据(如 Python 列表与函数嵌套)。此外,纯 Python 语法让 `mypy` / `pyright` 可以秒级进行静态类型检查,AI 能够实现高精度的“测试-报错-自愈”闭环。
170
+
171
+ 4. **⚡ 极致飞速的开发与自愈反馈**:
172
+ - 去除了前端繁琐的 Vite/Webpack 打包编译链。
173
+ - Hiccl 组件可以直接在 Python 内存中以毫秒级运行单元测试(**140 个测试仅需 0.3 秒!**)。超高速的反馈环能让 AI Agent 在几秒内完成十几次自主迭代,达到惊人的开发成功率。
174
+
175
+ ---
176
+
177
+ ## 📦 极速离线体验
178
+
179
+ Hiccl 天生为企业级内网而设计。只需运行以下三合一联合应用即可预览超级炫酷的多组件自动路由与极速切换:
180
+
181
+ ```bash
182
+ # 启动离线三合一演示(集成 Counter, TwoClocks, ChatRoom)
183
+ python3 examples/combined_app.py
184
+ ```
185
+
186
+ ### 演示亮点:
187
+ 1. **DaisyUI Chat**:进入 `/chat-room` 开启高颜值多人同步聊天。
188
+ 2. **DaisyUI Stats**:进入 `/two-clocks` 查看由 Alpine.js 驱动的毫秒级系统偏差统计图表。
189
+ 3. **完全断网测试**:你可以彻底拔掉电脑网线,你会发现导航、交互、动态刷新均毫无迟滞地正常工作,所有 JS/CSS 均完全由本地静态服务器提供。
190
+
191
+ ---
192
+
193
+ ## 📝 授权许可
194
+
195
+ 本项目采用 [MIT 许可证](LICENSE) 授权。
@@ -0,0 +1,61 @@
1
+ [project]
2
+ name = "hiccl"
3
+ version = "0.1.0"
4
+ description = "Hiccl Reactive Web Framework — Hiccup DSL + Python Pickle-like State"
5
+ requires-python = ">=3.11"
6
+ license = "MIT"
7
+ authors = [
8
+ { name = "Hiccl Contributors" },
9
+ ]
10
+
11
+ dependencies = [
12
+ "fastapi>=0.110.0",
13
+ "python-multipart>=0.0.6",
14
+ ]
15
+
16
+ [project.urls]
17
+ Documentation = "https://github.com/shiunko/hiccl"
18
+ Repository = "https://github.com/shiunko/hiccl"
19
+
20
+ [dependency-groups]
21
+ dev = [
22
+ "httpx>=0.27",
23
+ "pytest>=8.0",
24
+ "pytest-asyncio>=0.23",
25
+ "pytest-timeout>=2.2.0",
26
+ "uvicorn[standard]>=0.29",
27
+ ]
28
+
29
+ [build-system]
30
+ requires = ["setuptools>=68.0"]
31
+ build-backend = "setuptools.build_meta"
32
+
33
+ [tool.pytest.ini_options]
34
+ addopts = "-v --tb=short"
35
+ markers = [
36
+ "asyncio: marks tests as async",
37
+ "timeout: marks tests with timeout",
38
+ "integration: marks tests as integration tests requiring external services",
39
+ ]
40
+ testpaths = ["tests"]
41
+ asyncio_mode = "auto"
42
+ timeout = 60
43
+ timeout_method = "thread"
44
+
45
+ consider_namespace_packages = true
46
+
47
+ [tool.ruff.format]
48
+ quote-style = "double"
49
+ indent-style = "space"
50
+
51
+ [tool.ruff.lint.isort]
52
+ lines-after-imports = 2
53
+ no-sections = false
54
+ known-first-party = ["hiccl"]
55
+
56
+ [tool.setuptools.packages.find]
57
+ where = ["src"]
58
+
59
+ [[tool.uv.index]]
60
+ url = "https://mirrors.aliyun.com/pypi/simple"
61
+ default = true
hiccl-0.1.0/setup.cfg ADDED
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,137 @@
1
+ """Hiccl — Reactive Multi-Tier Web Framework."""
2
+
3
+ from hiccl.app import (
4
+ HicclConfig,
5
+ create_hiccl_app,
6
+ run_dev,
7
+ menu,
8
+ hiccl_default_layout,
9
+ hiccl_card_layout,
10
+ hiccl_raw_layout,
11
+ )
12
+ from hiccl.component import ActionRef, BoundAction, Component, server
13
+ from hiccl.eventbus import EventBus, event_bus
14
+ from hiccl.hiccup import (
15
+ a,
16
+ br_,
17
+ button,
18
+ div,
19
+ footer,
20
+ form,
21
+ fragment,
22
+ h1,
23
+ h2,
24
+ h3,
25
+ header,
26
+ hr_,
27
+ img,
28
+ input_,
29
+ label,
30
+ li,
31
+ main,
32
+ nav,
33
+ ol,
34
+ option,
35
+ p,
36
+ raw,
37
+ section,
38
+ select,
39
+ span,
40
+ table,
41
+ tbody,
42
+ td,
43
+ textarea,
44
+ th,
45
+ thead,
46
+ tr,
47
+ ul,
48
+ )
49
+ from hiccl.registry import ComponentRegistry, component, set_registry
50
+ from hiccl.renderer import HiccupRenderer, autobind
51
+ from hiccl.scheduler import RenderScheduler
52
+ from hiccl.session import Session
53
+ from hiccl.signal import ComputedSignal, Effect, Signal, batch
54
+ from hiccl.transport.protocol import NullTransport, Transport
55
+ from hiccl.diff import Diff, DiffEngine
56
+
57
+
58
+ def signal(initial):
59
+ """Create a new Signal with the given initial value."""
60
+ return Signal(initial)
61
+
62
+
63
+ __all__ = [
64
+ # Signal system
65
+ "Signal",
66
+ "ComputedSignal",
67
+ "Effect",
68
+ "batch",
69
+ "signal",
70
+ # Hiccup DSL
71
+ "div",
72
+ "h1",
73
+ "h2",
74
+ "h3",
75
+ "p",
76
+ "span",
77
+ "button",
78
+ "input_",
79
+ "ul",
80
+ "ol",
81
+ "li",
82
+ "a",
83
+ "form",
84
+ "label",
85
+ "select",
86
+ "option",
87
+ "textarea",
88
+ "img",
89
+ "br_",
90
+ "hr_",
91
+ "table",
92
+ "tr",
93
+ "td",
94
+ "th",
95
+ "thead",
96
+ "tbody",
97
+ "section",
98
+ "header",
99
+ "footer",
100
+ "nav",
101
+ "main",
102
+ "raw",
103
+ "fragment",
104
+ # Component system
105
+ "Component",
106
+ "ActionRef",
107
+ "BoundAction",
108
+ "server",
109
+ # Registry
110
+ "ComponentRegistry",
111
+ "set_registry",
112
+ "component",
113
+ # EventBus
114
+ "EventBus",
115
+ "event_bus",
116
+ # Renderer
117
+ "HiccupRenderer",
118
+ "autobind",
119
+ # Scheduler
120
+ "RenderScheduler",
121
+ # Session
122
+ "Session",
123
+ # Transport
124
+ "Transport",
125
+ "NullTransport",
126
+ # Diff Engine
127
+ "Diff",
128
+ "DiffEngine",
129
+ # App
130
+ "HicclConfig",
131
+ "create_hiccl_app",
132
+ "run_dev",
133
+ "menu",
134
+ "hiccl_default_layout",
135
+ "hiccl_card_layout",
136
+ "hiccl_raw_layout",
137
+ ]