Provide a Bokeh Application Handler to build up documents by running the code from or main.ipynb files in specified directories.

The directory may also optionally contain:

  • A module to provide lifecycle callbacks for the application and sessions.

  • A static subdirectory containing app-specific static resources to serve.

  • A theme.yaml file containing a Bokeh theme to automatically apply to all new documents.

  • A templates subdirectory containing templates for app display

A full directory layout might look like:

class DirectoryHandler(*, filename: PathLike, argv: list[str] = [])[source]#

Load an application directory which modifies a Document.

__init__(*, filename: PathLike, argv: list[str] = []) None[source]#

filename (str) : a path to an application directory with either “” or “main.ipynb”

argv (list[str], optional) : a list of string arguments to make available as sys.argv to

modify_document(doc: Document) None[source]#

Execute the configured or main.ipynb to modify the document.

This method will also search the app directory for any theme or template files, and automatically configure the document with them if they are found.

on_server_loaded(server_context: ServerContext) None[source]#

Execute on_server_unloaded` from (if it is defined) when the server is first started.


server_context (ServerContext) –

on_server_unloaded(server_context: ServerContext) None[source]#

Execute on_server_unloaded from (if it is defined) when the server cleanly exits. (Before stopping the server’s IOLoop.)


server_context (ServerContext) –


In practice this code may not run, since servers are often killed by a signal.

on_session_created(session_context: SessionContext) Coroutine[Any, Any, None][source]#

Execute on_session_created from (if it is defined) when a new session is created.


session_context (SessionContext) –

on_session_destroyed(session_context: SessionContext) Coroutine[Any, Any, None][source]#

Execute on_session_destroyed from (if it is defined) when a session is destroyed.


session_context (SessionContext) –

process_request(request: HTTPServerRequest) dict[str, Any][source]#

Processes incoming HTTP request returning a dictionary of additional data to add to the session_context.


request – HTTP request


A dictionary of JSON serializable data to be included on the session context.

url_path() str | None[source]#

The last path component for the basename of the path to the configured directory.

property error: str | None#

If the handler fails, may contain a related error message.

property error_detail: str | None#

If the handler fails, may contain a traceback or other details.

property failed: bool#

True if the handler failed to modify the doc

property safe_to_fork: bool#

Whether it is still safe for the Bokeh server to fork new workers.

False if the configured code (script, notebook, etc.) has already been run.