Trame Server
Trame-server is the internal server-side implementation of the Trame web framework. It provides the core server logic for managing shared state, controllers, and the web server itself. While it can run in various environments like Jupyter or as a standalone desktop application, it's primarily designed to be a dependency of the higher-level `trame` package rather than being used directly by end-users. It is under active development.
Warnings
- breaking Trame v3 (which `trame-server` is part of) changed the default client framework from Vue2 to Vue3 around January 2024. Existing Trame applications built with Vue2 may break or behave unexpectedly.
- breaking Trame v3 no longer bundles all widgets as implicit dependencies. Core widgets like `trame.widgets.html` and `trame.widgets.client` remain, but other common widget sets (e.g., Vuetify, VTK, Plotly) must now be explicitly installed.
- deprecated The `trame.app.jupyter` package has been removed in Trame v3. Its functionalities for Jupyter integration are now directly handled by the layout components.
- gotcha `trame-server` is an internal implementation package. Direct usage and instantiation of its core components (e.g., `trame_server.core.Server`) are generally discouraged.
Install
-
pip install --upgrade trame-server
Imports
- get_server
from trame.app import get_server
Quickstart
from trame.app import get_server
from trame.ui.vuetify import SinglePageLayout
from trame.widgets import vuetify
# 1. Get a server instance
server = get_server(client_type="vue3") # Explicitly set client_type for V3 compatibility
# 2. Add application logic to the state and controller
state, ctrl = server.state, server.controller
state.count = 0
@state.change('count')
def update_title(count, **kwargs):
ctrl.trame.title(f'Count is {count}')
@ctrl.add('reset_count')
def reset():
state.count = 0
# 3. Create the UI
with SinglePageLayout(server) as layout:
layout.title.set_text("Trame Counter")
with layout.content:
with vuetify.VContainer(fluid=True):
with vuetify.VRow(classes="fill-height", align="center", justify="center"):
with vuetify.VCol(cols=4):
vuetify.VSlider(
label="Count",
min=0,
max=100,
step=1,
v_model=("count", 0) # Bind to state.count
)
vuetify.VBtn("Reset", click=ctrl.reset_count)
# 4. Start the server
if __name__ == "__main__":
server.start()