Trame Common Utilities
trame-common is a core component within the Trame ecosystem, providing dependency-less classes and functions for various trame packages like trame-client and trame-server. It offers a centralized collection of utilities for assets handling, decorators, asynchronous/throttled execution, and common Trame object patterns (Component, App, Widget, Singleton). While it is installable, it's primarily designed to be consumed as a dependency by other `trame` libraries rather than used standalone, enabling robust and efficient development across the Trame framework. Trame itself is an active, Python-based framework for creating interactive web applications with visual analytics, with a rapid release cadence for its main packages.
Warnings
- gotcha trame-common is intended as an internal dependency for the wider Trame ecosystem (e.g., trame-client, trame-server, trame itself) rather than a standalone end-user library. While you can install it, its full feature set and context are realized when used as part of a Trame application.
- gotcha Some modules within trame-common (e.g., those related to specific backend operations) may have implicit 'extra dependencies' that are not declared in trame-common's `setup.py`. The consuming `trame` package or your user application is expected to manage and declare these additional dependencies if specific `trame-common` modules are utilized.
- breaking The broader Trame ecosystem (which `trame-common` supports) transitioned its default client from Vue 2 to Vue 3 starting with Trame v3.9.0 (released April 2025). Existing Trame applications built with Vue 2 might encounter breaking changes in UI widgets or behavior if not explicitly configured to use `client_type="vue2"` or updated to be Vue 3 compatible.
Install
-
pip install trame-common
Imports
- throttle
from trame_common.exec import throttle
- Singleton
from trame_common.obj import Singleton
- get_mime_type
from trame_common.assets import get_mime_type
Quickstart
import time
from trame_common.exec import throttle
@throttle(delay=1)
def log_message(value):
print(f"Processing value: {value} at {time.time():.2f}")
print("Calling log_message rapidly (throttled to 1 call/sec):")
for i in range(5):
log_message(i)
time.sleep(0.2) # Call every 0.2 seconds
print("\nWaiting for throttle to reset (1.5 seconds) and calling again:")
time.sleep(1.5)
log_message("Final call")