bokeh.sphinxext

In order to help automate and simplify the generation of Bokeh documentation, several Sphinx extensions have been created. Most of these will not be of general interest, except for bokeh.sphinxext.bokeh_plot, which allows anyone to include and embed bokeh plots directly in their own Sphinx docs.

bokeh_autodoc

Integrate Bokeh extensions into Sphinx autodoc.

Ensures that autodoc directives such as autoclass automatically use Bokeh-specific directives (e.g., bokeh-prop and bokeh-model) when appropriate.

bokeh_github

Simplify linking to Bokeh Github resources.

This module proved four new roles that can be uses to easily link to various resources in the Bokeh Github repository:

:bokeh-commit: : link to a specific commit

:bokeh-issue: : link to an issue

:bokeh-milestone: : link to a milestone page

:bokeh-pull: : link to a pull request

:bokeh-tree: : (versioned) link to a source tree URL

Examples

The following code:

The repo history shows that :bokeh-commit:`bf19bcb` was made in
in :bokeh-pull:`1698`, which closed :bokeh-issue:`1694` as part of
:bokeh-milestone:`0.8`. This included updating all of the files in
the :bokeh-tree:`examples` subdirectory.

yields the output:

The repo history shows that commit bf19bcb was made in in pull request 1698,which closed issue 1694 as part of milestone 0.8. This included updating all of the files in the examples subdirectory.

bokeh_model

Thoroughly document Bokeh model classes.

The bokeh-model directive will automatically document all the attributes (including Bokeh properties) of a Bokeh model class. A JSON prototype showing all the possible JSON fields will also be generated.

This directive takes the path to a Bokeh model class as an argument:

.. bokeh-model:: bokeh.sphinxext.sample.Foo

Examples

For the following definition of bokeh.sphinxext.sample.Foo:

class Foo(Model):
    ''' This is a Foo model. '''
    index = Either(Auto, Enum('abc', 'def', 'xzy'), help="doc for index")
    value = Tuple(Float, Float, help="doc for value")

the above usage yields the output:

class Foo(**kwargs)

Bases: bokeh.model.Model

This is a Foo model.

index

property type: index:Either(Auto, Enum(‘abc’, ‘def’, ‘xzy’))

doc for index

value

property type: value:Tuple(Float, Float)

doc for value

JSON Prototype
{
  "id": "c23131d0-dfb0-42da-9b7e-1b29fe90cbba",
  "index": "auto",
  "name": null,
  "tags": [],
  "value": null
}

bokeh_palette

Generate color representations of all known Bokeh palettes.

This directive takes no arguments.

bokeh_plot

Include Bokeh plots in Sphinx HTML documentation.

For other output types, the placeholder text [graph] will be generated.

The bokeh-plot directive can be used by either supplying:

A path to a source file as the argument to the directive:

.. bokeh-plot:: path/to/plot.py

Inline code as the content of the directive:

.. bokeh-plot::

    from bokeh.plotting import figure, output_file, show

    output_file("example.html")

    x = [1, 2, 3, 4, 5]
    y = [6, 7, 6, 4, 5]

    p = figure(title="example", plot_width=300, plot_height=300)
    p.line(x, y, line_width=2)
    p.circle(x, y, size=10, fill_color="white")

    show(p)

This directive also works in conjunction with Sphinx autodoc, when used in docstrings.

The bokeh-plot directive accepts the following options:

source-position
: enum(‘above’, ‘below’, ‘none’)
Where to locate the the block of formatted source code (if anywhere).
linenos
: bool
Whether to display line numbers along with the source.
emphasize-lines
: list[int]
A list of source code lines to emphasize.

Examples

The inline example code above produces the following output:

from bokeh.plotting import figure, output_file, show

output_file("example.html")

x = [1, 2, 3, 4, 5]
y = [6, 7, 6, 4, 5]

p = figure(title="example", plot_width=300, plot_height=300)
p.line(x, y, line_width=2)
p.circle(x, y, size=10, fill_color="white")

show(p)

bokeh_prop

Thoroughly document Bokeh property attributes.

The bokeh-prop directive generates useful type information for the property attribute, including cross links to the relevant property types. Additionally, any per-attribute docstrings are also displayed.

This directive takes the path to an attribute on a Bokeh model class as an argument:

.. bokeh-prop:: bokeh.sphinxext.sample.Bar.thing

Examples

For the following definition of bokeh.sphinxext.sample.Bar:

class Bar(Model):
    ''' This is a Bar model. '''
    thing = List(Int, help="doc for thing")

the above usage yields the output:

thing

property type: thing:List(Int)

doc for thing

bokeh_sitemap

Generate a sitemap.txt to aid with search indexing.

sitemap.txt is a plain text list of all the pages in the docs site. Each url is listed on a new line in the text file. It is machine readable and used by search engines to know what pages are available for indexing.

collapsible_code_block

Display code blocks in collapsible sections when outputting to HTML.

This directive takes a heading to use for the collapsible code block:

.. collapsible-code-block:: python
    :heading: Some Code

    from __future__ import print_function

    print("Hello, Bokeh!")

This directive is identical to the standard code-block directive that Sphinx supplies, with the addition of one new option:

heading
: string
A heading to put for the collapsible block. Clicking the heading expands or collapses the block

Examples

The inline example code above produces the following output:

Some Code
from __future__ import print_function

print("Hello, Bokeh!")