ultralight-py DOCSshabbywu/ultralight-py

PYTHON × WEB × NATIVE

用 Web 构建界面,
让 Python 驱动。

Ultralight 2.x 的 Python 绑定。把 HTML、CSS 和 JavaScript 带到原生桌面,用熟悉的 Python 编写应用逻辑。

Python 3.10+ / Windows · Linux · macOS

INSTALL
python -m pip install ultralight-py
安装说明 →

01 / THE TOOLKIT

从一个窗口,到双向连接。

界面、逻辑与数据,在同一个应用中协作。

02 / YOUR FIRST APPLICATION

从这几行开始。

完整快速开始 →

一个窗口,一次跨语言调用。

先注册 Python 函数,将 API 附着到窗口的 View,再加载页面。JavaScript 直接从命名空间调用函数。

窗口循环由 AppCore 驱动;离屏脚本可以选择 ScriptDriver.auto()。

了解 API 注册与导航恢复 →
示例在本地 Python 中运行。安装 wheel 即包含引擎与运行资源,无需单独下载 SDK。
hello.pyPYTHON
from ultralight_py import API, Application

with API("app") as api, Application() as app:

    @api.register
    def hello(name):
        return f"你好,{name}!"

    window = app.create_window(800, 520, title="Hello, ultralight-py")
    api.attach(window.view)
    window.view.load_html("""
        <style>
          body { background: #111315; color: #edb584;
                 font: 24px system-ui; padding: 48px; }
        </style>
        <h1 id="hello"></h1>
        <script>
          document.querySelector('#hello').textContent = app.hello('世界');
        </script>
    """)
    app.run()

03 / THE REFERENCE

找到你需要的接口。

全部 API →

04 / BUILT WITH ULTRALIGHT-PY

看看它们如何组合。

进入 Showcase ↗

从桥接实验到桌面游戏,查看原生运行效果、实现思路与源码。

搜索文档

输入关键词搜索 API 与使用指南

    ↑ ↓ 选择 · Enter 打开 · Esc 关闭