bokeh.server.tornado#
Provides the Bokeh Server Tornado application.
- class BokehTornado(applications: Mapping[str, Application | ModifyDoc] | Application | ModifyDoc, *, absolute_url: str | None = None, prefix: str | None = None, extra_websocket_origins: Sequence[str] | None = None, extra_patterns: URLRoutes | None = None, secret_key: bytes | None = None, sign_sessions: bool = False, generate_session_ids: bool = True, keep_alive_milliseconds: int = 37000, check_unused_sessions_milliseconds: int = 17000, unused_session_lifetime_milliseconds: int = 15000, stats_log_frequency_milliseconds: int = 15000, mem_log_frequency_milliseconds: int = 0, use_index: bool = True, redirect_root: bool = True, websocket_max_message_size_bytes: int = 20971520, websocket_compression_level: int | None = None, websocket_compression_mem_level: int | None = None, ico_path: str = '/usr/share/miniconda3/envs/bk-release-build/lib/python3.8/site-packages/bokeh/server/views/bokeh.ico', index: str | None = None, auth_provider: AuthProvider = <bokeh.server.auth_provider.NullAuth object>, xsrf_cookies: bool = False, include_headers: list[str] | None = None, include_cookies: list[str] | None = None, exclude_headers: list[str] | None = None, exclude_cookies: list[str] | None = None, session_token_expiration: int = 300, **kwargs: Any)[source]#
A Tornado Application used to implement the Bokeh Server.
- Parameters:
applications (dict[str,Application] or Application) –
A map from paths to
Application
instances.If the value is a single Application, then the following mapping is generated:
applications = { '/' : applications }
When a connection comes in to a given path, the associate Application is used to generate a new document for the session.
prefix (str, optional) – A URL prefix to use for all Bokeh server paths. (default: None)
ico_path (str, optional) – A path to a .ico file to return for
/favicon.ico
.extra_websocket_origins (list[str], optional) –
A list of hosts that can connect to the websocket.
This is typically required when embedding a Bokeh server app in an external web site using
server_document()
or similar.If None,
["localhost"]
will be assumed (default: None)extra_patterns (seq[tuple], optional) –
A list of tuples of (str, http or websocket handler)
Use this argument to add additional endpoints to custom deployments of the Bokeh Server.
If None, then
[]
will be used. (default: None)secret_key (str, optional) –
A secret key for signing session IDs.
Defaults to the current value of the environment variable
BOKEH_SECRET_KEY
sign_sessions (bool, optional) –
Whether to cryptographically sign session IDs
Defaults to the current value of the environment variable
BOKEH_SIGN_SESSIONS
. IfTrue
, thensecret_key
must also be provided (either via environment setting or passed as a parameter value)generate_session_ids (bool, optional) – Whether to generate a session ID if one is not provided (default: True)
keep_alive_milliseconds (int, optional) –
Number of milliseconds between keep-alive pings (default: 37000)
Pings normally required to keep the websocket open. Set to 0 to disable pings.
check_unused_sessions_milliseconds (int, optional) – Number of milliseconds between checking for unused sessions (default: 17000)
unused_session_lifetime_milliseconds (int, optional) – Number of milliseconds for unused session lifetime (default: 15000)
stats_log_frequency_milliseconds (int, optional) – Number of milliseconds between logging stats (default: 15000)
mem_log_frequency_milliseconds (int, optional) –
Number of milliseconds between logging memory information (default: 0)
Enabling this feature requires the optional dependency
psutil
to be installed.use_index (bool, optional) – Whether to generate an index of running apps in the
RootHandler
(default: True)index (str, optional) – Path to a Jinja2 template to serve as the index for “/” if use_index is True. If None, the basic built in app index template is used. (default: None)
redirect_root (bool, optional) –
When there is only a single running application, whether to redirect requests to
"/"
to that application automatically (default: True)If there are multiple Bokeh applications configured, this option has no effect.
websocket_max_message_size_bytes (int, optional) – Set the Tornado
websocket_max_message_size
value. (default: 20971520)websocket_compression_level (int, optional) – Set the Tornado WebSocket
compression_level
documented in https://docs.python.org/3.7/library/zlib.html#zlib.compressobj.websocket_compression_mem_level (int, optional) – Set the Tornado WebSocket compression
mem_level
documented in https://docs.python.org/3.7/library/zlib.html#zlib.compressobj.index – Path to a Jinja2 template to use for the root URL
auth_provider (AuthProvider, optional) – An AuthProvider instance
include_headers (list, optional) – List of request headers to include in session context (by default all headers are included)
exclude_headers (list, optional) – List of request headers to exclude in session context (by default all headers are included)
include_cookies (list, optional) – List of cookies to include in session context (by default all cookies are included)
exclude_cookies (list, optional) – List of cookies to exclude in session context (by default all cookies are included)
session_token_expiration (int, optional) – Duration in seconds that a new session token is valid for session creation. After the expiry time has elapsed, the token will not be able create a new session (default: 300)
Any additional keyword arguments are passed to
tornado.web.Application
.Public Data Attributes:
The configured applications
A list of all application paths for all Bokeh applications configured on this Bokeh server instance.
Path to a Jinja2 template to serve as the index "/"
Favicon.ico file data, or None
The Tornado IOLoop that this Bokeh Server Tornado Application is running on.
A URL prefix for this Bokeh Server Tornado Application to use for all paths
A list of websocket origins permitted to connect to this server.
A secret key for this Bokeh Server Tornado Application to use when signing session IDs, if configured.
A list of request cookies to make available in the session context.
A list of request headers to make available in the session context.
A list of request cookies to exclude in the session context.
A list of request headers to exclude in the session context.
Whether this Bokeh Server Tornado Application has been configured to cryptographically sign session IDs
Whether this Bokeh Server Tornado Application has been configured to automatically generate session IDs.
Duration in seconds that a new session token is valid for session creation.
Public Methods:
__init__
(applications, *[, absolute_url, ...])initialize
(io_loop)Start a Bokeh Server Tornado Application on a given Tornado IOLoop.
resources
([absolute_url])Provide a
Resources
that specifies where Bokeh application sessions should load BokehJS resources from.start
()Start the Bokeh Server application.
stop
([wait])Stop the Bokeh Server application.
new_connection
(protocol, socket, ...)client_lost
(connection)get_session
(app_path, session_id)Get an active a session by name application path and session ID.
get_sessions
(app_path)Gets all currently active sessions for an application.
Inherited from : py: class:Application
__init__
(applications, *[, absolute_url, ...])listen
(port[, address, family, backlog, ...])Starts an HTTP server for this application on the given port.
add_handlers
(host_pattern, host_handlers)Appends the given handlers to our handler list.
add_transform
(transform_class)__call__
(request)Call self as a function.
find_handler
(request, **kwargs)Must be implemented to return an appropriate instance of ~.httputil.HTTPMessageDelegate that can serve the request.
get_handler_delegate
(request, target_class)Returns ~.httputil.HTTPMessageDelegate that can serve a request for application and RequestHandler subclass.
reverse_url
(name, *args)Returns a URL path for handler named
name
log_request
(handler)Writes a completed HTTP request to the logs.
Inherited from : py: class:ReversibleRouter
reverse_url
(name, *args)Returns a URL path for handler named
name
Inherited from : py: class:Router
find_handler
(request, **kwargs)Must be implemented to return an appropriate instance of ~.httputil.HTTPMessageDelegate that can serve the request.
start_request
(server_conn, request_conn)This method is called by the server when a new request has started.
Inherited from : py: class:HTTPServerConnectionDelegate
start_request
(server_conn, request_conn)This method is called by the server when a new request has started.
on_close
(server_conn)This method is called when a connection has been closed.
- get_session(app_path: str, session_id: ID) ServerSession [source]#
Get an active a session by name application path and session ID.
- get_sessions(app_path: str) list[ServerSession] [source]#
Gets all currently active sessions for an application.
- Parameters:
app_path (str) – The configured application path for the application to return sessions for.
- Returns:
list[ServerSession]
- initialize(io_loop: IOLoop) None [source]#
Start a Bokeh Server Tornado Application on a given Tornado IOLoop.
- resources(absolute_url: str | None = None) Resources [source]#
Provide a
Resources
that specifies where Bokeh application sessions should load BokehJS resources from.- Parameters:
absolute_url (bool) – An absolute URL prefix to use for locating resources. If None, relative URLs are used (default: None)
- start() None [source]#
Start the Bokeh Server application.
Starting the Bokeh Server Tornado application will run periodic callbacks for stats logging, cleanup, pinging, etc. Additionally, any startup hooks defined by the configured Bokeh applications will be run.
- stop(wait: bool = True) None [source]#
Stop the Bokeh Server application.
- Parameters:
wait (bool) – whether to wait for orderly cleanup (default: True)
- Returns:
None
- property app_paths: set[str]#
A list of all application paths for all Bokeh applications configured on this Bokeh server instance.
- property applications: Mapping[str, ApplicationContext]#
The configured applications
- property exclude_cookies: list[str] | None#
A list of request cookies to exclude in the session context.
- property exclude_headers: list[str] | None#
A list of request headers to exclude in the session context.
- property generate_session_ids: bool#
Whether this Bokeh Server Tornado Application has been configured to automatically generate session IDs.
- property include_cookies: list[str] | None#
A list of request cookies to make available in the session context.
- property include_headers: list[str] | None#
A list of request headers to make available in the session context.
- property io_loop: IOLoop#
The Tornado IOLoop that this Bokeh Server Tornado Application is running on.
- property secret_key: bytes | None#
A secret key for this Bokeh Server Tornado Application to use when signing session IDs, if configured.
- property session_token_expiration: int#
Duration in seconds that a new session token is valid for session creation.
After the expiry time has elapsed, the token will not be able create a new session.