API

Public surface

Stable entry points for Glue apps. Import as import glue after pip install glue-ui.

glue.expose

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

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.

glue.start

Positional args = start pages (before kwargs). Compact view below; expand for the full README table (Option / Default / Source / Hosts / Notes).

All glue.start() options

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
port80000 = pick a free port
blockTrueFalse returns; skips PyWebView in auto
jinja_templatesNoneJinja2 subfolder under UI root
close_callbackNoneOn window/WebSocket close
all_interfacesFalseTrusted networks only
disable_cacheTrueCache-Control: no-store
default_path'index.html'Page for /
appnew BottleCustom Bottle / middleware
shutdown_delay1.0Seconds after last window closes
splashFalseDiscover or select a transparent PNG/APNG/GIF startup splash (max height 500px)
splash_min_duration1.0Minimum visible seconds before fade-out
geometry{}Per-page size/position
app_modeTrueChromium --app
cmdline_argscache flagsChrome/Edge extras or custom argv
framelessTruePyWebView; Glue title bar
easy_dragFalseDrag frameless from empty area
shadowWin TrueWindow drop shadow
debugFalseDevTools / shortcuts
confirm_closeFalseConfirm before quit
fullscreenFalseStart fullscreen
minimizedFalseStart minimized
maximizedFalseStart maximized
on_topFalseAlways on top
min_size(200, 100)Minimum resize
iconui/favicon.icoTaskbar / caption favicon inject
guiautoPyWebView backend
menu[]Native menu bar
webview_options{}Escape hatch; kwargs win
size1280×720(width, height)
positionNone(left, top)
centeredNone → splashCenter the window; automatic with splash. Windows PyWebView uses the work area; other hosts use available-screen/host placement
title'Glue'Window / in-page title
resizableTrueUser resize; Win edge grips

Source: Glue / PyWebView / both · Hosts: all / webview / chrome/edge — see expanded table.

glue.settings / save_settings / settings_path

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 / glue.spawn

glue.sleep(1.0)
greenlet = glue.spawn(my_fn, arg1, kw=2)

Gevent-friendly; prefer these over blocking stdlib sleep in Glue apps.

glue.show

Open additional pages after start (same hosts / geometry rules).

glue.show('other.html')

glue.get_webview_windows

Returns the list of PyWebView window objects for advanced control when the host is PyWebView.

windows = glue.get_webview_windows()

glue.register_glue_routes

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)

JavaScript API

Include the bridge on every page before your app scripts:

<script type="text/javascript" src="/glue.js"></script>

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);
}

Call Python

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

Window identity

When you pass title= to glue.start, /glue.js applies it to document.title so Chrome/Edge captions match.

Geometry helpers

On Chrome/Edge, /glue.js can apply size / position / per-page geometry via resizeTo / moveTo after load.