Skip to main content

pgwidgets-python logo

pgwidgets — Python Bindings

Python bindings for the pgwidgets JavaScript widget library. Build desktop-style browser UIs from Python with a familiar Qt/GTK-style API.

Documentation

Full documentation is available at pgwidgets-python.readthedocs.io.

Installation

pip install pgwidgets-python

This will also install pgwidgets-js (the JavaScript assets) and websockets as dependencies.

Quick Start

from pgwidgets.sync import Application

app = Application()

@app.on_connect
def setup(session):
    Widgets = session.get_widgets()

    top = Widgets.TopLevel(title="Hello", resizable=True)
    top.resize(400, 300)

    vbox = Widgets.VBox(spacing=8, padding=10)
    btn = Widgets.Button("Click me")
    label = Widgets.Label("Ready")

    btn.on("activated", lambda: label.set_text("Clicked!"))

    vbox.add_widget(btn, 0)
    vbox.add_widget(label, 1)
    top.set_widget(vbox)
    top.show()

app.run()

Run the script, then open the printed URL in your browser.

Sync vs Async

Both APIs provide the same widget classes and methods.

Synchronous (recommended for most use cases):

from pgwidgets.sync import Application
app = Application()

@app.on_connect
def setup(session):
    Widgets = session.get_widgets()
    btn = Widgets.Button("Click")      # blocking call
    btn.set_text("New text")           # blocking call

app.run()

Asynchronous (for asyncio applications):

from pgwidgets.async_ import Application
app = Application()

@app.on_connect
async def setup(session):
    Widgets = session.get_widgets()
    btn = await Widgets.Button("Click")    # awaitable
    await btn.set_text("New text")         # awaitable

await app.run()

How It Works

The Application class starts two servers:

  • An HTTP server (default port 9501) that serves the pgwidgets JS/CSS and a connector page
  • A WebSocket server (default port 9500) for the JSON command protocol

When you open the URL in a browser, the page loads pgwidgets and connects back over WebSocket. Python widget constructors and method calls are translated to JSON messages and executed in the browser. Callbacks are forwarded back to Python.

Sessions and Reconnection

Sessions persist independently of browser connections. When a browser disconnects (page refresh, network drop, tab close), the session and its widget tree remain alive on the Python side. When the browser reconnects, the entire UI is automatically reconstructed.

app = Application(max_sessions=4, logger=logger)

@app.on_connect
def setup(session):
    Widgets = session.get_widgets()
    # Build your UI...
    # If the browser refreshes, this UI is reconstructed automatically.

Key features:

  • Automatic reconstruction -- refresh the browser and the UI reappears in its current state (widget positions, text, slider values, etc.).
  • Multi-browser support -- open the same session URL in a second browser tab or window. Both browsers show the same UI and stay synchronized. Widget state changes (slider moves, tab switches, tree expand/collapse) are pushed to all connected browsers in real time.
  • Headless sessions -- create sessions without a browser using app.create_session(), build the widget tree, then connect a browser later to see the pre-built UI.

License

BSD 3-Clause

Metadata

Release files for pgwidgets-python 0.4.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pgwidgets-python 0.4.3
File Size Uploaded Provenance Actions
pgwidgets_python-0.4.3.tar.gz 2.6 MB Without provenance Details for pgwidgets_python-0.4.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pgwidgets-python 0.4.3
File Interpreter ABI Platform Actions
pgwidgets_python-0.4.3-py3-none-any.whl Python 3 none any Details for pgwidgets_python-0.4.3-py3-none-any.whl

Total release size: 5.2 MB

Release files / pgwidgets_python-0.4.3.tar.gz

Download URL pgwidgets_python-0.4.3.tar.gz
Size 2.6 MB
Tags Source
SHA-256 checksum
How to use checksums
903f60aff96ae9998bde0f5b97bf6b6712f4fa0bbb8aaa1a0b50db8e7206fa60
BLAKE2b-256 checksum
How to use checksums
6aa5100b4f29b1d180ac6ce2dad0004320de6b3e7e2b167a274c4f1112ab594d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.12

Release files / pgwidgets_python-0.4.3-py3-none-any.whl

Download URL pgwidgets_python-0.4.3-py3-none-any.whl
Size 2.5 MB
Tags Python 3
SHA-256 checksum
How to use checksums
b7cb55efd6d99c481e843a2f0baa25a26f89474b517ec877ae082df00524cce5
BLAKE2b-256 checksum
How to use checksums
5c6a606ddea2780d640b455de57c5c1074c12f839bb8e1792b02879710dec6df
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.12

Security for pgwidgets-python 0.4.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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