Provide a customizable Bokeh Server Tornado application.


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.


class NextTickCallback(document, callback, id=None)[source]
class PeriodicCallback(document, callback, period, id=None)[source]
class SessionCallback(document, callback, id=None)[source]
class TimeoutCallback(document, callback, timeout, id=None)[source]

class ColumnsPatchedEvent(document, column_source, patches, setter=None)[source]
class ColumnsStreamedEvent(document, column_source, data, rollover, setter=None)[source]
class DocumentChangedEvent(document, setter=None)[source]
class DocumentPatchedEvent(document, setter=None)[source]
class ModelChangedEvent(document, model, attr, old, new, serializable_new, hint=None, setter=None)[source]
class RootAddedEvent(document, model, setter=None)[source]
class RootRemovedEvent(document, model, setter=None)[source]
class SessionCallbackAdded(document, callback)[source]
class SessionCallbackRemoved(document, callback)[source]
class TitleChangedEvent(document, title, setter=None)[source]


Provides a Server which instantiates Application instances as clients connect

class Server(applications, io_loop=None, tornado_server_kwargs=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”
num_procs (str):
Number of worker processes for an app. Default to one. Using 0 will autodetect number of cores
tornado_server_kwargs (dict):

Additional arguments passed to tornado.httpserver.HTTPServer. E.g. max_buffer_size to specify the maximum upload size. More details can be found at:

get_session(app_path, session_id)[source]

Gets a session by name (session must already exist)


Gets all live sessions for an application.


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.
  • 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.



Start the Bokeh Server and its background tasks.


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 the Bokeh Server.

Parameters:fast (boolean) – whether to wait for orderly cleanup (default: True)

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


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


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


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.


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


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


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


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


Provides the Bokeh Server Tornado application.

class BokehTornado(applications, prefix, 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.
  • (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
  • 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
  • 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 the Bokeh Server application.


Stop the Bokeh Server application.

Parameters:wait (boolean) – whether to wait for orderly cleanup (default: True)
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(‘’, ‘’) True >>> match_host(‘’, ‘’) True >>> match_host(‘’, ‘’) False >>> match_host(‘’, ‘’) False >>> match_host(‘’, ‘192.168.*.*’) True >>> match_host(‘alice’, ‘alice’) True >>> match_host(‘alice:80’, ‘alice’) True >>> match_host(‘alice’, ‘bob’) False >>> match_host(‘’, ‘’) 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


Standard endpoints for a BokehServer application.