Trame Common Utilities

1.1.3 · active · verified Wed Apr 15

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

Install

Imports

Quickstart

This example demonstrates a direct use of a utility from `trame_common.exec`, specifically the `throttle` decorator. It showcases how `trame-common` provides useful functions that can be integrated into Python code, often within a larger Trame application, to control execution frequency. The function `log_message` will be called at most once every second, despite being invoked more frequently.

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

view raw JSON →