trame-client
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
- breaking Trame v3 (and by extension, trame-client in its context) changed the default client type from Vue 2 to Vue 3 starting December 2023. Existing applications built with Vue 2 components might break if not explicitly configured.
- breaking With trame v3, the default dependency list was shrunk. Core widgets like Vuetify, VTK, and Plotly are no longer bundled by default with the main `trame` package. They must be installed separately as `trame-vuetify`, `trame-vtk`, `trame-plotly`, etc.
- gotcha trame-client is primarily a client-side (JavaScript) library bundled for Python's trame framework. It is not intended for direct Python imports or standalone usage for application logic. All client-side interactions are abstracted and managed by the main `trame` library.
- gotcha When deploying Trame applications, a common issue is the client loading screen appearing before the Trame server's WebSocket connection is fully established, leading to a 'connection_error'.
Install
-
pip install trame-client -
pip install trame
Imports
- trame.widgets.html
from trame.widgets import html
Quickstart
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()