pysepal.solara.decorators.with_sepal_sessions#
- pysepal.solara.decorators.with_sepal_sessions(module_name='default', error_handler=None)[source]#
Decorator that establishes this runtime’s session before the Page renders.
Required under an app-launcher Solara server, optional everywhere else. There the session is per connection, built from that connection’s SEPAL headers, and those are readable only on a thread carrying that connection’s kernel context – the render thread and any thread started from it, but not a thread-pool worker. Nothing can build one lazily, so
get_current_gee_interface()raisesSepalSessionErroron a connection whose Page never ran the decorator. It is keyed by connection rather than by route: in a multipage app an undecorated route reuses the session a decorated one established.In a SEPAL sandbox, under Voila, in plain Jupyter, in a script, or wherever
PYSEPAL_DEV_AUTHis armed, the session belongs to the process and the firstget_current_*call builds it. Two reasons to write the decorator there anyway:It sets the default
module_name. An accessor may still pass one per call, but only the decorator makes the choice stick for the bare calls afterwards; without it they get"default".It wraps the whole render – the session build and the component body – so any exception becomes a
solara.Errorin the page, or reacheserror_handler. That breadth has a cost: a body that raises after calling hooks is swallowed here, and reacton then reports a misleading “Previously render had N effects” hook-count error next to the alert.
The credential source follows runtime topology, never header probing; see
pysepal.solara._topologyfor the rules and their limits.- Parameters:
module_name (str) – The module name for the SepalClient.
error_handler (Callable[[Exception], None] | None) – Custom error handler function. If None, uses default error handling.
- Returns:
Decorator function.
Example
@solara.component @with_sepal_sessions(module_name="my.module") def Page(): gee_interface = get_current_gee_interface() sepal_client = get_current_sepal_client() solara.Markdown("GEE interface is ready!")