trame-client

3.11.4 · active · verified Tue Apr 14

trame-client is the internal JavaScript core of the trame framework, providing client-side infrastructure for web applications. It handles connections to a trame server, state synchronization, method calls, dynamic component loading, and template feeding in the browser. It is typically installed as a dependency of the main 'trame' package and is not intended for direct end-user Python interaction. The current version is 3.11.4, and it follows the release cadence of the trame ecosystem.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates a basic Trame application, which implicitly uses `trame-client` for its client-side functionality. Since `trame-client` is an internal dependency, end-users typically interact with Trame through its main API and widgets. Run this Python script and navigate to the displayed URL in your browser.

from trame.app import get_server
from trame.ui.html import Div
from trame.widgets import html

# -----------------------------------------------------------------------------
# Trame setup (trame-client is implicitly used by trame)
# -----------------------------------------------------------------------------

server = get_server(name="trame_client_example")
# Explicitly set client_type for trame v3+ to manage Vue.js version
server.client_type = "vue3"

state, ctrl = server.state, server.controller

# 1. Initial state
state.value = 0
state.message = "Initial message"

# 2. Callbacks
@state.change("value")
def update_message(value, **kwargs):
    state.message = f"Value is now: {value}"

def increment():
    state.value += 1

# 3. UI definition using trame.widgets.html (which relies on trame-client)
with Div(classes="container") as main_layout:
    with html.Div("Hello Trame-client!", classes="text-h4 q-my-md"):
        pass
    with html.Div(classes="text-h6 q-my-md"):
        html.P("Current message: {{ message }}")
    with html.Button("Increment", click=increment, classes="q-mr-sm"):
        pass
    with html.Span("Value: {{ value }}", classes="q-ml-sm"):
        pass

# 4. Start server
if __name__ == "__main__":
    # This will open a browser window with the Trame application
    server.start()

view raw JSON →