Sphinx Extensions

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

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

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.

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.

Usage

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(PlotObject):
    ''' 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.plot_object.PlotObject

This is a Foo model.

index

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

doc for index

value

property type: Tuple(Float, Float)

doc for value

[
  {
    "attributes": {
      "doc": null,
      "id": "b7b84bad-a2c9-4b46-b8b8-5aa79c0a704d",
      "index": "auto",
      "name": null,
      "tags": [],
      "value": null
    },
    "id": "b7b84bad-a2c9-4b46-b8b8-5aa79c0a704d",
    "type": "Foo"
  }
]

bokeh_palette

Generate color representations of all known Bokeh palettes.

Usage

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.

Usage

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

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

    .. bokeh-plot:: path/to/plot.py
    
  2. 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.

Options

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.

Usage

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(PlotObject):
    ''' This is a Bar model. '''
    thing = List(Int, help="doc for thing")

the above usage yields the output:


thing

property type: List(Int)

doc for thing

collapsible_code_block

Display code blocks in collapsible sections when outputting to HTML.

Usage

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!")

Options

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 collapes the block

Examples

The inline example code above produces the following output:


from __future__ import print_function

print("Hello, Bokeh!")