Skip to main content

aspectly-bridge (Python / WebKitGTK)

PyPI

Type-safe, bidirectional bridge between native Python code and JavaScript running in a WebKitGTK web view (Linux desktop). Speaks the Aspectly protocol, so the same @aspectly/core web content runs unchanged across every host.

WebKitGTK uses the same JS mechanism as WKWebView (window.webkit.messageHandlers.aspectly), so the embedded web content auto-detects this host through the existing @aspectly/transports WebKit transport — no Flutter/Android-style extra transport needed.

Install

pip install aspectly-bridge

# For the WebKitGTK browser bridge (Linux):
#   system packages: gobject-introspection, gir1.2-webkit2-4.1 (or 4.0)
pip install "aspectly-bridge[webkitgtk]"

The core (BridgeHost) is pure Python with no dependencies. Only the WebKitGTKBrowserBridge needs PyGObject + WebKit2GTK (Linux).

Usage

from aspectly_bridge import BridgeHost
from aspectly_bridge.webkitgtk import WebKitGTKBrowserBridge

bridge = BridgeHost(WebKitGTKBrowserBridge(web_view))

# Register handlers JS can call (before initialize).
bridge.register_handler("ping", lambda params: "pong")
bridge.register_handler("add", lambda params: params["a"] + params["b"])

# Initialize (returns a Future; resolves when the handshake completes).
bridge.initialize().result()

# Call a JS method (returns a Future).
result = bridge.send("greet", {"name": "Python"}).result()
print(result["message"])

send and initialize return concurrent.futures.Future. In a GTK app, the result is delivered on the GLib main thread, so use future.add_done_callback or GLib.idle_add rather than blocking .result() on the UI thread.

API

BridgeHost(browser_bridge, logger=None, timeout_ms=100000)

register_handler(method, handler)     # handler(params) -> result
unregister_handler(method)
initialize(handlers=None) -> Future
send(method, params=None, timeout_ms=None) -> Future
process_message(message_json)

is_initialized        # bool
supported_methods     # list[str]  (JS-side methods)
registered_methods    # list[str]  (Python-side handlers)
on_initialized        # callable or None
dispose()

send / handlers surface BridgeException with error_type one of BridgeErrorType.{UNSUPPORTED_METHOD, METHOD_EXECUTION_TIMEOUT, REJECTED, BRIDGE_NOT_AVAILABLE}.

Testing

cd python
python -m pytest          # the pure-Python core (no GTK required)

See examples/webkitgtk for a runnable GTK app.

Other platforms

This is the Python / WebKitGTK host (PyPI aspectly-bridge, 2.1.0). The same Aspectly protocol ships for Web (@aspectly/web), React Native (@aspectly/react-native), React Native Web/Expo (@aspectly/react-native-web), .NET CefSharp/WebView2 (Aspectly.Bridge.CefSharp / Aspectly.Bridge.WebView2), iOS/macOS/visionOS (AspectlyBridge), Android (io.github.jeanisahakyan:aspectly-bridge), and Flutter (aspectly_bridge) — all at version 2.1.0. See the repository README for the full platform matrix.

License

MIT

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aspectly_bridge-2.2.0.tar.gz (10.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aspectly_bridge-2.2.0-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

Details for the file aspectly_bridge-2.2.0.tar.gz.

File metadata

  • Download URL: aspectly_bridge-2.2.0.tar.gz
  • Upload date:
  • Size: 10.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for aspectly_bridge-2.2.0.tar.gz
Algorithm Hash digest
SHA256 1809f4272120e00b0a1c9c86e5f8f1a65691abde9e266478d062252580a686f7
MD5 9bcdec1aa0aa7f23749f6714574eb3c9
BLAKE2b-256 5c83476a51c545362b332f9b13e9f9f524e661b5ef77e2d92dbe97101dfd6195

See more details on using hashes here.

Provenance

The following attestation bundles were made for aspectly_bridge-2.2.0.tar.gz:

Publisher: release.yml on JeanIsahakyan/aspectly

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file aspectly_bridge-2.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for aspectly_bridge-2.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 32a9ec98aeed0be81ef13565e50d085bf9afbeadde82dfaf4bc84b476db1be9c
MD5 6d90fd21b4412ad94566248be1ee9f9e
BLAKE2b-256 ce3a79ab1d6d24c4f55d7b4f9f4413feb4a6b85a4573ba85573f94baa05ebe4c

See more details on using hashes here.

Provenance

The following attestation bundles were made for aspectly_bridge-2.2.0-py3-none-any.whl:

Publisher: release.yml on JeanIsahakyan/aspectly

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

2.2.0 This release

2 files

2.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page