bokeh.server.server (original) (raw)

Provide basic Bokeh server objects that use a Tornado HTTPServer andBokeTornado Tornado Application to service Bokeh Server Applications. There are two public classes in this module:

BaseServer

This is a lightweight class to explicitly coordinate the components needed to run a Bokeh server (A BokehTornadoinstance, and Tornado HTTPServer and a Tornado IOLoop)

Server

This higher-level convenience class only needs to be configured with BokehApplication instances, and will automatically create and coordinate the lower level Tornado components.

See Server introduction for general information on the Bokeh server.

class BaseServer(io_loop: IOLoop, tornado_app: BokehTornado, http_server: HTTPServer)[source]#

Explicitly coordinate the level Tornado components required to run a Bokeh server:

All three of these components must be passed to BaseServer, which will initialize the BokehTornado instance on the io_loop. Thehttp_server must have been previously created and initialized with theBokehTornado instance.

__init__(io_loop: IOLoop, tornado_app: BokehTornado, http_server: HTTPServer) → None[source]#

Create a BaseServer instance.

Parameters:

get_session(app_path: str, session_id: ID) → ServerSession[source]#

Get an active a session by name application path and session ID.

Parameters:

Returns:

ServerSession

get_sessions(app_path: str | None = None) → list[ServerSession][source]#

Gets all currently active sessions for applications.

Parameters:

app_path (str, optional) – The configured application path for the application to return sessions for. If None, return active sessions for all applications. (default: None)

Returns:

list[ServerSession]

run_until_shutdown() → None[source]#

Run the Bokeh Server until shutdown is requested by the user, either via a Keyboard interrupt (Ctrl-C) or SIGTERM.

Calling this method will start the Tornado IOLoop and block all execution in the calling process.

Returns:

None

show(app_path: str, browser: str | None = None, new: BrowserTarget = 'tab') → None[source]#

Opens an app in a browser window or tab.

This method is useful for testing or running Bokeh server applications on a local machine but should not call when running Bokeh server for an actual deployment.

Parameters:

Returns:

None

start() → None[source]#

Install the Bokeh Server and its background tasks on a TornadoIOLoop.

This method does not block and does not affect the state of the Tornado IOLoop You must start and stop the loop yourself, i.e. this method is typically useful when you are already explicitly managing an IOLoop yourself.

To start a Bokeh server and immediately “run forever” in a blocking manner, see run_until_shutdown().

stop(wait: bool = True) → None[source]#

Stop the Bokeh Server.

This stops and removes all Bokeh Server IOLoop callbacks, as well as stops the HTTPServer that this instance was configured with.

Parameters:

wait (bool) – Whether to wait for orderly cleanup (default: True)

Returns:

None

unlisten() → None[source]#

Stop listening on ports. The server will no longer be usable after calling this function.

Note

This function is mostly useful for tests

Returns:

None

property address_: str | None_#

The configured address that the server listens on for HTTP requests

property index_: str | None_#

A path to a Jinja2 template to use for index at “/”

property io_loop_: IOLoop_#

The Tornado IOLoop that this Bokeh Server is running on.

property port_: int | None_#

The configured port number that the server listens on for HTTP requests

property prefix_: str_#

The configured URL prefix to use for all Bokeh server paths.

class Server(applications: Mapping[str, Application | ModifyDoc] | Application | ModifyDoc, io_loop: IOLoop | None = None, http_server_kwargs: dict[str, Any] | None = None, **kwargs: Any)[source]#

A high level convenience class to run a Bokeh server.

This class can automatically coordinate the three the base level components required to run a Bokeh server:

This high level Server class has some limitations. In particular, it is not possible to set an explicit io_loop and num_procs other than 1 at the same time. To do that, it is necessary to use BaseServer and coordinate the three components above explicitly.

__init__(applications: Mapping[str, Application | ModifyDoc] | Application | ModifyDoc, io_loop: IOLoop | None = None, http_server_kwargs: dict[str, Any] | None = None, **kwargs: Any) → None[source]#

Create a Server instance.

Parameters:

Additionally, the following options may be passed to configure the operation of Server:

Keyword Arguments:

Any remaining keyword arguments will be passed as-is toBokehTornado.

property address_: str | None_#

The configured address that the server listens on for HTTP requests.

property port_: int | None_#

The configured port number that the server listens on for HTTP requests.

property unix_socket_: str_#

The configured unix socket that the server listens to.