Application¶
- class Application(*args, **kwargs)[source]¶
Bases:
objectSupervisely application runtime built on top of FastAPI and widgets.
- Parameters:
- layout :
Widget Main layout of the application.
- templates_dir : str, optional
Directory with Jinja2 templates. It is preferred to use
layoutinstead oftemplates_dir.- static_dir : str, optional
Directory with static files (e.g. CSS, JS), used for serving static content.
- hot_reload : bool, optional
Whether to enable hot reload during development (default is False).
- session_info_extra_content :
Widget, optional Additional content to be displayed in the session info area.
- session_info_solid : bool, optional
Whether to use solid background for the session info area.
- ready_check_function : Callable, optional
Function to check if the app is ready for requests.
- show_header : bool, optional
Whether to show the header in the application.
- hide_health_check_logs : bool, optional
Whether to hide health check logs in info level.
- health_check_endpoints : List[str], optional
List of additional endpoints to check health of the app. Add your custom endpoints here to be able to manage logging of health check requests on info level with
hide_health_check_logs.
- layout :
Methods
call_before_shutdownDecorator to register posts to specific endpoints.
get_serverget_static_dirContextmanager to suppress StopException and control graceful shutdown.
Indicates whether the application is in the process of being terminated.
reload_pagerenderset_ready_check_functionshutdownstop- exception StopException[source]¶
Bases:
ExceptionRaise to stop the function from running in app.handle_stop
- add_note()¶
Exception.add_note(note) – add a note to the exception
- with_traceback()¶
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
-
event(event, use_state=
False)[source]¶ Decorator to register posts to specific endpoints. Supports both async and sync functions.
- Parameters:
- Returns:
decorator
- Return type:
Callable
- Usage Example:
import supervisely as sly app = sly.Application(layout=layout) @app.event(sly.Event.Brush.LeftMouseReleased) def some_function(api: sly.Api, event: sly.Event.Brush.LeftMouseReleased): # do something pass
-
handle_stop(graceful=
True)[source]¶ Contextmanager to suppress StopException and control graceful shutdown.
- Parameters:
- graceful=
True¶ Whether to perform a graceful shutdown if a StopException is raised.
- graceful=
If set to
Falseand shutdown request recieved (i.e.app.is_stopped()isTrue), the application will be terminated immediately, defaults toTrue:type graceful: bool :returns: context manager :rtype: _type_