bokeh.server

Provide a customizable Bokeh Server Tornado application.

bokeh.server.application_context

Provides the ApplicationContext class.

class ApplicationContext(application, io_loop=None)[source]

Server-side holder for bokeh.application.Application plus any associated data. This holds data that’s global to all sessions, while ServerSession holds data specific to an “instance” of the application.

bokeh.server.server

Provides a Server which instantiates Application instances as clients connect

class Server(applications, io_loop=None, **kwargs)[source]

A Server which creates a new Session for each connection, using an Application to initialize each Session.

Parameters:(dict of str (applications) – bokeh.application.Application) or bokeh.application.Application: mapping from URL paths to Application instances, or a single Application to put at the root URL The Application is a factory for Document, with a new Document initialized for each Session. Each application should be identified by a path meant to go in a URL, like “/” or “/foo”
Kwargs:
num_procs (str):
Number of worker processes for an app. Default to one. Using 0 will autodetect number of cores
get_session(app_path, session_id)[source]

Gets a session by name (session must already exist)

get_sessions(app_path)[source]

Gets all live sessions for an application.

run_until_shutdown()[source]

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

show(app_path, browser=None, new='tab')[source]

Opens an app in a browser window or tab.

Useful for testing server applications on your local desktop but should not call when running bokeh-server on an actual server.
Parameters:
  • app_path (str) – the app path to open The part of the URL after the hostname:port, with leading slash.
  • browser (str, optional) – browser to show with (default: None) For systems that support it, the browser argument allows specifying which browser to display in, e.g. “safari”, “firefox”, “opera”, “windows-default” (see the webbrowser module documentation in the standard lib for more details).
  • new (str, optional) – window or tab (default: “tab”) If new is ‘tab’, then opens a new tab. If new is ‘window’, then opens a new window.
Returns:

None

start()[source]

Start the Bokeh Server and its background tasks.

Notes

This method does not block and does not affect the state of the Tornado I/O loop. You must start and stop the loop yourself.

stop(wait=True)[source]

Stop the Bokeh Server.

Parameters:fast (boolean) – whether to wait for orderly cleanup (default: True)
Returns:None
unlisten()[source]

Stop listening on ports (Server will no longer be usable after calling this)

Returns:None
address

The address the server is listening on for HTTP requests (may be empty or None).

port

The actual port number the server is listening on for HTTP requests.

bokeh.server.session

Provides the ServerSession class.

class ServerSession(session_id, document, io_loop=None)[source]

Hosts an application “instance” (an instantiated Document) for one or more connections.

classmethod patch(message, connection)[source]

Handle a PATCH-DOC, return a Future with work to be scheduled.

classmethod pull(message, connection)[source]

Handle a PULL-DOC, return a Future with work to be scheduled.

classmethod push(message, connection)[source]

Handle a PUSH-DOC, return a Future with work to be scheduled.

request_expiration()[source]

Used in test suite for now. Forces immediate expiration if no connections.

subscribe(connection)[source]

This should only be called by ServerConnection.subscribe_session or our book-keeping will be broken

unsubscribe(connection)[source]

This should only be called by ServerConnection.unsubscribe_session or our book-keeping will be broken

current_time()[source]

Return the time in milliseconds since the epoch as a floating point number.

bokeh.server.tornado

Provides the Bokeh Server Tornado application.

class BokehTornado(applications, prefix, hosts, extra_websocket_origins, extra_patterns=None, secret_key=None, sign_sessions=False, generate_session_ids=True, keep_alive_milliseconds=37000, check_unused_sessions_milliseconds=17000, unused_session_lifetime_milliseconds=15000, stats_log_frequency_milliseconds=15000, use_index=True, redirect_root=True)[source]

A Tornado Application used to implement the Bokeh Server.

The Server class is the main public interface, this class has Tornado implementation details.
Parameters:
  • (dict of str (applications) – bokeh.application.Application) : map from paths to Application instances The application is used to create documents for each session.
  • extra_patterns (seq[tuple]) – tuples of (str, http or websocket handler) Use this argument to add additional endpoints to custom deployments of the Bokeh Server.
  • prefix (str) – a URL prefix to use for all Bokeh server paths
  • hosts (list) – hosts that are valid values for the Host header
  • secret_key (str) – secret key for signing session IDs
  • sign_sessions (boolean) – whether to sign session IDs
  • generate_session_ids (boolean) – whether to generate a session ID when none is provided
  • extra_websocket_origins (list) – hosts that can connect to the websocket These are in addition to hosts.
  • keep_alive_milliseconds (int) – number of milliseconds between keep-alive pings Set to 0 to disable pings. Pings keep the websocket open.
  • check_unused_sessions_milliseconds (int) – number of milliseconds between check for unused sessions
  • unused_session_lifetime_milliseconds (int) – number of milliseconds for unused session lifetime
  • stats_log_frequency_milliseconds (int) – number of milliseconds between logging stats
  • use_index (boolean) – True to generate an index of the running apps in the RootHandler
run_in_background(_func, *args, **kwargs)[source]

Run a synchronous function in the background without disrupting the main thread. Useful for long-running jobs.

start()[source]

Start the Bokeh Server application.

stop(wait=True)[source]

Stop the Bokeh Server application.

Parameters:wait (boolean) – whether to wait for orderly cleanup (default: True)
Returns:None
check_whitelist(request_host, whitelist)[source]

Check a given request host against a whitelist.

match_host(host, pattern)[source]

Match host against pattern

>>> match_host('192.168.0.1:80', '192.168.0.1:80')
True
>>> match_host('192.168.0.1:80', '192.168.0.1')
True
>>> match_host('192.168.0.1:80', '192.168.0.1:8080')
False
>>> match_host('192.168.0.1', '192.168.0.2')
False
>>> match_host('192.168.0.1', '192.168.*.*')
True
>>> match_host('alice', 'alice')
True
>>> match_host('alice:80', 'alice')
True
>>> match_host('alice', 'bob')
False
>>> match_host('foo.example.com', 'foo.example.com.net')
False
>>> match_host('alice', '*')
True
>>> match_host('alice', '*:*')
True
>>> match_host('alice:80', '*')
True
>>> match_host('alice:80', '*:80')
True
>>> match_host('alice:8080', '*:80')
False

bokeh.server.urls

Standard endpoints for a BokehServer application.