bokeh.resources¶
The resources module provides the Resources class for easily configuring how BokehJS code and CSS resources should be located, loaded, and embedded in Bokeh documents.
Additionally, functions for retrieving Subresource Integrity hashes for Bokeh JavaScript files are provided here.
Some pre-configured Resources objects are made available as attributes.
- CDN¶
load minified BokehJS from CDN
- INLINE¶
provide minified BokehJS from library static directory
- class CSSResources(mode: ResourcesMode | None = None, version: str | None = None, root_dir: PathLike | None = None, minified: bool | None = None, legacy: bool | None = None, log_level: LogLevel | None = None, root_url: str | None = None, path_versioner: PathVersioner | None = None, components: List[str] | None = None, base_dir: str | None = None)[source]¶
The CSSResources class encapsulates information relating to loading or embedding Bokeh client-side CSS.
- Parameters
mode (str) –
how should Bokeh CSS be included in output
See below for descriptions of available modes
version (str, optional) –
what version of Bokeh CSS to load
Only valid with the
'cdn'
moderoot_dir (str, optional) –
root directory for loading BokehJS resources
Only valid with
'relative'
and'relative-dev'
modesminified (bool, optional) – whether CSS should be minified or not (default: True)
root_url (str, optional) –
URL and port of Bokeh Server to load resources from
Only valid with
'server'
and'server-dev'
modes
The following mode values are available for configuring a Resource object:
'inline'
configure to provide entire BokehJS code and CSS inline'cdn'
configure to load Bokeh CSS fromhttps://cdn.bokeh.org
'server'
configure to load from a Bokeh Server'server-dev'
same asserver
but supports non-minified CSS'relative'
configure to load relative to the given directory'relative-dev'
same asrelative
but supports non-minified CSS'absolute'
configure to load from the installed Bokeh library static directory'absolute-dev'
same asabsolute
but supports non-minified CSS
Once configured, a Resource object exposes the following public attributes:
- css_raw¶
any raw CSS that needs to be places inside
<style>
tags
- css_files¶
URLs of any CSS files that need to be loaded by
<link>
tags
- messages¶
any informational messages concerning this configuration
- Type
List[bokeh.resources.RuntimeMessage]
These attributes are often useful as template parameters when embedding Bokeh plots.
- class JSResources(mode: ResourcesMode | None = None, version: str | None = None, root_dir: PathLike | None = None, minified: bool | None = None, legacy: bool | None = None, log_level: LogLevel | None = None, root_url: str | None = None, path_versioner: PathVersioner | None = None, components: List[str] | None = None, base_dir: str | None = None)[source]¶
The Resources class encapsulates information relating to loading or embedding Bokeh Javascript.
- Parameters
mode (str) –
How should Bokeh JS be included in output
See below for descriptions of available modes
version (str, optional) –
what version of Bokeh JS to load
Only valid with the
'cdn'
moderoot_dir (str, optional) –
root directory for loading Bokeh JS assets
Only valid with
'relative'
and'relative-dev'
modesminified (bool, optional) – whether JavaScript should be minified or not (default: True)
root_url (str, optional) –
URL and port of Bokeh Server to load resources from (default: None)
If
None
, absolute URLs based on the default server configuration will be generated.root_url
can also be the empty string, in which case relative URLs, e.g., “static/js/bokeh.min.js”, are generated.Only valid with
'server'
and'server-dev'
modes
The following mode values are available for configuring a Resource object:
'inline'
configure to provide entire Bokeh JS and CSS inline'cdn'
configure to load Bokeh JS and CSS fromhttps://cdn.bokeh.org
'server'
configure to load from a Bokeh Server'server-dev'
same asserver
but supports non-minified assets'relative'
configure to load relative to the given directory'relative-dev'
same asrelative
but supports non-minified assets'absolute'
configure to load from the installed Bokeh library static directory'absolute-dev'
same asabsolute
but supports non-minified assets
Once configured, a Resource object exposes the following public attributes:
- css_raw¶
any raw CSS that needs to be places inside
<style>
tags
- css_files¶
URLs of any CSS files that need to be loaded by
<link>
tags
- messages¶
any informational messages concerning this configuration
- Type
List[bokeh.resources.RuntimeMessage]
These attributes are often useful as template parameters when embedding Bokeh plots.
- class Resources(mode: ResourcesMode | None = None, version: str | None = None, root_dir: PathLike | None = None, minified: bool | None = None, legacy: bool | None = None, log_level: LogLevel | None = None, root_url: str | None = None, path_versioner: PathVersioner | None = None, components: List[str] | None = None, base_dir: str | None = None)[source]¶
The Resources class encapsulates information relating to loading or embedding Bokeh Javascript and CSS.
- Parameters
mode (str) –
how should Bokeh JS and CSS be included in output
See below for descriptions of available modes
version (str, optional) –
what version of Bokeh JS and CSS to load
Only valid with the
'cdn'
moderoot_dir (str, optional) –
root directory for loading Bokeh JS and CSS assets
Only valid with
'relative'
and'relative-dev'
modesminified (bool, optional) – whether JavaScript and CSS should be minified or not (default: True)
root_url (str, optional) –
URL and port of Bokeh Server to load resources from
Only valid with
'server'
and'server-dev'
modes
The following mode values are available for configuring a Resource object:
'inline'
configure to provide entire Bokeh JS and CSS inline'cdn'
configure to load Bokeh JS and CSS fromhttps://cdn.bokeh.org
'server'
configure to load from a Bokeh Server'server-dev'
same asserver
but supports non-minified assets'relative'
configure to load relative to the given directory'relative-dev'
same asrelative
but supports non-minified assets'absolute'
configure to load from the installed Bokeh library static directory'absolute-dev'
same asabsolute
but supports non-minified assets
Once configured, a Resource object exposes the following public attributes:
- js_raw¶
any raw JS that needs to be placed inside
<script>
tags
- css_raw¶
any raw CSS that needs to be places inside
<style>
tags
- js_files¶
URLs of any JS files that need to be loaded by
<script>
tags
- css_files¶
URLs of any CSS files that need to be loaded by
<link>
tags
- messages¶
any informational messages concerning this configuration
- Type
List[bokeh.resources.RuntimeMessage]
These attributes are often useful as template parameters when embedding Bokeh plots.
- get_all_sri_hashes() Dict[str, Dict[str, str]] [source]¶
Report SRI script hashes for all versions of BokehJS.
Bokeh provides Subresource Integrity hashes for all JavaScript files that are published to CDN for full releases. This function returns a dictionary that maps version strings to sub-dictionaries that JavaScipt filenames to their hashes.
- Returns
dict
Example
The returned dict will map version strings to sub-dictionaries for each version:
{ '1.4.0': { 'bokeh-1.4.0.js': 'vn/jmieHiN+ST+GOXzRU9AFfxsBp8gaJ/wvrzTQGpIKMsdIcyn6U1TYtvzjYztkN', 'bokeh-1.4.0.min.js': 'mdMpUZqu5U0cV1pLU9Ap/3jthtPth7yWSJTu1ayRgk95qqjLewIkjntQDQDQA5cZ', ... } '1.3.4': { ... } ... }
- get_sri_hashes_for_version(version: str) Dict[str, str] [source]¶
Report SRI script hashes for a specific version of BokehJS.
Bokeh provides Subresource Integrity hashes for all JavaScript files that are published to CDN for full releases. This function returns a dictionary that maps JavaScript filenames to their hashes, for a single version of Bokeh.
- Parameters
version (str) – The Bokeh version to return SRI hashes for. Hashes are only provided for full releases, e.g “1.4.0”, and not for “dev” builds or release candidates.
- Returns
dict
- Raises
KeyError – if the specified version does not exist
Example
The returned dict for a single version will map filenames for that version to their SRI hashes:
{ 'bokeh-1.4.0.js': 'vn/jmieHiN+ST+GOXzRU9AFfxsBp8gaJ/wvrzTQGpIKMsdIcyn6U1TYtvzjYztkN', 'bokeh-1.4.0.min.js': 'mdMpUZqu5U0cV1pLU9Ap/3jthtPth7yWSJTu1ayRgk95qqjLewIkjntQDQDQA5cZ', 'bokeh-api-1.4.0.js': 'Y3kNQHt7YjwAfKNIzkiQukIOeEGKzUU3mbSrraUl1KVfrlwQ3ZAMI1Xrw5o3Yg5V', 'bokeh-api-1.4.0.min.js': '4oAJrx+zOFjxu9XLFp84gefY8oIEr75nyVh2/SLnyzzg9wR+mXXEi+xyy/HzfBLM', 'bokeh-tables-1.4.0.js': 'I2iTMWMyfU/rzKXWJ2RHNGYfsXnyKQ3YjqQV2RvoJUJCyaGBrp0rZcWiTAwTc9t6', 'bokeh-tables-1.4.0.min.js': 'pj14Cq5ZSxsyqBh+pnL2wlBS3UX25Yz1gVxqWkFMCExcnkN3fl4mbOF8ZUKyh7yl', 'bokeh-widgets-1.4.0.js': 'scpWAebHEUz99AtveN4uJmVTHOKDmKWnzyYKdIhpXjrlvOwhIwEWUrvbIHqA0ke5', 'bokeh-widgets-1.4.0.min.js': 'xR3dSxvH5hoa9txuPVrD63jB1LpXhzFoo0ho62qWRSYZVdyZHGOchrJX57RwZz8l' }
- verify_sri_hashes() None [source]¶
Verify the SRI hashes in a full release package.
This function compares the computed SRI hashes for the BokehJS files in a full release package to the values in the SRI manifest file. Returns None if all hashes match, otherwise an exception will be raised.
Note
This function can only be called on full release (e.g “1.2.3”) packages.
- Returns
None
- Raises
ValueError – If called outside a full release package
RuntimeError – If there are missing, extra, or mismatched files