utils.rcclient.libs.streamlit_utils.activity_tracker.inject_api

Module Contents

Classes

CustomRule

Functions

init_global_tornado_hook(rule_list)

Injects custom RESTful routes into the Streamlit application by

uninitialize_global_tornado_hook()

Uninitialize the global Tornado hook.

has_global_tornado_hook()

returns:

TRUE if the global Tornado hook is active, FALSE otherwise.

Attributes

_global_tornado_hook

_global_hook_lock

utils.rcclient.libs.streamlit_utils.activity_tracker.inject_api._global_tornado_hook
utils.rcclient.libs.streamlit_utils.activity_tracker.inject_api._global_hook_lock
class utils.rcclient.libs.streamlit_utils.activity_tracker.inject_api.CustomRule(path_pattern: str | tornado.routing.Matcher, handler_class: Any, target_kwargs: Dict[str, Any] | None = None, name: str | None = None)
utils.rcclient.libs.streamlit_utils.activity_tracker.inject_api.init_global_tornado_hook(rule_list: Iterable[CustomRule | tornado.routing.Rule])

Injects custom RESTful routes into the Streamlit application by intercepting the underlying Tornado web framework.

This function serves as a mechanism to add custom behavior to a Streamlit application without modifying its core logic. It ensures that the custom routes are injected only once, and that the native behavior of Streamlit is preserved for other routes.

Calling this function twice has no effect. To change the rule list, first call ‘uninitialize_global_tornado_hook’ and then call this function again with the new rule list.

Example

>>> from src.hooks.injectApi import (
>>>    init_global_tornado_hook, CustomRule
>>> )
>>> from tornado.web import RequestHandler
>>> class CustomHelloWorldHandler(RequestHandler):
>>>     def get(self):
>>>         self.write({
>>>             "text": "Hello World"
>>>         })
>>> init_global_tornado_hook(
>>>     [ CustomRule("/hello", CustomHelloWorldHandler) ]
>>> )
Parameters:
  • rule_list (Iterable[Union[CustomRule, Rule]]) – A list of custom rules

  • application. (to inject into the Streamlit)

Returns:

TRUE if the hooking mechanism was executed successfully, FALSE otherwise.

utils.rcclient.libs.streamlit_utils.activity_tracker.inject_api.uninitialize_global_tornado_hook()

Uninitialize the global Tornado hook.

This can be useful if you need to change the rules that are injected into the Streamlit application.’

Returns:

TRUE if the hooking mechanism was executed successfully, FALSE otherwise.

utils.rcclient.libs.streamlit_utils.activity_tracker.inject_api.has_global_tornado_hook()
Returns:

TRUE if the global Tornado hook is active, FALSE otherwise.