Trame
Trame is an easy-to-use, Python-based framework that lets you create web applications with interactive scientific visualization. It simplifies web development by managing UI layout, state, events, and widgets entirely in Python, abstracting away the need for HTML, CSS, or JavaScript. Trame applications can run locally, remotely, in the cloud, in Jupyter, or on HPC. The library maintains an active release cadence, with version 3.12.0 being the latest stable release.
Warnings
- breaking Trame v3 changed the default client type from Vue2 to Vue3 in January 2024. Existing applications built with Trame v2 that relied on Vue2 components will need to explicitly set `server.client_type = "vue2"` or migrate to Vue3 components.
- breaking In Trame v3, 'trame-vuetify' and 'trame-vtk' are no longer bundled by default with the core `trame` package. They must be installed separately if you intend to use Vuetify UI components or VTK visualizations.
- deprecated The `trame.app.jupyter` package has been removed in Trame v3 as Jupyter integration is now directly part of the layouts. The `trame.app.dev` package is also considered deprecated and generally not needed for 99.99% of users.
- gotcha When combining Trame with custom command-line argument parsers (e.g., `argparse`), ensure that your arguments do not overlap with Trame's built-in server arguments.
- gotcha API changes in underlying front-end libraries (like Vuetify from v2 to v3) can affect Trame widgets, even if Trame itself aims for API compatibility.
Install
-
pip install trame
Imports
- get_server
from trame.app import get_server
- SinglePageLayout
from trame.ui.vuetify3 import SinglePageLayout
- v3
from trame.widgets import vuetify3 as v3
Quickstart
from trame.app import get_server
from trame.ui.vuetify3 import SinglePageLayout
from trame.widgets import vuetify3 as v3
server = get_server(client_type="vue3") # Explicitly set for clarity in v3+ apps
server.state.name = "Trame"
with SinglePageLayout(server) as layout:
layout.title.set_text("Hello Trame")
with layout.content:
with v3.VContainer(classes="fill-height", fluid=True):
with v3.VRow(classes="fill-height", align="center", justify="center"):
with v3.VCol(cols=12, sm=6, md=4):
v3.VCard(
v3.VCardTitle(classes="headline", children=["Welcome to ", ('name', 'Trame App')]),
v3.VCardText("This is a simple Trame application running in Vue3!"),
v3.VCardActions(
v3.VSpacer(),
v3.VBtn('Click me!', click='server.state.name = "Updated Trame"'),
v3.VSpacer(),
)
)
if __name__ == '__main__':
server.start()