Expose to Python
glue.expose(fn) or glue.expose(fn, "name") registers a JS function so Python can call glue.name()().
glue.expose(say_hello_js);
function say_hello_js(x) {
console.log(x);
}
API
Stable entry points for Glue apps. Import as import glue after pip install glue-ui.
Decorator (or function) to expose Python callables to JavaScript.
@glue.expose
def add(a, b):
return a + b
@glue.expose('renamed')
def internal_name():
return 1
From JS: await glue.add(1, 2)() — note the extra () for the callback / await pattern.
glue.init(
path='ui',
allowed_extensions=['.js', '.html', '.txt', '.htm', '.xhtml', '.vue'],
js_result_timeout=10000,
app_name=None,
)
path — UI root folder (default ui / web discovery).allowed_extensions — files scanned for glue.expose(...) so Python can call those JS names.js_result_timeout — ms to wait for JS return values.app_name — unlocks default settings path ~/.{app_name}/{app_name}.json.Positional args = start pages (before kwargs). Compact view below; expand for the full README table (Option / Default / Source / Hosts / Notes).
| Option | Default | Notes |
|---|---|---|
*(pages) | 'index.html' | HTML file(s) to open first (positional) |
mode | 'auto' | webview → chrome → edge — see Hosts |
host | 'localhost' | HTTP bind hostname |
port | 8000 | 0 = pick a free port |
block | True | False returns; skips PyWebView in auto |
jinja_templates | None | Jinja2 subfolder under UI root |
close_callback | None | On window/WebSocket close |
all_interfaces | False | Trusted networks only |
disable_cache | True | Cache-Control: no-store |
default_path | 'index.html' | Page for / |
app | new Bottle | Custom Bottle / middleware |
shutdown_delay | 1.0 | Seconds after last window closes |
splash | False | Discover or select a transparent PNG/APNG/GIF startup splash (max height 500px) |
splash_min_duration | 1.0 | Minimum visible seconds before fade-out |
geometry | {} | Per-page size/position |
app_mode | True | Chromium --app |
cmdline_args | cache flags | Chrome/Edge extras or custom argv |
frameless | True | PyWebView; Glue title bar |
easy_drag | False | Drag frameless from empty area |
shadow | Win True | Window drop shadow |
debug | False | DevTools / shortcuts |
confirm_close | False | Confirm before quit |
fullscreen | False | Start fullscreen |
minimized | False | Start minimized |
maximized | False | Start maximized |
on_top | False | Always on top |
min_size | (200, 100) | Minimum resize |
icon | ui/favicon.ico | Taskbar / caption favicon inject |
gui | auto | PyWebView backend |
menu | [] | Native menu bar |
webview_options | {} | Escape hatch; kwargs win |
size | 1280×720 | (width, height) |
position | None | (left, top) |
centered | None → splash | Center the window; automatic with splash. Windows PyWebView uses the work area; other hosts use available-screen/host placement |
title | 'Glue' | Window / in-page title |
resizable | True | User resize; Win edge grips |
Source: Glue / PyWebView / both · Hosts: all / webview / chrome/edge — see expanded table.
data = glue.settings() # or settings('/path.json')
glue.save_settings(data) # creates dirs on first write
path = glue.settings_path() # requires app_name
glue.sleep(1.0)
greenlet = glue.spawn(my_fn, arg1, kw=2)
Gevent-friendly; prefer these over blocking stdlib sleep in Glue apps.
Open additional pages after start (same hosts / geometry rules).
glue.show('other.html')
Returns the list of PyWebView window objects for advanced control when the host is PyWebView.
windows = glue.get_webview_windows()
Attach Glue routes to a custom Bottle app before glue.start(app=...). Usually automatic.
import bottle
import glue
app = bottle.Bottle()
glue.register_glue_routes(app)
glue.start(app=app)
Include the bridge on every page before your app scripts:
<script type="text/javascript" src="/glue.js"></script>
glue.expose(fn) or glue.expose(fn, "name") registers a JS function so Python can call glue.name()().
glue.expose(say_hello_js);
function say_hello_js(x) {
console.log(x);
}
Exposed Python functions appear on glue. Call with args, then an extra () to run (returns a Promise — use await).
let sum = await glue.add(1, 2)();
glue.add(1, 2)(console.log); // callback style
When you pass title= to glue.start, /glue.js applies it to document.title so Chrome/Edge captions match.
On Chrome/Edge, /glue.js can apply size / position / per-page geometry via resizeTo / moveTo after load.
| Option | Default | Source | Hosts | Notes |
|---|---|---|---|---|
*(pages) | 'index.html' | Glue | all | Which HTML file(s) to open first (positional args), they must come before keyword args |
mode | 'auto' | Glue | all | How to show the UI — see Hosts |
host | 'localhost' | Glue | all | Hostname the local HTTP server binds to |
port | 8000 | Glue | all | Server port (0 = pick a free port) |
block | True | Glue | all | Keep start() running until the app exits. False returns so you can run your own loop (skips PyWebView in auto; PyWebView needs True) |
jinja_templates | None | Glue | all | Subfolder of the UI root for Jinja2 templates |
close_callback | None | Glue | all | Called when a window/WebSocket closes (cleanup / last-window logic) |
all_interfaces | False | Glue | all | Listen on 0.0.0.0 and allow remote WebSocket clients (trusted networks only) |
disable_cache | True | Glue | all | Send no-store so the browser doesn’t cache UI assets during development |
default_path | 'index.html' | Glue | all | Page served for the root URL / (homepage) |
app | new Bottle | Glue | all | Optional custom Bottle app (e.g. auth/session middleware). Omit to let Glue create one |
shutdown_delay | 1.0 | Glue | all | Seconds to wait after the last window closes before the Python process exits |
splash | False | Glue | webview / chrome / edge / custom | True discovers a PNG/APNG/GIF named splash in the UI or project root; a path selects an explicit image. Images taller than 500px are scaled down with aspect ratio preserved. Requires glue-ui[splash] |
splash_min_duration | 1.0 | Glue | webview / chrome / edge / custom | Minimum visible seconds; both page readiness and this duration must complete before fade-out |
geometry | {} | Glue | webview / chrome / edge | Per-page size/position when opening multiple files. Keys = page paths; values = {'size': (w, h), 'position': (x, y)} (either key optional) |
app_mode | True | Glue | chrome/edge | Open Chromium in --app (desktop-like, less browser chrome) |
cmdline_args | ['--disable-http-cache'] | Glue | chrome/edge/custom | Chrome/Edge: extra flags. custom: full Popen argv |
frameless | True | PyWebView | webview | Hide the OS title bar; Glue draws its in-page title bar (False = stock OS chrome) |
easy_drag | False | PyWebView | webview | Allow dragging a frameless window from any empty area of the page |
shadow | True on Windows | PyWebView | webview | Draw a drop shadow around the window |
debug | False | PyWebView | webview | Enable DevTools / shortcuts (F12, F5, context menu) |
confirm_close | False | PyWebView | webview | Ask before quitting |
fullscreen | False | PyWebView | webview | Start covering the whole screen |
minimized | False | PyWebView | webview | Start in the taskbar/dock |
maximized | False | PyWebView | webview | Start maximized to the work area |
on_top | False | PyWebView | webview | Keep the window above other windows |
min_size | (200, 100) | PyWebView | webview | Smallest (width, height) the user can resize to |
icon | ui/favicon.ico if present | PyWebView | webview / chrome / edge | PyWebView: taskbar/dock. Chrome/Edge: caption from page favicon — Glue injects <link rel="icon"> when the file exists |
gui | auto | PyWebView | webview | Force backend ('edgechromium', 'qt', 'gtk', …) |
menu | [] | PyWebView | webview | Native menu bar; empty = no menus |
webview_options | {} | PyWebView | webview | Escape hatch for other PyWebView kwargs; first-class kwargs win on conflict |
size | None → 1280×720 | both | webview / chrome / edge | Initial content size as (width, height) pixels |
position | None | both | webview / chrome / edge | Initial screen position as (left, top); omit for host placement |
centered | None → splash default | both | webview / chrome / edge | Center the window. Automatically enabled with splash; use False to opt out. Explicit positions override the automatic default. Windows PyWebView uses the primary work area; Chrome/Edge/macOS/Linux use available-screen or host placement |
title | 'Glue' | both | webview | Text in the native/in-page title bar (Chrome/Edge use the page <title> / injected title) |
resizable | True | both | webview | Allow resize; on Windows frameless, Glue adds edge grips |
Source: Glue = Glue API · PyWebView = exposed PyWebView option · both = first-class on start and mapped for PyWebView. Hosts: which window host honors the option.