Trame Server

3.10.0 · active · verified Tue Apr 14

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

Install

Imports

Quickstart

This basic example demonstrates how to set up a Trame server, define a reactive state variable ('count'), create a simple UI with a slider and a button using `trame-vuetify`, and bind UI elements to the server's state and controller. It explicitly sets `client_type='vue3'` for V3 compatibility, which is the default for current Trame versions.

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()

view raw JSON →