Lifecycle Hooks

How do I use lifecycle hooks within a Flask app?

When using them, how I refer to them within the document (bkapp(doc))?
i.e. how do I save things to a ‘BokehServerContext’ object? How do i then reference this within the file?

You can use lifecycle hooks in a Flask context, but it is an advanced and uncommon thing to do, and does not have all the conveniences that the “directory format” bokeh server apps with an file has. You will have to create an actual handler class to configure on the application:

from bokeh.application import Application
from bokeh.application.handlers import FunctionHandler
from bokeh.application.handlers.lifecycle import LifecycleHandler
class MyHandler(LifecycleHandler):
    def on_server_loaded(self, server_context):
        print("SERVER LOADED")
bkapp = Application(FunctionHandler(bkapp), MyHandler())